. */ namespace App\Repository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; class AttachmentRepository extends DBElementRepository { /** * Gets the count of all private/secure attachments. */ public function getPrivateAttachmentsCount(): int { $qb = $this->createQueryBuilder('attachment'); $qb->select('COUNT(attachment)') ->where('attachment.path LIKE :like'); $qb->setParameter('like', '\\%SECURE\\%%'); $query = $qb->getQuery(); return (int) $query->getSingleScalarResult(); } /** * Gets the count of all external attachments (attachments only containing an URL). * * @throws NoResultException * @throws NonUniqueResultException */ public function getExternalAttachments(): int { $qb = $this->createQueryBuilder('attachment'); $qb->select('COUNT(attachment)') ->where('attachment.path LIKE :http') ->orWhere('attachment.path LIKE :https'); $qb->setParameter('http', 'http://%'); $qb->setParameter('https', 'https://%'); $query = $qb->getQuery(); return (int) $query->getSingleScalarResult(); } /** * Gets the count of all attachments where an user uploaded an file. * * @throws NoResultException * @throws NonUniqueResultException */ public function getUserUploadedAttachments(): int { $qb = $this->createQueryBuilder('attachment'); $qb->select('COUNT(attachment)') ->where('attachment.path LIKE :base') ->orWhere('attachment.path LIKE :media') ->orWhere('attachment.path LIKE :secure'); $qb->setParameter('secure', '\\%SECURE\\%%'); $qb->setParameter('base', '\\%BASE\\%%'); $qb->setParameter('media', '\\%MEDIA\\%%'); $query = $qb->getQuery(); return (int) $query->getSingleScalarResult(); } }