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.
|
- <?php
-
- namespace Lc\CaracoleBundle\Repository;
-
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Lc\SovBundle\Repository\StoreInterface;
-
- trait SectionStoreTrait
- {
- protected ?SectionInterface $section = null;
-
- public function setSection(?SectionInterface $section):self
- {
- $this->section = $section;
-
- return $this;
- }
-
- public function isSectionDefined(): bool
- {
- return isset($this->section) && $this->section;
- }
-
- public function addFilterBySectionOptionnal(RepositoryQueryInterface $query): StoreInterface
- {
- if($this->isSectionDefined()) {
- $query->filterBySection($this->section);
- }
-
- return $this;
- }
-
- public function addFilterBySectionRequired(RepositoryQueryInterface $query): StoreInterface
- {
- $this->addFilterBySectionOptionnal($query);
-
- if(!$this->isSectionDefined()) {
- throw new \ErrorException('La Section doit être définie dans '.get_class($this));
- }
-
- return $this;
- }
-
- public function getParents()
- {
- $query = $this->query->create();
- if ($this->section) {
- $query->filterBySection($this->section);
- }
- $query->filterIsParent();
-
- return $query->find();
- }
-
- }
|