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.

ReductionCreditStore.php 2.3KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  4. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  5. use Lc\SovBundle\Model\User\UserInterface;
  6. use Lc\CaracoleBundle\Repository\AbstractStore;
  7. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  8. class ReductionCreditStore extends AbstractStore
  9. {
  10. use SectionStoreTrait;
  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->addFilterBySectionOptionnal($query);
  26. $this->addFilterByMerchantViaSectionOptionnal($query);
  27. $query->filterIsOnlineAndOffline();
  28. return $query;
  29. }
  30. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  31. {
  32. return $query;
  33. }
  34. // findReductionCreditsByUser
  35. public function getByTypeAndUser(string $type, UserInterface $user, $query = null)
  36. {
  37. $query = $this->createDefaultQuery($query);
  38. $query
  39. ->filterByType($type)
  40. ->filterByUser($user);
  41. return $query->find();
  42. }
  43. // findReductionGiftToUseByUser
  44. public function getReductionGiftToUseByUser(UserInterface $user, $query = null)
  45. {
  46. $query = $this->createDefaultQuery($query);
  47. $query->filterByUser($user);
  48. return $query->find();
  49. }
  50. // findReductionGiftOwnedByUser
  51. public function getReductionGiftOwnedByUser(UserInterface $user, $query = null)
  52. {
  53. $query = $this->createDefaultQuery($query);
  54. $query
  55. ->filterByOwner($user)
  56. ->filterInactive();
  57. return $query->find();
  58. }
  59. // findReductionGiftOwnedActiveByUser
  60. public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null)
  61. {
  62. $query = $this->createDefaultQuery($query);
  63. $query
  64. ->filterByOwner($user)
  65. ->filterActive();
  66. return $query->find();
  67. }
  68. }