FileRepository.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace AppBundle\Entity\Core\Repository;
  3. use AppBundle\Services\Exporter\Document;
  4. use Doctrine\ORM\EntityRepository;
  5. /**
  6. * Description of NotificationRepository
  7. *
  8. * @author sebastienhupin
  9. */
  10. class FileRepository extends EntityRepository {
  11. /**
  12. * Find notification are not viewed by the user
  13. *
  14. * @param array $ids
  15. *
  16. * @return Array
  17. */
  18. public function findByDocument(Document $document) {
  19. $queryBuilder = $this->createQueryBuilder('o');
  20. if($document->getAccess()){
  21. $queryBuilder
  22. ->innerJoin('o.accessPersons', 'p')
  23. ->andWhere('p.id = :person')
  24. ->setParameter('person', $document->getAccess()->getPerson());
  25. }else{
  26. $queryBuilder
  27. ->innerJoin('o.organization', 'or');
  28. }
  29. $queryBuilder
  30. ->andWhere('o.name = :name')
  31. ->andWhere('o.type = :type')
  32. ->setParameter('name', $document->getName())
  33. ->setParameter('type', $document->getType());
  34. return $queryBuilder->getQuery()->getResult();
  35. }
  36. }