Charly 3 år sedan
förälder
incheckning
777f3aa86e
5 ändrade filer med 126 tillägg och 7 borttagningar
  1. +1
    -1
      Repository/AbstractRepositoryQuery.php
  2. +16
    -3
      Repository/Ticket/TicketRepositoryQuery.php
  3. +52
    -2
      Repository/Ticket/TicketStore.php
  4. +23
    -0
      Repository/User/UserRepositoryQuery.php
  5. +34
    -1
      Repository/User/UserStore.php

+ 1
- 1
Repository/AbstractRepositoryQuery.php Visa fil

@@ -64,7 +64,7 @@ abstract class AbstractRepositoryQuery
return $this->query->getQuery()->getResult();
}

public function limit(int $maxResults): self
public function limit(int $maxResults)
{
return $this->query->setMaxResults($maxResults);
}

+ 16
- 3
Repository/Ticket/TicketRepositoryQuery.php Visa fil

@@ -13,10 +13,23 @@ class TicketRepositoryQuery extends AbstractRepositoryQuery implements TicketRep
parent::__construct($repository, 'r', $paginator);
}

public function filterByUser(UserInterface $user)
public function filterByUser(UserInterface $user): self
{
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');
}
}

+ 52
- 2
Repository/Ticket/TicketStore.php Visa fil

@@ -2,6 +2,8 @@

namespace Lc\SovBundle\Repository\Ticket;

use App\Entity\Ticket\Ticket;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Repository\AbstractStore;

class TicketStore extends AbstractStore implements TicketStoreInterface
@@ -14,12 +16,60 @@ class TicketStore extends AbstractStore implements TicketStoreInterface
}

// 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);

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();
// }
}

+ 23
- 0
Repository/User/UserRepositoryQuery.php Visa fil

@@ -2,6 +2,8 @@

namespace Lc\SovBundle\Repository\User;

use App\Entity\Merchant\Merchant;
use App\Entity\Newsletter\Newsletter;
use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

@@ -11,4 +13,25 @@ class UserRepositoryQuery extends AbstractRepositoryQuery implements UserReposit
{
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 . '"%');
}
}

+ 34
- 1
Repository/User/UserStore.php Visa fil

@@ -2,7 +2,7 @@

namespace Lc\SovBundle\Repository\User;

use Lc\SovBundle\Model\User\UserInterface;
use App\Entity\Newsletter\Newsletter;
use Lc\SovBundle\Repository\AbstractStore;

class UserStore extends AbstractStore implements UserStoreInterface
@@ -13,4 +13,37 @@ class UserStore extends AbstractStore implements UserStoreInterface
{
$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();
}
}

Laddar…
Avbryt
Spara