Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

152 linhas
5.0KB

  1. <?php
  2. namespace Lc\SovBundle\Repository\Reminder;
  3. use Lc\SovBundle\Model\User\UserInterface;
  4. use Lc\SovBundle\Repository\AbstractStore;
  5. class ReminderStore extends AbstractStore implements ReminderStoreInterface
  6. {
  7. protected ReminderRepositoryQueryInterface $query;
  8. public function __construct(ReminderRepositoryQueryInterface $query)
  9. {
  10. $this->query = $query;
  11. }
  12. public function get($params = [], $query = null)
  13. {
  14. if (is_null($query)) {
  15. $query = $this->query->create();
  16. }
  17. $query->filterByDone();
  18. if (array_key_exists('user', $params)) {
  19. $query
  20. ->filterByUser($params['user'])
  21. ->groupBy('.id');
  22. }
  23. if (array_key_exists('crudAction', $params)) {
  24. $query->filterByCrudAction($params['crudAction']);
  25. }
  26. if (array_key_exists('crudControllerFqcn', $params)) {
  27. $query->filterByCrudControllerFqcn($params['crudControllerFqcn']);
  28. }
  29. if (array_key_exists('entityId', $params)) {
  30. $query->filterByEntityId($params['entityId']);
  31. }
  32. $query->orderBy('.dateReminder');
  33. return $query->find();
  34. }
  35. // findByUser
  36. public function getByUser(UserInterface $user, $query = null): array
  37. {
  38. if (is_null($query)) {
  39. $query = $this->query->create();
  40. }
  41. $query = $this->query->create();
  42. $query
  43. ->filterByUser($user)
  44. ->filterIsNotDone()
  45. ->orderBy('.dateReminder')
  46. ->groupBy('.id');
  47. return $query->find();
  48. }
  49. // findByEasyAdminConfigAndUser
  50. public function getByEasyAdminConfigAndUser(
  51. string $crudAction,
  52. string $crudControllerFqcn,
  53. UserInterface $user,
  54. int $entityId = null,
  55. $query = null
  56. ): array {
  57. if (is_null($query)) {
  58. $query = $this->query->create();
  59. }
  60. $query
  61. ->filterByUser($user)
  62. ->filterLikeCrudAction($crudAction)
  63. ->filterLikeCrudControllerFqcn($crudControllerFqcn)
  64. ->filterIsNotDone();
  65. if ($entityId) {
  66. $query
  67. ->filterLikeEntityId($entityId);
  68. }
  69. $query
  70. ->orderBy('.dateReminder')
  71. ->groupBy('.id');
  72. return $query->find();
  73. }
  74. // public function findByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId = null)
  75. // {
  76. // $qb = $this->createQueryBuilder('e');
  77. // $qb->leftJoin('e.users', 'u');
  78. // $qb->having('COUNT(u.id) = 0');
  79. // $qb->orHaving(':user MEMBER OF e.users');
  80. // $qb->andWhere('e.done = 0');
  81. // $qb->andWhere('e.crudAction LIKE :crudAction');
  82. // $qb->andWhere('e.crudControllerFqcn LIKE :entity');
  83. // $qb->setParameter('crudAction', $crudAction);
  84. // $qb->setParameter('crudControllerFqcn', $crudControllerFqcn);
  85. // $qb->setParameter('user', $user);
  86. // if ($entityId) {
  87. // $qb->andWhere('e.entityId LIKE :id');
  88. // $qb->setParameter('entityId', $entityId);
  89. // }
  90. // $qb->orderBy('e.dateReminder', 'ASC');
  91. // $qb->groupBy('e.id');
  92. //
  93. // return $qb->getQuery()->getResult();
  94. // }
  95. }
  96. /*
  97. public function getRemindersByUser($user)
  98. {
  99. $reminderRepo = $this->em->getRepository(ReminderInterface::class);
  100. $reminders = $reminderRepo->findByUser($user);
  101. $entitiesRepo = array();
  102. $entitiesConfig = array();
  103. if (count($reminders) > 0) {
  104. foreach ($reminders as $reminder) {
  105. if ($reminder->getEntityName()) {
  106. if (!isset($entitiesConfig[$reminder->getEntityName()])) {
  107. $entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
  108. }
  109. if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
  110. if (!isset($entitiesRepo[$reminder->getEntityName()])) {
  111. $entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
  112. }
  113. if ($reminder->getEntityId()) {
  114. $reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
  115. }
  116. } else {
  117. $reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
  118. }
  119. }
  120. }
  121. }
  122. return $reminders;
  123. }
  124. */