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.

66 lines
1.7KB

  1. <?php
  2. namespace Lc\PietroBundle\Repository\Search;
  3. use Lc\PietroBundle\Model\Thematic;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Lc\SovBundle\Repository\AbstractStore;
  6. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  7. use Lc\SovBundle\Repository\StoreInterface;
  8. class SearchStore extends AbstractStore implements StoreInterface
  9. {
  10. public function __construct($query)
  11. {
  12. $this->query = $query;
  13. }
  14. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  15. {
  16. $query->orderBy('id');
  17. return $query;
  18. }
  19. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  20. {
  21. $query->filterIsValid();
  22. return $query;
  23. }
  24. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  25. {
  26. return $query;
  27. }
  28. public function filterSearch(
  29. ?string $subthematic,
  30. ArrayCollection $territoryArray,
  31. ArrayCollection $thematicArray,
  32. $query = null
  33. ) {
  34. $query = $this->createDefaultQuery($query);
  35. if (!($thematicArray->isEmpty())) {
  36. $query->filterByThematic($thematicArray);
  37. }
  38. if (!($territoryArray->isEmpty())) {
  39. $query->filterByTerritory($territoryArray);
  40. }
  41. if (!empty($subthematic)) {
  42. $query->filterBySubthematicName($subthematic);
  43. }
  44. return $query->find();
  45. }
  46. public function getByThematic(Thematic $thematic, $query = null)
  47. {
  48. $query = $this->createDefaultQuery($query);
  49. $query->filterByThematic(new ArrayCollection([$thematic]));
  50. return $query->find();
  51. }
  52. }