lib/composer/DiscountBundle/src/VisualMedia/DiscountBundle/Manager/DiscountRegistryManager.php line 58

Open in your IDE?
  1. <?php
  2. /**
  3. * Discount Registry Manager
  4. *
  5. * @author Bertin van den Ham <b.vandenham@dappr.nl>
  6. */
  7. namespace VisualMedia\DiscountBundle\Manager;
  8. use VisualMedia\DiscountBundle\Entity\DiscountRegistry;
  9. use VisualMedia\DiscountBundle\Repository\DiscountRegistryRepository;
  10. use VisualMedia\LisaBundle\Component\ManagerData;
  11. /**
  12. * Discount Registry Manager
  13. */
  14. class DiscountRegistryManager extends DiscountRegistryRepository
  15. {
  16. /**
  17. * {@inheritDoc}
  18. */
  19. public static function getEntityName(): string
  20. {
  21. return DiscountRegistry::class;
  22. }
  23. /**
  24. * @param string $email
  25. * @param bool|null $redeemed
  26. * @param int|null $limit
  27. * @return DiscountRegistry[]"null
  28. */
  29. public function getDiscountRegistriesByInvoiceEmail(string $email, bool $redeemed = null, int $limit = null): ?array
  30. {
  31. $conditions = array(
  32. DiscountRegistryRepository::OPTION_INVOICE_EMAIL => $email,
  33. );
  34. if (is_bool($redeemed)) {
  35. $conditions = array_merge($conditions, array(DiscountRegistryRepository::OPTION_REDEEMED => $redeemed));
  36. }
  37. $discountRegistries = $this->getIndex(new ManagerData($conditions, array('amount' => 'DESC'), $limit));
  38. if (empty($discountRegistries)) {
  39. return null;
  40. }
  41. return $discountRegistries;
  42. }
  43. /**
  44. * @param string $email
  45. * @param string $discountType
  46. * @param bool|null $redeemed
  47. * @param int|null $limit
  48. * @return DiscountRegistry[]"null
  49. */
  50. public function getDiscountRegistriesByInvoiceEmailAndDiscountType(string $email, string $discountType, bool $redeemed = null, int $limit = null): ?array
  51. {
  52. $conditions = [
  53. DiscountRegistryRepository::OPTION_INVOICE_EMAIL => $email,
  54. DiscountRegistryRepository::OPTION_JOIN_DISCOUNT => true,
  55. DiscountRegistryRepository::OPTION_DISCOUNT_TYPE => $discountType
  56. ];
  57. if (is_bool($redeemed)) {
  58. $conditions = array_merge($conditions, [ DiscountRegistryRepository::OPTION_REDEEMED => $redeemed ]);
  59. }
  60. $discountRegistries = $this->getIndex(new ManagerData($conditions, [ 'amount' => 'DESC' ], $limit));
  61. if (empty($discountRegistries)) {
  62. return null;
  63. }
  64. return $discountRegistries;
  65. }
  66. }