選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

76 行
2.1KB

  1. <?php
  2. namespace App\Repository;
  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. public function __construct($repository, PaginatorInterface $paginator)
  13. {
  14. parent::__construct($repository, 'r', $paginator);
  15. }
  16. public function filterIsValid()
  17. {
  18. $this->joinCollectifData();
  19. $this->joinIndividualData();
  20. return $this
  21. ->andWhere('colData.status = 1 OR indivData.status = 1');
  22. }
  23. public function filterByThematic(ArrayCollection $thematicArray): self
  24. {
  25. return $this
  26. ->andWhere('.thematic IN (:thematic)')
  27. ->setParameter(':thematic', $thematicArray);
  28. }
  29. public function filterByDescription(string $description): self
  30. {
  31. return $this
  32. ->andWhere('.description LIKE :description')
  33. ->setParameter(':description', '%' . $description . '%');
  34. }
  35. public function filterByTerritory(ArrayCollection $territoryArray): self
  36. {
  37. $this->joinCollectifData();
  38. $this->joinIndividualData();
  39. return $this
  40. ->andWhere('colData.territory IN (:territory) OR indivData.territory IN (:territory)')
  41. ->setParameter(':territory', $territoryArray);
  42. }
  43. public function joinCollectifData(): self
  44. {
  45. if (!$this->isJoinCollectifData) {
  46. $this->isJoinCollectifData = true;
  47. return $this
  48. ->leftJoin('.collectifData', 'colData');
  49. }
  50. return $this;
  51. }
  52. public function joinIndividualData(): self
  53. {
  54. if (!$this->isJoinIndividualData) {
  55. $this->isJoinIndividualData = true;
  56. return $this
  57. ->leftJoin('.individualData', 'indivData');
  58. }
  59. return $this;
  60. }
  61. }