container = $_container; $this->entityManager = $_container->get('doctrine.orm.entity_manager'); $this->templating = $_container->get('twig'); $this->agridCacheService = $_container->get('agrid.cache_service'); //TODO a charger depuis les parameters du projet $this->langs = ['fr','en','es']; $this->resolutions = ['s','m','l','xl']; $this->repository = $this->entityManager->getRepository(AGridModule::class); } /** * @param AGridContent $content * @param AGridModuleType $moduleType * @param AGridModuleTypeContent|null $moduleTypeContent * @return AGridModule|null */ public function create(AGridContent $content, AGridModuleType $moduleType, AGridModuleTypeContent $moduleTypeContent = null){ $module = new AGridModule($content, $moduleType, $moduleTypeContent); $module->initCaches($this->langs, $this->resolutions); $module->initContents($this->langs, $this->resolutions); if(!$this->update($module)) return null; return $module; } /** * @param AGridModule $element * @return bool */ public function update(AGridModule $element): bool { $this->agridCacheService->invalidate($element->getParentContainer()); return $this->quickUpdate($element); } /** * @param AGridModule $element * @return bool */ public function quickUpdate(AGridModule $element): bool { try { if (!$this->entityManager->contains($element)) { if ($element) $this->entityManager->persist($element); else return false; } $this->entityManager->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } /** * @param int $id * @return AGridModule|null */ public function getById(int $id): ?AGridModule { return $this->repository->findOneBy(['id'=>$id]); } public function getByI(int $id): ?AGridModule { return $this->repository->findOneBy(['id'=>$id]); } /** * @param int $_module_id * @param string $_lang * @param string $_dataHTML * @return bool */ public function saveHTML(int $_module_id, string $_lang, string $_dataHTML): bool { $module = $this->getById($_module_id); if($module instanceof AGridModule){ $module->addParameter($_lang, $_dataHTML); return $this->update($module); } return false; } /********************************* - Make Parameters for Modules - ***************************************/ /* @param AGridModule $module * @param array $data * @return bool * Update Parameters of module */ public function updateParameters(AGridModule $module, array $data): bool { foreach ($data as $key => $value) $module->addParameter($key, $value); return $this->update($module); } public function rendererFront(string $twig, array $content) { return $this->templating->render($twig,['content'=>$content]); } /********************************* - Render Beck for Modules - *****************************************/ // Render back for title public function render_back_title(AGridModule $module, string $lang) { $options = $this->container->get('agrid.module_type.manager')->getTypeContent($module); return $this->templating->render('@AGrid/agrid_modules/Title/module.title.edit.html.twig', [ 'module' => $module, 'options' => $options, 'lang' => $lang ]); } // render back for photos public function render_back_photos(AGridModule $module, string $lang){ $fileItem = null; //on recupere le faileitem en parametre if($module->getParameter('image') != null) $fileItem = $this->container->get('net15.file.item.manager')->getByGUID($module->getParameter('image')); return $this->templating->render('@AGrid/agrid_modules/photos/module.photo.edit.html.twig',[ 'module' => $module, 'image'=>$fileItem, 'lang'=>$lang ]); } // Render back for slider public function render_back_slider(AGridModule $module, string $lang){ $files_item = null; if ($module->getParameter('image_slider') != null){ $files_item = $this->container->get('net15.file.item.manager')->getAllByGuid($module->getParameter('image_slider')); } return $this->templating->render('@AGrid/agrid_modules/slider/module.slider.edit.html.twig', [ 'module' => $module, 'images' => $files_item, 'lang'=>$lang ]); } // Render back for basic video public function render_back_basic_video(AGridModule $module, string $lang) { return $this->templating->render('@AGrid/agrid_modules/media/video/module.basic.video.edit.html.twig', [ 'module' => $module, 'lang'=>$lang ]); } // Render back for youtube video public function render_back_youtube_video(AGridModule $module, string $lang) { return $this->templating->render('@AGrid/agrid_modules/media/video_youtube/module.youtube.video.edit.html.twig', [ 'module' => $module, 'lang'=>$lang ]); } // Render back for youtube video public function render_back_news(AGridModule $module, string $lang) { $newsFeeds= $this->container->get('agrid.news_feed.manager')->getAll(); return $this->templating->render('@AGrid/agrid_modules/news/news.edit.navbar.html.twig', [ 'module' => $module, 'lang' => $lang, 'newsFeeds' => $newsFeeds ]); } }