You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  4. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  5. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  6. use Lc\SovBundle\Model\User\UserInterface;
  7. use Lc\CaracoleBundle\Repository\AbstractStore;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ReductionCreditStore extends AbstractStore
  10. {
  11. use MerchantStoreTrait;
  12. protected ReductionCreditRepositoryQuery $query;
  13. public function __construct(
  14. ReductionCreditRepositoryQuery $query
  15. ) {
  16. $this->query = $query;
  17. }
  18. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  19. {
  20. $query->orderBy('id');
  21. return $query;
  22. }
  23. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  24. {
  25. $this->addFilterByMerchantRequired($query);
  26. $query->filterIsOnlineAndOffline();
  27. return $query;
  28. }
  29. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  30. {
  31. return $query;
  32. }
  33. // findReductionCreditsByUser
  34. public function getByTypeAndUser(string $type, UserInterface $user, $query = null)
  35. {
  36. $query = $this->createDefaultQuery($query);
  37. $query
  38. ->filterByType($type)
  39. ->filterByUser($user);
  40. return $query->find();
  41. }
  42. // findReductionGiftToUseByUser
  43. public function getReductionGiftToUseByUser(UserInterface $user, $query = null)
  44. {
  45. $query = $this->createDefaultQuery($query);
  46. $query->filterByUser($user);
  47. return $query->find();
  48. }
  49. // findReductionGiftOwnedByUser
  50. public function getReductionGiftOwnedByUser(UserInterface $user, $query = null)
  51. {
  52. $query = $this->createDefaultQuery($query);
  53. $query
  54. ->filterByOwner($user)
  55. ->filterInactive();
  56. return $query->find();
  57. }
  58. // findReductionGiftOwnedActiveByUser
  59. public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null)
  60. {
  61. $query = $this->createDefaultQuery($query);
  62. $query
  63. ->filterByOwner($user)
  64. ->filterActive();
  65. return $query->find();
  66. }
  67. //Toutes les reductionGift d'un utilisateur inter/merchant
  68. public function getReductionGiftByUserOutOfContext(UserInterface $user, $query = null)
  69. {
  70. $query = $this->createQuery($query);
  71. $query->filterIsOnlineAndOffline();
  72. $query->filterByUser($user);
  73. $query->filterByType(ReductionCreditModel::TYPE_GIFT);
  74. return $query->find();
  75. }
  76. //Toutes les reductionCredit d'un utilisateur inter/merchant
  77. public function getReductionCreditByUserOutOfContext(UserInterface $user, $query = null)
  78. {
  79. $query = $this->createQuery($query);
  80. $query->filterIsOnlineAndOffline();
  81. $query->filterByUser($user);
  82. $query->filterByType(ReductionCreditModel::TYPE_CREDIT);
  83. return $query->find();
  84. }
  85. }