src/Kiwi/PageBundle/Service/PageModuleTemplate.php line 90

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Matěj Böswart
  5.  * Date: 5.12.14
  6.  * Time: 19:26
  7.  */
  8. namespace Kiwi\PageBundle\Service;
  9. use Symfony\Component\Form\Extension\Core\Type\FormType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. class PageModuleTemplate extends PageModulesGlobal {
  13.     public function getKiwiModuleBox() {
  14.         return '<div id="module_'.md5(get_class()).'" class="module"><span class="glyphicon glyphicon-indent-right"></span>Šablona</div>';
  15.     }
  16.     
  17.     public function getKiwiPlacedModuleBox(\Kiwi\PageBundle\Entity\PageTreeModules $module) {
  18.         $twig = clone $this->controller->get('twig');
  19.         $disabled_css_selector = ($module->getIsActive()) ? '' ' placeholder_module_disabled';
  20.         return $twig->render($this->controller->get('BL')->cacheStringTemplate(
  21.             '<div class="placeholder_module placeholder_module_html'.$disabled_css_selector.'" dbID="'.$module->getId().'">'.
  22.             '<div class="name"><span class="glyphicon glyphicon-indent-right"></span>Šablona</div>'.
  23.             '<div class="vertical-form">{{ form(form) }}</div>'.
  24.             '<div class="vertical-form">{{ form(formDSO) }}</div>'.
  25.             '<div class="controls">'.
  26.             '<a href="#" class="pop_editor" popComponent="template" formLink="'.$this->controller->get('router')->generate('kiwi_module_popup_templates_variables',array('module_id' => $module->getId())).'"><span class="glyphicon glyphicon-log-in"></span></a>'.
  27.             '<a href="'.$this->controller->get('router')->generate('kiwi_module_page_navigator_module_switch_state', array('level' => $this->page->getId(), 'module_id' => $module->getId())).'" class="trash" confirm="Změnit aktivitu komponenty ?"><span class="glyphicon glyphicon-refresh"></span></a>'.
  28.             '<a href="'.$this->controller->get('router')->generate($this->url_navigator_module_remove, array('level' => $this->page->getId(), 'module_id' => $module->getId())).'" class="trash" confirm="Nenávratně smazat tuto komponentu ?"><span class="glyphicon glyphicon-trash"></span></a>'.
  29.             '</div>'.
  30.             '</div>'),
  31.             array(
  32.                 'form' => $this->updateModuleTemplate($module),
  33.                 'formDSO' => $this->updateModuleDSO($module)
  34.             )
  35.         );
  36.     }
  37.     private function updateModuleDSO(\Kiwi\PageBundle\Entity\PageTreeModules $module) {
  38.         $form $this->controller->get('form.factory')->createNamedBuilder('formupdatemoduledso'.$module->getId(), FormType::class, $module)
  39.             ->add('template_dso_service'TextType::class, array('label' => 'Služba''required' => false))
  40.             ->add('template_dso_method'TextType::class, array('label' => 'Metoda''required' => false))
  41.             ->add('save'SubmitType::class, array('label' => 'nastavit DSO'))
  42.             ->getForm();
  43.         $form->handleRequest($this->request);
  44.         if($form->isValid()) {
  45.             $formdata $form->getData();
  46.             $this->em->getRepository('\Kiwi\PageBundle\Entity\PageTreeModules');
  47.             $this->em->persist($formdata);
  48.             $this->em->flush();
  49.             Header("Location: ".$this->controller->get('router')->generate('kiwi_module_page_navigator_level',array('level' => $module->getPageId())));
  50.             exit();
  51.         }
  52.         return $form->createView();
  53.     }
  54.     public function getKiwiFrontendModuleBox(\Kiwi\PageBundle\Entity\PageTreeModules $module, Array $config) {
  55.         if($module->getTemplate()) {
  56.             $twig = clone $this->controller->get('twig');
  57.             $data false;
  58.             if($module->getTemplateDsoService() != '' && $module->getTemplateDsoMethod() != '') {
  59.                 $service $module->getTemplateDsoService();
  60.                 $method_config explode(',',$module->getTemplateDsoMethod());
  61.                 $method $method_config[0];
  62.                 array_shift($method_config);
  63.                 $method_params $method_config;
  64.                 $serviceObj $this->controller->get($service);
  65.                 if(method_exists($serviceObj,'setController'))
  66.                     $serviceObj->setController($this->controller);
  67.                 if($method_params)
  68.                     $config['method_params'] = $method_params;
  69.                 $data $serviceObj->$method($config$this->request);
  70.             }
  71.             //variables dynamic content
  72.             $v_to_replace = array();
  73.             $v_with_replace = array();
  74.             if(isset($_GET)) {
  75.                 foreach($_GET as $get_key => $get_val) {
  76.                     $v_to_replace[] = '%get.'.$get_key.'%';
  77.                     $v_with_replace[] = $get_val;
  78.                 }
  79.             }
  80.             $v = array();
  81.             $variables $this->controller->get('templates_modules_groups_templates_variables_handle')->getModuleVariables($module->getId());
  82.             if($variables) {
  83.                 foreach($variables as $variable) {
  84.                     if($variable->data) {
  85.                         $v[$variable->variable->getVarName()] = str_replace($v_to_replace,$v_with_replace,$variable->data->getContentPlain());
  86.                     } else {
  87.                         $v[$variable->variable->getVarName()] = null;
  88.                     }
  89.                 }
  90.             }
  91.             $v['_root_config'] = $config;
  92.             return $twig->render($this->controller->get('BL')->cacheStringTemplate(
  93.                 '{% autoescape false %}'.$module->getTemplate()->getTpl().'{% endautoescape %}'),
  94.                 array(
  95.                     'config' => $config,
  96.                     'data' => $data,
  97.                     'v' => $v
  98.                 )
  99.             );
  100.         } else {
  101.             return false;
  102.         }
  103.     }