|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
-
- namespace Lc\SovBundle\Repository;
-
- use Lc\SovBundle\Doctrine\EntityInterface;
- use Lc\SovBundle\Model\Site\PageInterface;
-
- abstract class AbstractStore implements StoreInterface
- {
- public function createDefaultQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface
- {
- $query = $this->createQuery($query);
- $query->resetRelationsJoin();
- $this->filtersDefault($query);
- $this->relationsDefault($query);
- $this->orderByDefault($query);
- return $query;
- }
-
- public function createQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface
- {
- if (is_null($query)) {
- $query = $this->query->create();
- }
-
- return $query;
- }
- /*
- public function orderByDefault(RepositoryQueryInterface $query)
- {
- return $query;
- }
-
- public function filtersDefault(RepositoryQueryInterface $query)
- {
- $query->filterIsOnlineAndOffline();
- return $query;
- }
-
- public function relationsDefault($query)
- {
- return $query;
- }
- */
- public function getRepositoryQuery()
- {
- return $this->query;
- }
-
- public function getOneById(int $id)
- {
- $query = $this->query->create();
-
- $query->filterById($id);
-
- return $query->findOne();
- }
-
- public function getOneBySlug(string $slug, bool $isOnline = true, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterBySlug($slug);
-
- if ($isOnline) {
- $query->filterIsOnline();
- }
-
- return $query->findOne();
- }
-
- public function getOneByDevAlias(string $devAlias, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterByDevAlias($devAlias);
- return $query->findOne();
- }
-
- public function getOneOnlineByDevAlias(string $devAlias, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query
- ->filterByDevAlias($devAlias)
- ->filterIsOnline();
-
- return $query->findOne();
- }
-
- public function getOneByOldUrl(string $oldUrl, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query
- ->filterByOldUrl($oldUrl)
- ->filterIsOnline();
-
- return $query->findOne();
- }
-
- public function get($query = null)
- {
- $query = $this->createDefaultQuery($query);
- return $query->find();
- }
-
- public function getAll($query = null)
- {
- $query = $this->createQuery($query);
- $query->filterIsOnlineAndOffline();
- return $query->find();
- }
-
- public function getOnline($query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterIsOnline();
- return $query->find();
- }
-
- public function getOnlineAndOffline($query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterIsOnlineAndOffline();
- return $query->find();
- }
-
- public function getParent(bool $isOnline = true, $query = null)
- {
- $query = $this->createDefaultQuery($query);
-
- if ($isOnline) {
- $query->filterIsOnline();
- }
-
- $query->filterIsParent();
-
- return $query->find();
- }
- }
|