. */ namespace App\Repository\Parts; use App\Entity\ProjectSystem\Project; use App\Repository\StructuralDBElementRepository; use InvalidArgumentException; class DeviceRepository extends StructuralDBElementRepository { public function getParts(object $element, array $order_by = ['name' => 'ASC']): array { if (!$element instanceof Project) { throw new InvalidArgumentException('$element must be an Device!'); } //TODO: Change this later, when properly implemented devices return []; } public function getPartsCount(object $element): int { if (!$element instanceof Project) { throw new InvalidArgumentException('$element must be an Device!'); } //TODO: Change this later, when properly implemented devices //Prevent user from deleting devices, to not accidentally remove filled devices from old versions return 1; } public function autocompleteSearch(string $query, int $max_limits = 50): array { $qb = $this->createQueryBuilder('p'); $qb->select('p') ->where('ILIKE(p.name, :query) = TRUE'); $qb->setParameter('query', '%'.$query.'%'); $qb->setMaxResults($max_limits); $qb->orderBy('NATSORT(p.name)', 'ASC'); return $qb->getQuery()->getResult(); } }