Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

develop
Fab 3 years ago
parent
commit
cf657962cc
12 changed files with 353 additions and 123 deletions
  1. +20
    -10
      Repository/AbstractRepositoryQuery.php
  2. +62
    -32
      Repository/Reminder/ReminderRepositoryQuery.php
  3. +104
    -70
      Repository/Reminder/ReminderStore.php
  4. +3
    -0
      Repository/Site/NewsRepositoryQuery.php
  5. +32
    -0
      Repository/Site/NewsStore.php
  6. +7
    -0
      Repository/Site/PageRepositoryQuery.php
  7. +12
    -0
      Repository/Site/PageStore.php
  8. +16
    -3
      Repository/Ticket/TicketRepositoryQuery.php
  9. +34
    -2
      Repository/Ticket/TicketStore.php
  10. +6
    -5
      Repository/User/UserRepository.php
  11. +23
    -0
      Repository/User/UserRepositoryQuery.php
  12. +34
    -1
      Repository/User/UserStore.php

+ 20
- 10
Repository/AbstractRepositoryQuery.php View File

return $this; return $this;
} }


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

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


public function find() :array
public function find(): array
{ {
return $this->query->getQuery()->getResult(); return $this->query->getQuery()->getResult();
} }


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

public function paginate(int $page = 1, int $limit = 20) public function paginate(int $page = 1, int $limit = 20)
{ {
return $this->paginator->paginate($this->query->getQuery(), $page, $limit); return $this->paginator->paginate($this->query->getQuery(), $page, $limit);


foreach ($words as $k => $v) { foreach ($words as $k => $v) {
if (isset($v[0]) && '.' === $v[0]) { if (isset($v[0]) && '.' === $v[0]) {
$words[$k] = $this->id.$v;
$words[$k] = $this->id . $v;
} }
} }


return $data; return $data;
} }


public function orderBy($field, $sort){
if(substr($field,0,1)=== '.'){
return $this->addOrderBy($field, $sort) ;
}else{
return $this->addOrderBy('.'.$field, $sort) ;
public function orderBy(string $field, string $sort = 'ASC'): self
{
if (substr($field, 0, 1) === '.') {
return $this->addOrderBy($field, $sort);
} else {
return $this->addOrderBy('.' . $field, $sort);
} }
} }

} }



+ 62
- 32
Repository/Reminder/ReminderRepositoryQuery.php View File

namespace Lc\SovBundle\Repository\Reminder; namespace Lc\SovBundle\Repository\Reminder;


use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;


class ReminderRepositoryQuery extends AbstractRepositoryQuery implements ReminderRepositoryQueryInterface class ReminderRepositoryQuery extends AbstractRepositoryQuery implements ReminderRepositoryQueryInterface
{ {
protected $isJoinUser = false;

public function __construct(ReminderRepository $repository, PaginatorInterface $paginator) public function __construct(ReminderRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function filterDone($done = false)
public function filterByDone($done = false): self
{ {
return $this return $this
->andWhere('.done = :done')
->setParameter(':done', $done);
->andWhere('.done = :done')
->setParameter(':done', $done);
} }


public function filterUser($user)
public function joinUser(): self
{ {
if (!$this->isJoinUser) {
$this->isJoinUser = true;

return $this
->leftJoin('.users', 'u');
}
return $this;
}

public function filterByUser(UserInterface $user): self
{
$this->joinUser();
return $this return $this
->leftJoin('.users', 'u')
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF .users')
->setParameter(':user', $user)
->groupBy('.id');
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF .users')
->setParameter(':user', $user);
} }


public function filterCrudAction($crudAction)
public function filterByCrudAction(string $crudAction): self
{ {
if(is_null($crudAction)) {
if (is_null($crudAction)) {
return $this return $this
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
return $this return $this
->andWhere('.crudAction = :crudAction')
->setParameter(':crudAction', $crudAction);
->andWhere('.crudAction = :crudAction')
->setParameter(':crudAction', $crudAction);
} }
} }


public function filterCrudControllerFqcn($crudControllerFqcn)
public function filterByCrudControllerFqcn(string $crudControllerFqcn): self
{ {
if(is_null($crudControllerFqcn)) {
if (is_null($crudControllerFqcn)) {
return $this return $this
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
return $this return $this
->andWhere('.crudControllerFqcn = :crudControllerFqcn')
->setParameter(':crudControllerFqcn', $crudControllerFqcn);
->andWhere('.crudControllerFqcn = :crudControllerFqcn')
->setParameter(':crudControllerFqcn', $crudControllerFqcn);
} }
} }


public function filterEntityId($entityId)
public function filterByEntityId(int $entityId): self
{ {
if(is_null($entityId)) {
if (is_null($entityId)) {
return $this return $this
->andWhere('.entityId IS NULL');
}
else {
->andWhere('.entityId IS NULL');
} else {
return $this return $this
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
} }
} }


public function orderDefault()
public function filterIsNotDone(): self
{ {
return $this return $this
->orderBy('.dateReminder', 'ASC');
->andWhere('.done = 0');
} }


public function filterLikeCrudAction(string $crudAction): self
{
return $this
->andWhere('.crudAction LIKE :crudAction')
->setParameter('crudAction', $crudAction);
}

public function filterLikeCrudControllerFqcn(string $crudControllerFqcn): self
{
return $this
->andWhere('.crudControllerFqcn LIKE :crudControllerFqcn')
->setParameter('crudControllerFqcn', $crudControllerFqcn);
}

public function filterLikeEntityId(int $entityId): self
{
return $this
->andWhere('.entityId LIKE :id')
->setParameter('entityId', $entityId);
}
} }

+ 104
- 70
Repository/Reminder/ReminderStore.php View File



namespace Lc\SovBundle\Repository\Reminder; namespace Lc\SovBundle\Repository\Reminder;


use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class ReminderStore extends AbstractStore implements ReminderStoreInterface class ReminderStore extends AbstractStore implements ReminderStoreInterface
$query = $this->query->create(); $query = $this->query->create();
} }


