return $this->query->getQuery()->getResult(); | return $this->query->getQuery()->getResult(); | ||||
} | } | ||||
public function limit(int $maxResults): self | |||||
public function limit(int $maxResults) | |||||
{ | { | ||||
return $this->query->setMaxResults($maxResults); | return $this->query->setMaxResults($maxResults); | ||||
} | } |
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function filterByUser(UserInterface $user) | |||||
public function filterByUser(UserInterface $user): self | |||||
{ | { | ||||
return $this | return $this | ||||
->andWhere('.user = :user') | |||||
->setParameter('user', $user); | |||||
->andWhere('.user = :user') | |||||
->setParameter('user', $user); | |||||
} | |||||
public function filterByStatus($statusArray): self | |||||
{ | |||||
return $this | |||||
->andWhere('.status IN (:status)') | |||||
->setParameter('status', $statusArray); | |||||
} | |||||
public function selectCount(): self | |||||
{ | |||||
return $this | |||||
->select('count(r.id) as count'); | |||||
} | } | ||||
} | } |
namespace Lc\SovBundle\Repository\Ticket; | namespace Lc\SovBundle\Repository\Ticket; | ||||
use App\Entity\Ticket\Ticket; | |||||
use Lc\SovBundle\Model\Ticket\TicketInterface; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class TicketStore extends AbstractStore implements TicketStoreInterface | class TicketStore extends AbstractStore implements TicketStoreInterface | ||||
} | } | ||||
// getTicketsByUser | // getTicketsByUser | ||||
public function getByUser($user) | |||||
public function getByUser($user, $query = null): array | |||||
{ | { | ||||
$query = $this->query->create(); | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
$query->filterByUser($user); | $query->filterByUser($user); | ||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
// findAllOpen | |||||
public function getAllOpen(int $limit = 0, $query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
$query | |||||
->filterByStatus(Ticket::TICKET_STATUS_OPEN) | |||||
->limit($limit) | |||||
->orderBy('r.id', 'DESC'); | |||||
return $query->find(); | |||||
} | |||||
// public function findAllOpen($limit = 0) | |||||
// { | |||||
// $query = $this->findByMerchantQuery(); | |||||
// $this->filterStatus($query, [Ticket::TICKET_STATUS_OPEN]); | |||||
// $query->addOrderBy('e.id', 'DESC'); | |||||
// $query->setMaxResults($limit); | |||||
// return $query->getQuery()->getResult(); | |||||
// } | |||||
//countAllOpen | |||||
public function countAllOpen($query = null) | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
$query | |||||
->selectCount() | |||||
->filterByStatus(Ticket::TICKET_STATUS_OPEN); | |||||
return $query->count(); | |||||
} | |||||
// public function countAllOpen() | |||||
// { | |||||
// $query = $this->findByMerchantQuery(); | |||||
// $query->select('count(e.id)'); | |||||
// $this->filterStatus($query, [Ticket::TICKET_STATUS_OPEN]); | |||||
// return $query->getQuery()->getSingleScalarResult(); | |||||
// } | |||||
} | } |
namespace Lc\SovBundle\Repository\User; | namespace Lc\SovBundle\Repository\User; | ||||
use App\Entity\Merchant\Merchant; | |||||
use App\Entity\Newsletter\Newsletter; | |||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | use Lc\SovBundle\Repository\AbstractRepositoryQuery; | ||||
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function filterByNewsletter(Newsletter $newsletter): self | |||||
{ | |||||
return $this | |||||
->andWhere(':newsletter MEMBER OF .newsletters') | |||||
->setParameter('newsletter', $newsletter->getId()); | |||||
} | |||||
public function filterLikeRole(string $role): self | |||||
{ | |||||
return $this | |||||
->andWhere('.roles LIKE :roles') | |||||
->setParameter('roles', '%"' . $role . '"%'); | |||||
} | |||||
public function filterLikeTicketTypeNotification(string $ticketType): self | |||||
{ | |||||
return $this | |||||
->andWhere('.ticketTypesNotification LIKE :ticketType') | |||||
->setParameter('ticketType', '%"' . $ticketType . '"%'); | |||||
} | |||||
} | } |
namespace Lc\SovBundle\Repository\User; | namespace Lc\SovBundle\Repository\User; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use App\Entity\Newsletter\Newsletter; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class UserStore extends AbstractStore implements UserStoreInterface | class UserStore extends AbstractStore implements UserStoreInterface | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
//findAllByNewsletter | |||||
public function getByNewsletter(Newsletter $newsletter, $query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
$query | |||||
->filterByNewsletter($newsletter); | |||||
return $query->find(); | |||||
} | |||||
//findByRole | |||||
public function getByRole(string $role): array | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterLikeRole($role); | |||||
return $query->find(); | |||||
} | |||||
//findByTicketTypesNotification | |||||
public function getByTicketTypesNotification(string $ticketType): array | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterLikeTicketTypeNotification($ticketType); | |||||
return $query->find(); | |||||
} | |||||
} | } |