. */ namespace App\Repository\Parts; use App\Entity\Parts\Part; use App\Entity\Parts\PartLot; use App\Entity\Parts\Storelocation; use App\Repository\AbstractPartsContainingRepository; use Doctrine\ORM\QueryBuilder; use Symfony\Component\HttpKernel\HttpCache\Store; class StorelocationRepository extends AbstractPartsContainingRepository { /** * @param Storelocation $element */ public function getParts(object $element, array $order_by = ['name' => 'ASC']): array { if(!$element instanceof Storelocation) { throw new \InvalidArgumentException('$element must be an Storelocation!'); } $qb = new QueryBuilder($this->getEntityManager()); $qb->select('part') ->from(Part::class, 'part') ->leftJoin('part.partLots', 'lots') ->where('lots.storage_location = ?1') ->setParameter(1, $element); foreach ($order_by as $field => $order) { $qb->addOrderBy('part.' . $field, $order); } return $qb->getQuery()->getResult(); } public function getPartsCount(object $element): int { if(!$element instanceof Storelocation) { throw new \InvalidArgumentException('$element must be an Storelocation!'); } $qb = new QueryBuilder($this->getEntityManager()); $qb->select('COUNT(part.id)') ->from(Part::class, 'part') ->leftJoin('part.partLots', 'lots') ->where('lots.storage_location = ?1') ->setParameter(1, $element); return (int) $qb->getQuery()->getSingleScalarResult(); } }