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.

64 lines
2.0KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
  4. use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
  5. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  6. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
  7. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  8. use Lc\CaracoleBundle\Resolver\SectionResolver;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFunction;
  11. class StoreTwigExtension extends AbstractExtension
  12. {
  13. protected $merchantRepository;
  14. protected $sectionRepository;
  15. protected ReminderStore $reminderStore;
  16. protected MerchantResolver $merchantResolver;
  17. protected SectionResolver $sectionResolver;
  18. public function __construct(
  19. MerchantResolver $merchantResolver,
  20. SectionResolver $sectionResolver,
  21. MerchantRepositoryQuery $merchantRepository,
  22. SectionRepository $sectionRepository,
  23. ReminderStore $reminderStore
  24. ) {
  25. $this->merchantResolver = $merchantResolver;
  26. $this->sectionResolver = $sectionResolver;
  27. $this->merchantRepository = $merchantRepository;
  28. $this->sectionRepository = $sectionRepository;
  29. $this->reminderStore = $reminderStore;
  30. }
  31. public function getFunctions()
  32. {
  33. return array(
  34. new TwigFunction('carac_sections', [$this, 'getSections']),
  35. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  36. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  37. );
  38. }
  39. public function getSections()
  40. {
  41. return $this->sectionRepository->findAll();
  42. }
  43. public function getMerchants()
  44. {
  45. return $this->merchantRepository->findAll();
  46. }
  47. public function getReminders($params = [])
  48. {
  49. return $this->reminderStore
  50. ->setMerchant($this->merchantResolver->getCurrent())
  51. ->setSection($this->sectionResolver->getCurrent())
  52. ->get($params);
  53. }
  54. }