|
- <?php
-
- namespace Lc\CaracoleBundle\Twig;
-
- use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
- use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFunction;
-
- class StoreTwigExtension extends AbstractExtension
- {
- protected $merchantRepository;
- protected $sectionRepository;
- protected ReminderStore $reminderStore;
- protected MerchantResolver $merchantResolver;
- protected SectionResolver $sectionResolver;
-
- public function __construct(
- MerchantResolver $merchantResolver,
- SectionResolver $sectionResolver,
- MerchantRepositoryQuery $merchantRepository,
- SectionRepository $sectionRepository,
- ReminderStore $reminderStore
- ) {
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- $this->merchantRepository = $merchantRepository;
- $this->sectionRepository = $sectionRepository;
- $this->reminderStore = $reminderStore;
- }
-
- public function getFunctions()
- {
- return array(
- new TwigFunction('carac_sections', [$this, 'getSections']),
- new TwigFunction('carac_merchants', [$this, 'getMerchants']),
- new TwigFunction('carac_reminders', [$this, 'getReminders']),
- );
- }
-
- public function getSections()
- {
- return $this->sectionRepository->findAll();
- }
-
- public function getMerchants()
- {
- return $this->merchantRepository->findAll();
- }
-
- public function getReminders($params = [])
- {
- return $this->reminderStore
- ->setMerchant($this->merchantResolver->getCurrent())
- ->setSection($this->sectionResolver->getCurrent())
- ->get($params);
- }
-
- }
|