findOneBy(['uuid' => $uuid]); } /** @return InventoryItem[] */ public function findByEntity(string $entityType, int $entityId): array { return $this->createQueryBuilder('i') ->where('i.entityType = :type AND i.entityId = :id') ->setParameter('type', $entityType) ->setParameter('id', $entityId) ->orderBy('i.name', 'ASC') ->getQuery() ->getResult(); } /** * Distinct non-empty "consumable" values for the tenant — powers the * category filter dropdown on the inventory page. * * @return string[] */ public function findConsumables(string $entityType, int $entityId): array { $rows = $this->createQueryBuilder('i') ->select('DISTINCT i.consumable AS consumable') ->where('i.entityType = :type AND i.entityId = :id AND i.consumable IS NOT NULL AND i.consumable != :empty') ->setParameter('type', $entityType) ->setParameter('id', $entityId) ->setParameter('empty', '') ->orderBy('i.consumable', 'ASC') ->getQuery() ->getArrayResult(); return array_map(static fn(array $r): string => $r['consumable'], $rows); } public function save(InventoryItem $item): void { $this->getEntityManager()->persist($item); $this->getEntityManager()->flush(); } public function remove(InventoryItem $item): void { $this->getEntityManager()->remove($item); $this->getEntityManager()->flush(); } }