Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

StoreTwigExtension.php 2.2KB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Repository\Section\SectionRepositoryQuery;
  8. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  9. use Lc\CaracoleBundle\Resolver\SectionResolver;
  10. use Twig\Extension\AbstractExtension;
  11. use Twig\TwigFunction;
  12. class StoreTwigExtension extends AbstractExtension
  13. {
  14. protected MerchantRepositoryQuery $merchantRepositoryQuery;
  15. protected SectionRepositoryQuery $sectionRepositoryQuery;
  16. protected ReminderStore $reminderStore;
  17. protected MerchantResolver $merchantResolver;
  18. protected SectionResolver $sectionResolver;
  19. public function __construct(
  20. MerchantResolver $merchantResolver,
  21. SectionResolver $sectionResolver,
  22. MerchantRepositoryQuery $merchantRepositoryQuery,
  23. SectionRepositoryQuery $sectionRepositoryQuery,
  24. ReminderStore $reminderStore
  25. ) {
  26. $this->merchantResolver = $merchantResolver;
  27. $this->sectionResolver = $sectionResolver;
  28. $this->merchantRepositoryQuery = $merchantRepositoryQuery;
  29. $this->sectionRepositoryQuery = $sectionRepositoryQuery;
  30. $this->reminderStore = $reminderStore;
  31. }
  32. public function getFunctions()
  33. {
  34. return array(
  35. new TwigFunction('carac_sections', [$this, 'getSections']),
  36. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  37. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  38. );
  39. }
  40. public function getSections()
  41. {
  42. return $this->sectionRepositoryQuery
  43. ->filterByMerchant($this->merchantResolver->getCurrent())
  44. ->find();
  45. }
  46. public function getMerchants()
  47. {
  48. return $this->merchantRepositoryQuery->find();
  49. }
  50. public function getReminders($params = [])
  51. {
  52. return $this->reminderStore
  53. ->setMerchant($this->merchantResolver->getCurrent())
  54. ->setSection($this->sectionResolver->getCurrent())
  55. ->get($params);
  56. }
  57. }