1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace App\Repository\Parts; |
22
|
|
|
|
23
|
|
|
use App\Entity\Parts\Part; |
24
|
|
|
use App\Repository\AbstractPartsContainingRepository; |
25
|
|
|
use Doctrine\ORM\QueryBuilder; |
26
|
|
|
|
27
|
|
|
class SupplierRepository extends AbstractPartsContainingRepository |
28
|
|
|
{ |
29
|
|
|
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array |
30
|
|
|
{ |
31
|
|
|
$qb = new QueryBuilder($this->getEntityManager()); |
32
|
|
|
|
33
|
|
|
$qb->select('part') |
34
|
|
|
->from(Part::class, 'part') |
35
|
|
|
->leftJoin('part.orderdetails', 'orderdetail') |
36
|
|
|
->where('orderdetail.supplier = ?1') |
37
|
|
|
->setParameter(1, $element); |
38
|
|
|
|
39
|
|
|
foreach ($order_by as $field => $order) { |
40
|
|
|
$qb->addOrderBy('part.' . $field, $order); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $qb->getQuery()->getResult(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getPartsCount(object $element): int |
47
|
|
|
{ |
48
|
|
|
$qb = new QueryBuilder($this->getEntityManager()); |
49
|
|
|
|
50
|
|
|
$qb->select('COUNT(part.id)') |
51
|
|
|
->from(Part::class, 'part') |
52
|
|
|
->leftJoin('part.orderdetails', 'orderdetail') |
53
|
|
|
->where('orderdetail.supplier = ?1') |
54
|
|
|
->setParameter(1, $element); |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
return (int) $qb->getQuery()->getSingleScalarResult(); |
58
|
|
|
} |
59
|
|
|
} |