You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 satır
2.7KB

  1. <?php
  2. namespace Lc\PietroBundle\Repository\Search;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Gedmo\Tree\RepositoryInterface;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  7. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  8. class SearchRepositoryQuery extends AbstractRepositoryQuery implements RepositoryQueryInterface
  9. {
  10. protected $isJoinCollectifData = false;
  11. protected $isJoinIndividualData = false;
  12. protected $isJoinSubthematic = false;
  13. public function __construct($repository, PaginatorInterface $paginator)
  14. {
  15. parent::__construct($repository, 'r', $paginator);
  16. }
  17. public function filterIsValid()
  18. {
  19. $this->joinCollectifData();
  20. $this->joinIndividualData();
  21. return $this
  22. ->andWhere('colData.status = 1 OR indivData.status = 1');
  23. }
  24. public function filterByThematic(ArrayCollection $thematicArray): self
  25. {
  26. return $this
  27. ->andWhere('.thematic IN (:thematic)')
  28. ->setParameter(':thematic', $thematicArray);
  29. }
  30. public function filterBySubthematicName(string $subthematic): self
  31. {
  32. $this->joinSubthematic();
  33. return $this
  34. ->andWhere('subT.name LIKE :subthematic')
  35. ->setParameter(':subthematic', '%' . $subthematic . '%');
  36. }
  37. public function filterByDescription(string $description): self
  38. {
  39. return $this
  40. ->andWhere('.description LIKE :description')
  41. ->setParameter(':description', '%' . $description . '%');
  42. }
  43. public function filterByTerritory(ArrayCollection $territoryArray): self
  44. {
  45. $this->joinCollectifData();
  46. $this->joinIndividualData();
  47. return $this
  48. ->andWhere('colData.territory IN (:territory) OR indivData.territory IN (:territory)')
  49. ->setParameter(':territory', $territoryArray);
  50. }
  51. public function joinSubthematic(): self
  52. {
  53. if (!$this->isJoinSubthematic) {
  54. $this->isJoinSubthematic = true;
  55. return $this
  56. ->leftJoin('.subthematic', 'subT');
  57. }
  58. return $this;
  59. }
  60. public function joinCollectifData(): self
  61. {
  62. if (!$this->isJoinCollectifData) {
  63. $this->isJoinCollectifData = true;
  64. return $this
  65. ->leftJoin('.collectifData', 'colData');
  66. }
  67. return $this;
  68. }
  69. public function joinIndividualData(): self
  70. {
  71. if (!$this->isJoinIndividualData) {
  72. $this->isJoinIndividualData = true;
  73. return $this
  74. ->leftJoin('.individualData', 'indivData');
  75. }
  76. return $this;
  77. }
  78. }