ContactPointRepository.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repository\Core;
  4. use App\Entity\Core\ContactPoint;
  5. use App\Entity\Organization\Organization;
  6. use App\Entity\Person\Person;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10. * @method ContactPoint|null find($id, $lockMode = null, $lockVersion = null)
  11. * @method ContactPoint|null findOneBy(array $criteria, array $orderBy = null)
  12. * @method ContactPoint[] findAll()
  13. * @method ContactPoint[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14. */
  15. class ContactPointRepository extends ServiceEntityRepository
  16. {
  17. public function __construct(ManagerRegistry $registry)
  18. {
  19. parent::__construct($registry, ContactPoint::class);
  20. }
  21. /**
  22. * Récupération des points de contacts d'une organization et d'un type précis
  23. * @param String $type
  24. * @param Organization $organization
  25. * @return array|null
  26. */
  27. public function getByTypeAndOrganization(String $type, Organization $organization): array | null{
  28. return $this->createQueryBuilder('contact_point')
  29. ->innerJoin('contact_point.organization', 'organization')
  30. ->where('contact_point.contactType = :type')
  31. ->andWhere('organization.id = :organizationId')
  32. ->setParameter('type', $type)
  33. ->setParameter('organizationId', $organization->getId())
  34. ->getQuery()
  35. ->getResult()
  36. ;
  37. }
  38. /**
  39. * Récupération des points de contacts d'une person et d'un type précis
  40. * @param String $type
  41. * @param Person $person
  42. * @return array|null
  43. */
  44. public function getByTypeAndPerson(String $type, Person $person): array | null{
  45. return $this->createQueryBuilder('contact_point')
  46. ->innerJoin('contact_point.person', 'person')
  47. ->where('contact_point.contactType = :type')
  48. ->andWhere('person.id = :personId')
  49. ->setParameter('type', $type)
  50. ->setParameter('personId', $person->getId())
  51. ->getQuery()
  52. ->getResult()
  53. ;
  54. }
  55. }