em = $em; $this->part_repo = $this->em->getRepository(Part::class); $this->attachment_repo = $this->em->getRepository(Attachment::class); } /** * Returns the count of distinct parts */ public function getDistinctPartsCount(): int { return $this->part_repo->count([]); } /** * Returns the summed instocked over all parts (only parts without a measurement unit) * @return string * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getPartsInstockSum(): string { return $this->part_repo->getPartsInstockSum(); } /** * Returns the number of all parts which have price informations * @return int * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getPartsCountWithPrice(): int { return $this->part_repo->getPartsCountWithPrice(); } /** * Returns the number of datastructures for the given type. * @param string $type * @return int */ public function getDataStructuresCount(string $type): int { $arr = [ 'attachment_type' => AttachmentType::class, 'category' => Category::class, 'device' => Device::class, 'footprint' => Footprint::class, 'manufacturer' => Manufacturer::class, 'measurement_unit' => MeasurementUnit::class, 'storelocation' => Storelocation::class, 'supplier' => Supplier::class, 'currency' => Currency::class, ]; if (!isset($arr[$type])) { throw new \InvalidArgumentException('No count for the given type available!'); } /** @var EntityRepository $repo */ $repo = $this->em->getRepository($arr[$type]); return $repo->count([]); } /** * Gets the count of all attachments. * @return int */ public function getAttachmentsCount(): int { return $this->attachment_repo->count([]); } /** * Gets the count of all private/secure attachments * @return int */ public function getPrivateAttachmentsCount(): int { return $this->attachment_repo->getPrivateAttachmentsCount(); } /** * Gets the count of all external (only containing an URL) attachments * @return int * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getExternalAttachmentsCount(): int { return $this->attachment_repo->getExternalAttachments(); } /** * Gets the count of all attachments where the user uploaded an file. * @return int * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getUserUploadedAttachmentsCount(): int { return $this->attachment_repo->getUserUploadedAttachments(); } }