Browse Source

Refactoring services

develop
Guillaume 3 years ago
parent
commit
45e92852ce
4 changed files with 16 additions and 31 deletions
  1. +7
    -6
      Repository/AbstractRepositoryQuery.php
  2. +5
    -21
      Repository/AbstractStore.php
  3. +3
    -2
      Repository/Ticket/TicketStore.php
  4. +1
    -2
      Repository/User/UserStore.php

+ 7
- 6
Repository/AbstractRepositoryQuery.php View File

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;


abstract class AbstractRepositoryQuery abstract class AbstractRepositoryQuery
{ {
public function count(): string public function count(): string
{ {
return $this->query->getQuery() return $this->query->getQuery()
->getSingleScalarResult();
->getSingleScalarResult();
} }


public function findOne()
public function findOne(): ?EntityInterface
{ {
return $this->query->getQuery() return $this->query->getQuery()
->setMaxResults(1)
->getOneOrNullResult();
->setMaxResults(1)
->getOneOrNullResult();
} }


public function find(): array public function find(): array
->setParameter('slug', $slug); ->setParameter('slug', $slug);
} }




} }



+ 5
- 21
Repository/AbstractStore.php View File



abstract class AbstractStore abstract class AbstractStore
{ {
public function createQuery()
public function createQuery($query = null)
{ {
return $this->query->create();
if (is_null($query)) {
$query = $this->query->create();
}
return $query;
} }


public function getRepositoryQuery() public function getRepositoryQuery()


return $query->findOne(); return $query->findOne();
} }

public function getOneByDevAlias(string $devAlias)
{
$query = $this->query->create();

$query->filterByDevAlias($devAlias);

return $query->findOne();
}

//findPageBySlug
public function getOneBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();
$query->filterBySlug($slug);

return $query->findOne();
}

} }

+ 3
- 2
Repository/Ticket/TicketStore.php View File



use App\Entity\Ticket\Ticket; use App\Entity\Ticket\Ticket;
use Lc\SovBundle\Model\Ticket\TicketInterface; use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\User\UserInterface;
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, $query = null): array
public function getByUser(UserInterface $user, $query = null): array
{ {
if (is_null($query)) { if (is_null($query)) {
$query = $this->query->create();
$query = $this->createQuery();
} }


$query->filterByUser($user); $query->filterByUser($user);

+ 1
- 2
Repository/User/UserStore.php View File

$query = $this->query->create(); $query = $this->query->create();
} }


$query
->filterByNewsletter($newsletter);
$query->filterByNewsletter($newsletter);


return $query->find(); return $query->find();
} }

Loading…
Cancel
Save