Kaynağa Gözat

Reminder

develop
Charly 3 yıl önce
ebeveyn
işleme
796d31d1db
3 değiştirilmiş dosya ile 160 ekleme ve 104 silme
  1. +0
    -1
      Repository/AbstractRepositoryQuery.php
  2. +62
    -32
      Repository/Reminder/ReminderRepositoryQuery.php
  3. +98
    -71
      Repository/Reminder/ReminderStore.php

+ 0
- 1
Repository/AbstractRepositoryQuery.php Dosyayı Görüntüle

@@ -108,6 +108,5 @@ abstract class AbstractRepositoryQuery
return $this->addOrderBy('.' . $field, $sort);
}
}

}


+ 62
- 32
Repository/Reminder/ReminderRepositoryQuery.php Dosyayı Görüntüle

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

+ 98
- 71
Repository/Reminder/ReminderStore.php Dosyayı Görüntüle

@@ -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,125 @@ 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): array
{
$query = $this->query->create();

*/
$query
->filterByUser($user)
->filterIsNotDone()
->orderBy('.dateReminder')
->groupBy('.id');

/*
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();
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(
$crudAction,
$crudControllerFqcn,
UserInterface $user,
$entityId = null
): array {
$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 $qb->getQuery()->getResult();
}*/
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);
// 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;
}

*/

Yükleniyor…
İptal
Kaydet