Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

57 lines
1.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository;
  3. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  4. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  5. use Lc\SovBundle\Repository\StoreInterface;
  6. trait SectionStoreTrait
  7. {
  8. protected ?SectionInterface $section = null;
  9. public function setSection(SectionInterface $section):self
  10. {
  11. $this->section = $section;
  12. return $this;
  13. }
  14. public function isSectionDefined(): bool
  15. {
  16. return isset($this->section) && $this->section;
  17. }
  18. public function addFilterBySectionOptionnal(RepositoryQueryInterface $query): StoreInterface
  19. {
  20. if($this->isSectionDefined()) {
  21. $query->filterBySection($this->section);
  22. }
  23. return $this;
  24. }
  25. public function addFilterBySectionRequired(RepositoryQueryInterface $query): StoreInterface
  26. {
  27. $this->addFilterBySectionOptionnal($query);
  28. if(!$this->isSectionDefined()) {
  29. throw new \ErrorException('La Section doit être définie dans '.get_class($this));
  30. }
  31. return $this;
  32. }
  33. public function getParents()
  34. {
  35. $query = $this->query->create();
  36. if ($this->section) {
  37. $query->filterBySection($this->section);
  38. }
  39. $query->filterIsParent();
  40. return $query->find();
  41. }
  42. }