src/Repository/RepertoireRepository.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Repertoire;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use App\Utils\Constants;
  7. /**
  8. * @extends ServiceEntityRepository<Repertoire>
  9. *
  10. * @method Repertoire|null find($id, $lockMode = null, $lockVersion = null)
  11. * @method Repertoire|null findOneBy(array $criteria, array $orderBy = null)
  12. * @method Repertoire[] findAll()
  13. * @method Repertoire[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14. */
  15. class RepertoireRepository extends ServiceEntityRepository
  16. {
  17. public function __construct(ManagerRegistry $registry)
  18. {
  19. parent::__construct($registry, Repertoire::class);
  20. }
  21. public function save(Repertoire $entity, bool $flush = false): void
  22. {
  23. $this->getEntityManager()->persist($entity);
  24. if ($flush) {
  25. $this->getEntityManager()->flush();
  26. }
  27. }
  28. public function remove(Repertoire $entity, bool $flush = false): void
  29. {
  30. $this->getEntityManager()->remove($entity);
  31. if ($flush) {
  32. $this->getEntityManager()->flush();
  33. }
  34. }
  35. public function getByReportType($type = null, $org) {
  36. if(is_null($type)) {
  37. return null;
  38. }
  39. return $this->createQueryBuilder('c')
  40. ->orWhere('c.status = :status AND c.organisation = :orgId AND c.report_type = :type')
  41. ->addOrderBy('c.name', 'ASC')
  42. ->setParameter('status', Constants::ACTIVE)
  43. ->setParameter('type', $type)
  44. ->setParameter('orgId', $org)
  45. ->getQuery()
  46. ->getResult();
  47. }
  48. public function getByReportTypeName($type = null, $name, $org) {
  49. if(is_null($type)) {
  50. return null;
  51. }
  52. if(is_null($name)) {
  53. return null;
  54. }
  55. return $this->createQueryBuilder('c')
  56. ->orWhere('c.status = :status AND c.organisation = :orgId AND c.report_type = :type AND c.name= :name')
  57. ->addOrderBy('c.name', 'ASC')
  58. ->setParameter('status', Constants::ACTIVE)
  59. ->setParameter('type', $type)
  60. ->setParameter('name', $name)
  61. ->setParameter('orgId', $org)
  62. ->getQuery()
  63. ->getResult();
  64. }
  65. public function getByReportTypeNameInactive($type = null, $name, $org) {
  66. if(is_null($type)) {
  67. return null;
  68. }
  69. if(is_null($name)) {
  70. return null;
  71. }
  72. return $this->createQueryBuilder('c')
  73. ->orWhere('c.status = :status AND c.organisation = :orgId AND c.report_type = :type AND c.name= :name')
  74. ->addOrderBy('c.name', 'ASC')
  75. ->setParameter('status', Constants::INACTIVE)
  76. ->setParameter('type', $type)
  77. ->setParameter('name', $name)
  78. ->setParameter('orgId', $org)
  79. ->getQuery()
  80. ->getResult();
  81. }
  82. // /**
  83. // * @return Repertoire[] Returns an array of Repertoire objects
  84. // */
  85. // public function findByExampleField($value): array
  86. // {
  87. // return $this->createQueryBuilder('r')
  88. // ->andWhere('r.exampleField = :val')
  89. // ->setParameter('val', $value)
  90. // ->orderBy('r.id', 'ASC')
  91. // ->setMaxResults(10)
  92. // ->getQuery()
  93. // ->getResult()
  94. // ;
  95. // }
  96. // public function findOneBySomeField($value): ?Repertoire
  97. // {
  98. // return $this->createQueryBuilder('r')
  99. // ->andWhere('r.exampleField = :val')
  100. // ->setParameter('val', $value)
  101. // ->getQuery()
  102. // ->getOneOrNullResult()
  103. // ;
  104. // }
  105. }