Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

108 lines
3.0KB

  1. <?php
  2. namespace Lc\SovBundle\Repository\Reminder;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\SovBundle\Model\User\UserInterface;
  5. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  6. class ReminderRepositoryQuery extends AbstractRepositoryQuery implements ReminderRepositoryQueryInterface
  7. {
  8. protected $isJoinUser = false;
  9. public function __construct(ReminderRepository $repository, PaginatorInterface $paginator)
  10. {
  11. parent::__construct($repository, 'r', $paginator);
  12. }
  13. public function filterByDone($done = false): self
  14. {
  15. return $this
  16. ->andWhere('.done = :done')
  17. ->setParameter(':done', $done);
  18. }
  19. public function joinUser(): self
  20. {
  21. if (!$this->isJoinUser) {
  22. $this->isJoinUser = true;
  23. return $this
  24. ->leftJoin('.users', 'u');
  25. }
  26. return $this;
  27. }
  28. public function filterByUser(UserInterface $user): self
  29. {
  30. $this->joinUser();
  31. return $this
  32. ->having('COUNT(u.id) = 0')
  33. ->orHaving(':user MEMBER OF .users')
  34. ->setParameter(':user', $user);
  35. }
  36. public function filterByCrudAction(string $crudAction): self
  37. {
  38. if (is_null($crudAction)) {
  39. return $this
  40. ->andWhere('.crudControllerFqcn IS NULL');
  41. } else {
  42. return $this
  43. ->andWhere('.crudAction = :crudAction')
  44. ->setParameter(':crudAction', $crudAction);
  45. }
  46. }
  47. public function filterByCrudControllerFqcn(string $crudControllerFqcn): self
  48. {
  49. if (is_null($crudControllerFqcn)) {
  50. return $this
  51. ->andWhere('.crudControllerFqcn IS NULL');
  52. } else {
  53. return $this
  54. ->andWhere('.crudControllerFqcn = :crudControllerFqcn')
  55. ->setParameter(':crudControllerFqcn', $crudControllerFqcn);
  56. }
  57. }
  58. public function filterByEntityId(int $entityId): self
  59. {
  60. if (is_null($entityId)) {
  61. return $this
  62. ->andWhere('.entityId IS NULL');
  63. } else {
  64. return $this
  65. ->andWhere('.entityId = :entityId')
  66. ->setParameter(':entityId', $entityId);
  67. }
  68. }
  69. public function filterIsNotDone(): self
  70. {
  71. return $this
  72. ->andWhere('.done = 0');
  73. }
  74. public function filterLikeCrudAction(string $crudAction): self
  75. {
  76. return $this
  77. ->andWhere('.crudAction LIKE :crudAction')
  78. ->setParameter('crudAction', $crudAction);
  79. }
  80. public function filterLikeCrudControllerFqcn(string $crudControllerFqcn): self
  81. {
  82. return $this
  83. ->andWhere('.crudControllerFqcn LIKE :crudControllerFqcn')
  84. ->setParameter('crudControllerFqcn', $crudControllerFqcn);
  85. }
  86. public function filterLikeEntityId(int $entityId): self
  87. {
  88. return $this
  89. ->andWhere('.entityId LIKE :id')
  90. ->setParameter('entityId', $entityId);
  91. }
  92. }