$query->filterDone();
$query->filterByDone();


if (array_key_exists('user', $params)) { if (array_key_exists('user', $params)) {
$query->filterUser($params['user']);
$query
->filterByUser($params['user'])
->groupBy('.id');
} }


if (array_key_exists('crudAction', $params)) { if (array_key_exists('crudAction', $params)) {
$query->filterCrudAction($params['crudAction']);
$query->filterByCrudAction($params['crudAction']);
} }


if (array_key_exists('crudControllerFqcn', $params)) { if (array_key_exists('crudControllerFqcn', $params)) {
$query->filterCrudControllerFqcn($params['crudControllerFqcn']);
$query->filterByCrudControllerFqcn($params['crudControllerFqcn']);
} }


if (array_key_exists('entityId', $params)) { if (array_key_exists('entityId', $params)) {
$query->filterEntityId($params['entityId']);
$query->filterByEntityId($params['entityId']);
} }


$query->orderDefault();
$query->orderBy('.dateReminder');


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


/*

public function getRemindersByUser($user)
{
$reminderRepo = $this->em->getRepository(ReminderInterface::class);


$reminders = $reminderRepo->findByUser($user);

$entitiesRepo = array();
$entitiesConfig = array();
if (count($reminders) > 0) {
foreach ($reminders as $reminder) {
if ($reminder->getEntityName()) {
if (!isset($entitiesConfig[$reminder->getEntityName()])) {
$entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
}
if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
if (!isset($entitiesRepo[$reminder->getEntityName()])) {
$entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
}

if ($reminder->getEntityId()) {
$reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
}
} else {
$reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
}
}
}
}
return $reminders;
// findByUser
public function getByUser(UserInterface $user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
} }


*/
$query = $this->query->create();


