return $this; | return $this; | ||||
} | } | ||||
/*public function andIsOnline(){ | |||||
}*/ | |||||
public function andWhereStatus($dqlId, $status){ | |||||
$this->andWhere($dqlId.'.status = :status'); | |||||
$this->setParameter('status', $status); | |||||
return $this; | |||||
} | |||||
} | } |
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
use Doctrine\ORM\QueryBuilder; | use Doctrine\ORM\QueryBuilder; | ||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\SovBundle\Doctrine\EntityInterface; | use Lc\SovBundle\Doctrine\EntityInterface; | ||||
abstract class AbstractRepositoryQuery | |||||
abstract class AbstractRepositoryQuery implements RepositoryQueryInterface | |||||
{ | { | ||||
use StatusRepositoryQueryTrait; | |||||
use TreeRepositoryQueryTrait; | |||||
protected ServiceEntityRepository $repository; | protected ServiceEntityRepository $repository; | ||||
protected QueryBuilder $query; | protected QueryBuilder $query; | ||||
return $data; | return $data; | ||||
} | } | ||||
public function groupBy(string $field): self | |||||
{ | |||||
if (substr($field, 0, 1) === '.') { | |||||
return $this->groupBy($field) ; | |||||
} else { | |||||
return $this->groupBy('.'.$field) ; | |||||
} | |||||
} | |||||
public function orderBy(string $field, string $sort = 'ASC'): self | public function orderBy(string $field, string $sort = 'ASC'): self | ||||
{ | { | ||||
if (substr($field, 0, 1) === '.') { | if (substr($field, 0, 1) === '.') { | ||||
->setParameter('id', $id); | ->setParameter('id', $id); | ||||
} | } | ||||
/* | |||||
* DEVALIAS | |||||
*/ | |||||
public function filterByDevAlias(string $devAlias): self | public function filterByDevAlias(string $devAlias): self | ||||
{ | { | ||||
return $this | return $this | ||||
->setParameter('devAlias', $devAlias); | ->setParameter('devAlias', $devAlias); | ||||
} | } | ||||
/* | |||||
* SLUG | |||||
*/ | |||||
public function filterBySlug(string $slug) | public function filterBySlug(string $slug) | ||||
{ | { | ||||
return $this | return $this | ||||
->setParameter('slug', $slug); | ->setParameter('slug', $slug); | ||||
} | } | ||||
/* | |||||
* TREE | |||||
*/ | |||||
public function filterIsParent() | |||||
{ | |||||
return $this->andWhere('.parent is NULL'); | |||||
} | |||||
public function filterIsChildren() | |||||
{ | |||||
return $this->andWhere('.parent is NOT NULL'); | |||||
} | |||||
public function filterByParent(EntityInterface $parent) | |||||
{ | |||||
return $this->andWhere('.parent = :parent')->setParameter('parent', $parent); | |||||
} | |||||
/* | |||||
* STATUS | |||||
*/ | |||||
public function filterByStatus(int $status):self | |||||
{ | |||||
return $this->andWhereStatus($this->id, $status); | |||||
} | |||||
public function filterIsOffline():self | |||||
{ | |||||
return $this->andWhereStatus($this->id, 0); | |||||
} | |||||
public function filterIsOnline():self | |||||
{ | |||||
return $this->andWhereStatus($this->id, 1); | |||||
} | |||||
public function filterIsDeleted():self | |||||
{ | |||||
return $this->andWhereStatus($this->id, -1); | |||||
} | |||||
public function filterIsOnlineAndOffline():self | |||||
{ | |||||
return $this->andWhere('.status >= 0'); | |||||
} | |||||
} | } | ||||
namespace Lc\SovBundle\Repository; | namespace Lc\SovBundle\Repository; | ||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
use Lc\SovBundle\Model\Site\PageInterface; | use Lc\SovBundle\Model\Site\PageInterface; | ||||
abstract class AbstractStore | |||||
abstract class AbstractStore implements StoreInterface | |||||
{ | { | ||||
public function createQuery($query = null) | |||||
public function createDefaultQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface | |||||
{ | |||||
$query = $this->createQuery($query); | |||||
$this->filtersDefault($query); | |||||
$this->relationsDefault($query); | |||||
$this->orderByDefault($query); | |||||
return $query; | |||||
} | |||||
public function createQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface | |||||
{ | { | ||||
if (is_null($query)) { | if (is_null($query)) { | ||||
$query = $this->query->create(); | $query = $this->query->create(); | ||||
return $query; | 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() | public function getRepositoryQuery() | ||||
{ | { | ||||
return $this->query; | return $this->query; | ||||
return $query->findOne(); | 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, bool $isOnline = true, $query = null) | |||||
{ | |||||
$query = $this->createDefaultQuery($query); | |||||
$query->filterByDevAlias($devAlias); | |||||
if ($isOnline) { | |||||
$query->filterIsOnline(); | |||||
} | |||||
return $query->findOne(); | |||||
} | |||||
public function get($query = null) | |||||
{ | |||||
$query = $this->createDefaultQuery($query); | |||||
return $query->find(); | |||||
} | |||||
public function getOnline($query = null) | |||||
{ | |||||
$query = $this->createDefaultQuery($query); | |||||
$query->filterIsOnline(); | |||||
return $query->find(); | |||||
} | |||||
public function getParent(bool $isOnline = true, $query = null) | |||||
{ | |||||
$query = $this->createDefaultQuery($query); | |||||
if ($isOnline) { | |||||
$query->filterIsOnline(); | |||||
} | |||||
$query->filterIsParent(); | |||||
return $query->find(); | |||||
} | |||||
} | } |
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class ReminderStore extends AbstractStore implements ReminderStoreInterface | class ReminderStore extends AbstractStore implements ReminderStoreInterface | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function get($params = [], $query = null) | public function get($params = [], $query = null) | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query->filterByDone(); | $query->filterByDone(); | ||||
// findByUser | // findByUser | ||||
public function getByUser(UserInterface $user, $query = null): array | public function getByUser(UserInterface $user, $query = null): array | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query = $this->query->create(); | $query = $this->query->create(); | ||||
int $entityId = null, | int $entityId = null, | ||||
$query = null | $query = null | ||||
): array { | ): array { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query | $query | ||||
->filterByUser($user) | ->filterByUser($user) |
<?php | |||||
namespace Lc\SovBundle\Repository; | |||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | |||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
interface RepositoryQueryInterface | |||||
{ | |||||
public function create(); | |||||
public function call(callable $fn): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function count(): string; | |||||
public function findOne(): ?EntityInterface; | |||||
public function find(): array; | |||||
public function limit(int $maxResults); | |||||
public function paginate(int $page = 1, int $limit = 20); | |||||
public function getRepository(): ServiceEntityRepository; | |||||
public function groupBy(string $field): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function orderBy(string $field, string $sort = 'ASC'): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterById(int $id); | |||||
public function filterByDevAlias(string $devAlias): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterBySlug(string $slug); | |||||
public function filterIsParent(); | |||||
public function filterIsChildren(); | |||||
public function filterByParent(EntityInterface $parent); | |||||
public function filterByStatus($status): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterIsOffline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterIsOnline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterIsDeleted(): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
public function filterIsOnlineAndOffline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
} |
namespace Lc\SovBundle\Repository\Site; | namespace Lc\SovBundle\Repository\Site; | ||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class NewsStore extends AbstractStore implements NewsStoreInterface | class NewsStore extends AbstractStore implements NewsStoreInterface | ||||
{ | { | ||||
protected NewsRepositoryQueryInterface $query; | protected NewsRepositoryQueryInterface $query; | ||||
public function __construct(NewsRepositoryQueryInterface $query) | public function __construct(NewsRepositoryQueryInterface $query) | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
// findLatests | // findLatests | ||||
public function getLatests(int $maxResults = 0, $query = null): array | public function getLatests(int $maxResults = 0, $query = null): array | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query | $query | ||||
->filterIsOnline() | ->filterIsOnline() |
use Lc\SovBundle\Model\Site\PageInterface; | use Lc\SovBundle\Model\Site\PageInterface; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class PageStore extends AbstractStore implements PageStoreInterface | class PageStore extends AbstractStore implements PageStoreInterface | ||||
{ | { | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('position'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->filterIsOnlineAndOffline(); | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\SovBundle\Repository; | |||||
trait StatusRepositoryQueryTrait | |||||
{ | |||||
public function filterByStatus(int $status):self | |||||
{ | |||||
return $this->andWhere('.status = :status')->setParameter(':status', $status); | |||||
} | |||||
public function filterIsOffline():self | |||||
{ | |||||
return $this->andWhere('.status = :status')->setParameter(':status', 0); | |||||
} | |||||
public function filterIsOnline():self | |||||
{ | |||||
return $this->andWhere('.status = :status')->setParameter(':status', 1); | |||||
} | |||||
public function filterIsOnlineAndOffline():self | |||||
{ | |||||
return $this->andWhere('.status >= 0'); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\SovBundle\Repository; | |||||
interface StoreInterface | |||||
{ | |||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface; | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface; | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface; | |||||
public function createDefaultQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface; | |||||
public function createQuery(RepositoryQueryInterface $query = null): RepositoryQueryInterface; | |||||
public function getRepositoryQuery(); | |||||
public function getOneById(int $id); | |||||
public function getOneBySlug(string $slug, bool $isOnline = true, $query = null); | |||||
public function getOneByDevAlias(string $devAlias, bool $isOnline = true, $query = null); | |||||
public function get($query = null); | |||||
public function getOnline($query = null); | |||||
public function getParent(bool $isOnline = true, $query = null); | |||||
} |
namespace Lc\SovBundle\Repository\Ticket; | namespace Lc\SovBundle\Repository\Ticket; | ||||
use App\Entity\Ticket\Ticket; | use App\Entity\Ticket\Ticket; | ||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | |||||
use Lc\SovBundle\Model\Ticket\TicketInterface; | use Lc\SovBundle\Model\Ticket\TicketInterface; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class TicketStore extends AbstractStore implements TicketStoreInterface | class TicketStore extends AbstractStore implements TicketStoreInterface | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
// getTicketsByUser | // getTicketsByUser | ||||
public function getByUser(UserInterface $user, $query = null): array | public function getByUser(UserInterface $user, $query = null): array | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query->filterByUser($user); | $query->filterByUser($user); | ||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
// findAllOpen | // findAllOpen | ||||
public function getOpen(int $limit = 0, $query = null): array | public function getOpen(int $limit = 0, $query = null): array | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query | $query | ||||
->filterByStatus(Ticket::TICKET_STATUS_OPEN) | ->filterByStatus(Ticket::TICKET_STATUS_OPEN) | ||||
// countAllOpen | // countAllOpen | ||||
public function countOpen($query = null): string | public function countOpen($query = null): string | ||||
{ | { | ||||
$query = $this->createQuery($query); | |||||
$query = $this->createDefaultQuery($query); | |||||
$query | $query | ||||
->selectCount() | ->selectCount() |
<?php | |||||
namespace Lc\SovBundle\Repository; | |||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
trait TreeRepositoryQueryTrait | |||||
{ | |||||
public function filterIsParent() | |||||
{ | |||||
return $this->andWhere('.parent is NULL'); | |||||
} | |||||
public function filterIsChildren() | |||||
{ | |||||
return $this->andWhere('.parent is NOT NULL'); | |||||
} | |||||
public function filterByParent(EntityInterface $parent) | |||||
{ | |||||
return $this->andWhere('.parent = :parent')->setParameter('parent', $parent); | |||||
} | |||||
} |
namespace Lc\SovBundle\Repository\User; | namespace Lc\SovBundle\Repository\User; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class GroupUserStore extends AbstractStore implements GroupUserStoreInterface | class GroupUserStore extends AbstractStore implements GroupUserStoreInterface | ||||
{ | { | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
} | } |
use App\Entity\Newsletter\Newsletter; | use App\Entity\Newsletter\Newsletter; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class UserStore extends AbstractStore implements UserStoreInterface | class UserStore extends AbstractStore implements UserStoreInterface | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
// findAllByNewsletter | // findAllByNewsletter | ||||
public function getByNewsletter(Newsletter $newsletter, $query = null): array | public function getByNewsletter(Newsletter $newsletter, $query = null): array | ||||
{ | { |