No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

88 líneas
2.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Lc\CaracoleBundle\Repository\Config\TaxRateStore;
  4. use Lc\CaracoleBundle\Repository\Config\UnitStore;
  5. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
  6. use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
  7. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  8. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
  9. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
  10. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  11. use Lc\CaracoleBundle\Resolver\SectionResolver;
  12. use Lc\ShopBundle\Context\UnitInterface;
  13. use Twig\Extension\AbstractExtension;
  14. use Twig\TwigFunction;
  15. class StoreTwigExtension extends AbstractExtension
  16. {
  17. protected MerchantRepositoryQuery $merchantRepositoryQuery;
  18. protected SectionRepositoryQuery $sectionRepositoryQuery;
  19. protected ReminderStore $reminderStore;
  20. protected MerchantResolver $merchantResolver;
  21. protected SectionResolver $sectionResolver;
  22. protected UnitStore $unitStore;
  23. protected TaxRateStore $taxRateStore;
  24. public function __construct(
  25. MerchantResolver $merchantResolver,
  26. SectionResolver $sectionResolver,
  27. MerchantRepositoryQuery $merchantRepositoryQuery,
  28. SectionRepositoryQuery $sectionRepositoryQuery,
  29. ReminderStore $reminderStore,
  30. UnitStore $unitStore,
  31. TaxRateStore $taxRateStore
  32. ) {
  33. $this->merchantResolver = $merchantResolver;
  34. $this->sectionResolver = $sectionResolver;
  35. $this->merchantRepositoryQuery = $merchantRepositoryQuery;
  36. $this->sectionRepositoryQuery = $sectionRepositoryQuery;
  37. $this->reminderStore = $reminderStore;
  38. $this->unitStore = $unitStore;
  39. $this->taxRateStore = $taxRateStore;
  40. }
  41. public function getFunctions()
  42. {
  43. return array(
  44. new TwigFunction('carac_sections', [$this, 'getSections']),
  45. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  46. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  47. new TwigFunction('carac_units', [$this, 'getUnits']),
  48. new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
  49. );
  50. }
  51. public function getSections()
  52. {
  53. return $this->sectionRepositoryQuery
  54. ->filterByMerchant($this->merchantResolver->getCurrent())
  55. ->find();
  56. }
  57. public function getMerchants()
  58. {
  59. return $this->merchantRepositoryQuery->find();
  60. }
  61. public function getReminders($params = [])
  62. {
  63. return $this->reminderStore
  64. ->setMerchant($this->merchantResolver->getCurrent())
  65. ->setSection($this->sectionResolver->getCurrent())
  66. ->get($params);
  67. }
  68. public function getUnits(){
  69. return $this->unitStore->getAsArray();
  70. }
  71. public function getTaxRates(){
  72. return $this->taxRateStore->getAsArray();
  73. }
  74. }