Bladeren bron

Mise en place createQuery

develop
Guillaume 3 jaren geleden
bovenliggende
commit
bb1d571b07
5 gewijzigde bestanden met toevoegingen van 44 en 125 verwijderingen
  1. +1
    -0
      Repository/AbstractStore.php
  2. +22
    -85
      Repository/Reminder/ReminderStore.php
  3. +4
    -6
      Repository/Site/NewsStore.php
  4. +4
    -11
      Repository/Ticket/TicketStore.php
  5. +13
    -23
      Repository/User/UserStore.php

+ 1
- 0
Repository/AbstractStore.php Bestand weergeven

if (is_null($query)) { if (is_null($query)) {
$query = $this->query->create(); $query = $this->query->create();
} }

return $query; return $query;
} }



+ 22
- 85
Repository/Reminder/ReminderStore.php Bestand weergeven



public function get($params = [], $query = null) public function get($params = [], $query = null)
{ {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);


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


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


if (array_key_exists('crudAction', $params)) { if (array_key_exists('crudAction', $params)) {
// findByUser // findByUser
public function getByUser(UserInterface $user, $query = null): array public function getByUser(UserInterface $user, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);


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


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


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


// findByEasyAdminConfigAndUser // findByEasyAdminConfigAndUser
public function getByEasyAdminConfigAndUser( public function getByEasyAdminConfigAndUser(
string $crudAction,
string $crudControllerFqcn,
UserInterface $user,
int $entityId = null,
$query = null
string $crudAction,
string $crudControllerFqcn,
UserInterface $user,
int $entityId = null,
$query = null
): array { ): array {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);


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


if ($entityId) { if ($entityId) {
$query $query
->filterLikeEntityId($entityId);
->filterLikeEntityId($entityId);
} }
$query $query
->orderBy('.dateReminder')
->groupBy('.id');
->orderBy('.dateReminder')
->groupBy('.id');


return $query->find(); 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;
}

*/
}

+ 4
- 6
Repository/Site/NewsStore.php Bestand weergeven

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


//findLatests
// findLatests
public function getLatests(int $maxResults = 0, $query = null): array public function getLatests(int $maxResults = 0, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);

$query $query
->filterIsOnline() ->filterIsOnline()
->orderBy('.date', 'DESC'); ->orderBy('.date', 'DESC');


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


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

+ 4
- 11
Repository/Ticket/TicketStore.php Bestand weergeven

// getTicketsByUser // getTicketsByUser
public function getByUser(UserInterface $user, $query = null): array public function getByUser(UserInterface $user, $query = null): array
{ {
if (is_null($query)) {
$query = $this->createQuery();
}

$query = $this->createQuery($query);
$query->filterByUser($user); $query->filterByUser($user);

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


// findAllOpen // findAllOpen
public function getOpen(int $limit = 0, $query = null): array public function getOpen(int $limit = 0, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);


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

$query $query
->selectCount() ->selectCount()
->filterByStatus(Ticket::TICKET_STATUS_OPEN); ->filterByStatus(Ticket::TICKET_STATUS_OPEN);

+ 13
- 23
Repository/User/UserStore.php Bestand weergeven

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


//findAllByNewsletter
// findAllByNewsletter
public function getByNewsletter(Newsletter $newsletter, $query = null): array public function getByNewsletter(Newsletter $newsletter, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}

$query = $this->createQuery($query);
$query->filterByNewsletter($newsletter); $query->filterByNewsletter($newsletter);

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


//findByRole
public function getByRole(string $role): array
// findByRole
public function getByRole(string $role, $query = null): array
{ {
$query = $this->query->create();
$query
->filterByRole($role);

$query = $this->createQuery($query);
$query->filterByRole($role);
return $query->find(); return $query->find();
} }


//findByTicketTypesNotification
public function getByTicketTypesNotification(string $ticketType): array
// findByTicketTypesNotification
public function getByTicketTypesNotification(string $ticketType, $query = null): array
{ {
$query = $this->query->create();
$query
->filterByTicketTypeNotification($ticketType);

$query = $this->createQuery($query);
$query->filterByTicketTypeNotification($ticketType);
return $query->find(); return $query->find();
} }


public function getOneByEmail(string $email)
public function getOneByEmail(string $email, $query = null)
{ {
$query = $this->query->create();
$query
->filterByEmail($email);

$query = $this->createQuery($query);
$query->filterByEmail($email);
return $query->findOne(); return $query->findOne();
} }
} }

Laden…
Annuleren
Opslaan