/*
public function findByUser($user)
{
$qb = $this->createQueryBuilder('e')
->leftJoin('e.users', 'u')
->having('COUNT(u.id) = 0')
->orHaving(':user MEMBER OF e.users')
->andWhere('e.done = 0')
->setParameter('user', $user)
->orderBy('e.dateReminder', 'ASC')
->groupBy('e.id');

return $qb->getQuery()->getResult();
$query
->filterByUser($user)
->filterIsNotDone()
->orderBy('.dateReminder')
->groupBy('.id');

return $query->find();
} }


public function findByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId = null)
{
$qb = $this->createQueryBuilder('e');
$qb->leftJoin('e.users', 'u');
$qb->having('COUNT(u.id) = 0');
$qb->orHaving(':user MEMBER OF e.users');
$qb->andWhere('e.done = 0');
$qb->andWhere('e.crudAction LIKE :crudAction');
$qb->andWhere('e.crudControllerFqcn LIKE :entity');
$qb->setParameter('crudAction', $crudAction);
$qb->setParameter('crudControllerFqcn', $crudControllerFqcn);
$qb->setParameter('user', $user);
// findByEasyAdminConfigAndUser
public function getByEasyAdminConfigAndUser(
string $crudAction,
string $crudControllerFqcn,
UserInterface $user,
int $entityId = null,
$query = null
): array {
if (is_null($query)) {
$query = $this->query->create();
}

$query
->filterByUser($user)
->filterLikeCrudAction($crudAction)
->filterLikeCrudControllerFqcn($crudControllerFqcn)
->filterIsNotDone();

if ($entityId) { if ($entityId) {
$qb->andWhere('e.entityId LIKE :id');
$qb->setParameter('entityId', $entityId);
$query
->filterLikeEntityId($entityId);
} }
$qb->orderBy('e.dateReminder', 'ASC');
$qb->groupBy('e.id');
$query
->orderBy('.dateReminder')
->groupBy('.id');

return $query->find();
}


return $qb->getQuery()->getResult();
}*/
// public function findByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId = null)
// {
// $qb = $this->createQueryBuilder('e');
// $qb->leftJoin('e.users', 'u');
// $qb->having('COUNT(u.id) = 0');
// $qb->orHaving(':user MEMBER OF e.users');
// $qb->andWhere('e.done = 0');
// $qb->andWhere('e.crudAction LIKE :crudAction');
// $qb->andWhere('e.crudControllerFqcn LIKE :entity');
// $qb->setParameter('crudAction', $crudAction);
// $qb->setParameter('crudControllerFqcn', $crudControllerFqcn);
// $qb->setParameter('user', $user);
// if ($entityId) {
// $qb->andWhere('e.entityId LIKE :id');
// $qb->setParameter('entityId', $entityId);
// }
// $qb->orderBy('e.dateReminder', 'ASC');
// $qb->groupBy('e.id');
//
// return $qb->getQuery()->getResult();
// }
} }
/*

public function getRemindersByUser($user)
{
$reminderRepo = $this->em->getRepository(ReminderInterface::class);


$reminders = $reminderRepo->findByUser($user);

$entitiesRepo = array();
$entitiesConfig = array();
if (count($reminders) > 0) {
foreach ($reminders as $reminder) {
if ($reminder->getEntityName()) {
if (!isset($entitiesConfig[$reminder->getEntityName()])) {
$entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
}
if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
if (!isset($entitiesRepo[$reminder->getEntityName()])) {
$entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
}

if ($reminder->getEntityId()) {
$reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
}
} else {
$reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
}
}
}
}
return $reminders;
}

*/

+ 3
- 0
Repository/Site/NewsRepositoryQuery.php View File

namespace Lc\SovBundle\Repository\Site; namespace Lc\SovBundle\Repository\Site;


use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery; use Lc\SovBundle\Repository\AbstractRepositoryQuery;


class NewsRepositoryQuery extends AbstractRepositoryQuery implements NewsRepositoryQueryInterface class NewsRepositoryQuery extends AbstractRepositoryQuery implements NewsRepositoryQueryInterface
{ {
use StatusRepositoryQueryTrait;

public function __construct(NewsRepository $repository, PaginatorInterface $paginator) public function __construct(NewsRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);

+ 32
- 0
Repository/Site/NewsStore.php View File

{ {
$this->query = $query; $this->query = $query;
} }

//findLatests
public function getLatests(int $maxResults = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}
$query
->filterIsOnline()
->orderBy('.date', 'DESC');

if ($maxResults) {
$query
->limit($maxResults);
}

return $query->find();
}

public function findLatests($maxResults = 0)
{
$result = $this->findByMerchantQuery()
->orderBy('e.date', 'DESC');

$result->andWhere('e.status = 1');

if ($maxResults) {
$result->setMaxResults($maxResults);
}

return $result->getQuery()->getResult();
}
} }

+ 7
- 0
Repository/Site/PageRepositoryQuery.php View File

{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

public function filterBySlug(string $slug)
{
return $this
->andWhere('.slug = :slug')
->setParameter('slug', $slug);
}
} }

+ 12
- 0
Repository/Site/PageStore.php View File



namespace Lc\SovBundle\Repository\Site; namespace Lc\SovBundle\Repository\Site;


use Lc\SovBundle\Model\Site\PageInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;


class PageStore extends AbstractStore implements PageStoreInterface class PageStore extends AbstractStore implements PageStoreInterface
{ {
$this->query = $query; $this->query = $query;
} }

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

$query
->filterBySlug($slug);

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

+ 16
- 3
Repository/Ticket/TicketRepositoryQuery.php View File

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');
} }
} }

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



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

//countAllOpen
public function countAllOpen($query = null): string
{
if (is_null($query)) {
$query = $this->query->create();
}
$query
->selectCount()
->filterByStatus(Ticket::TICKET_STATUS_OPEN);

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

+ 6
- 5
Repository/User/UserRepository.php View File

$this->_em->flush(); $this->_em->flush();
} }


public function findByRole($role) {
public function findByRole($role)
{
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->andWhere('u.roles LIKE :role')
->setParameter('role', '%'.$role.'%')
->getQuery()
->getResult();
->andWhere('u.roles LIKE :role')
->setParameter('role', '%' . $role . '%')
->getQuery()
->getResult();
} }
} }

+ 23
- 0
Repository/User/UserRepositoryQuery.php View File



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 . '"%');
}
} }

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



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

Loading…
Cancel
Save