em = $em ; $this->security = $security ; $this->globalParam = $globalParam ; $this->formFactory = $formFactory ; $this->requestStack = $requestStack ; $this->productCategoryRepository = $this->em->getRepository($this->em->getClassMetadata(ProductCategoryInterface::class)->getName()) ; $this->merchantRepository = $this->em->getRepository($this->em->getClassMetadata(MerchantInterface::class)->getName()) ; $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetadata(ProductFamilyInterface::class)->getName()) ; $this->liipCacheHelper = $liipCacheHelper; $this->parameterBag = $parameterBag; } public function getFunctions() { return array( new TwigFunction('get_product_categories', [$this, 'getProductCategories']), new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']), new TwigFunction('get_merchants', [$this, 'getMerchants']), new TwigFunction('lc_liip', [$this, 'lcLiip']), new TwigFunction('get_file_manager_folder', [$this, 'getFileManagerFolder']), ); } public function getFilters() { return [ new TwigFilter('format_price', [$this, 'formatPrice']), new TwigFilter('lc_liip', [$this, 'lcLiip']), ]; } public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') { if(strpos($path, $this->getFileManagerFolder())===false){ $path = $this->getFileManagerFolder() .'/'. $path; } if ($path) { return $this->liipCacheHelper->getBrowserPath($path, $thumb); } else { return $this->liipCacheHelper->getBrowserPath('assets/img/frontend/'.$default, $thumb); } } /** * Retourne le chemin vers le dossier d'uploads de responsiveFilemanager * * @return string */ public function getFileManagerFolder(){ return $this->parameterBag->get('app.path.images'); } public function getProductCategories() { $categories = $this->productCategoryRepository->findAllParents($this->globalParam->getCurrentMerchant()) ; return $categories ; } public function getFormNewsletter() { $form = $this->formFactory->create(NewsletterType::class); return $form->createView() ; } public function formatPrice($price) { $price = number_format($price, 2, ',', ' ') ; $price = $price .' €' ; return $price ; } public function getMerchants() { return $this->merchantRepository->findAll() ; } }