Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SectionStoreTrait.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }