ソースを参照

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

develop
Fab 3年前
コミット
cf657962cc
12個のファイルの変更353行の追加123行の削除
  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 ファイルの表示

@@ -46,19 +46,29 @@ abstract class AbstractRepositoryQuery
return $this;
}

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

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

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

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

public function paginate(int $page = 1, int $limit = 20)
{
return $this->paginator->paginate($this->query->getQuery(), $page, $limit);
@@ -76,7 +86,7 @@ abstract class AbstractRepositoryQuery

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

@@ -90,13 +100,13 @@ abstract class AbstractRepositoryQuery
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 ファイルの表示

@@ -3,75 +3,105 @@
namespace Lc\SovBundle\Repository\Reminder;

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

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

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

public function filterDone($done = false)
public function filterByDone($done = false): self
{
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
->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
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
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
->andWhere('.crudControllerFqcn IS NULL');
}
else {
->andWhere('.crudControllerFqcn IS NULL');
} else {
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
->andWhere('.entityId IS NULL');
}
else {
->andWhere('.entityId IS NULL');
} else {
return $this
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
->andWhere('.entityId = :entityId')
->setParameter(':entityId', $entityId);
}
}

public function orderDefault()
public function filterIsNotDone(): self
{
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 ファイルの表示

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

namespace Lc\SovBundle\Repository\Reminder;

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

class ReminderStore extends AbstractStore implements ReminderStoreInterface
@@ -19,99 +20,132 @@ class ReminderStore extends AbstractStore implements ReminderStoreInterface
$query = $this->query->create();
}

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

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

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

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

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

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

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) {
$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 ファイルの表示

@@ -3,10 +3,13 @@
namespace Lc\SovBundle\Repository\Site;

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

class NewsRepositoryQuery extends AbstractRepositoryQuery implements NewsRepositoryQueryInterface
{
use StatusRepositoryQueryTrait;

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

+ 32
- 0
Repository/Site/NewsStore.php ファイルの表示

@@ -12,4 +12,36 @@ class NewsStore extends AbstractStore implements NewsStoreInterface
{
$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 ファイルの表示

@@ -11,4 +11,11 @@ class PageRepositoryQuery extends AbstractRepositoryQuery implements PageReposit
{
parent::__construct($repository, 'r', $paginator);
}

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

+ 12
- 0
Repository/Site/PageStore.php ファイルの表示

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

namespace Lc\SovBundle\Repository\Site;

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

class PageStore extends AbstractStore implements PageStoreInterface
@@ -12,4 +13,15 @@ class PageStore extends AbstractStore implements PageStoreInterface
{
$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 ファイルの表示

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

+ 34
- 2
Repository/Ticket/TicketStore.php ファイルの表示

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

//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 ファイルの表示

@@ -29,11 +29,12 @@ class UserRepository extends AbstractRepository
$this->_em->flush();
}

public function findByRole($role) {
public function findByRole($role)
{
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 ファイルの表示

@@ -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 ファイルの表示

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

読み込み中…
キャンセル
保存