src/Kiwi/PageBundle/Service/PageFrontendHandle.php line 171

Open in your IDE?
  1. <?php
  2. namespace Kiwi\PageBundle\Service;
  3. use Symfony\Component\HttpFoundation\Session\Session;
  4. use Twig_Environment;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class PageFrontendHandle {
  7.     protected $page_handle;
  8.     protected $placeholders_handle;
  9.     protected $page_modules_handle;
  10.     protected $languages;
  11.     protected $kiweePageFrontendHandle;
  12.     var $controller false;
  13.     var $request false;
  14.     var $response false;
  15.     var $page false;
  16.     var $lang false;
  17.     var $config = array();
  18.     public function __construct(\Kiwi\PageBundle\Service\PageHandle $page_handle,
  19.                                 \Kiwi\LayoutTemplatesBundle\Service\LayoutTemplatesGroupsTemplatesPlaceholdersHandle $placeholders_handle,
  20.                                 \Kiwi\PageBundle\Service\PageModulesFactory $page_modules_handle,
  21.                                 \Kiwi\LanguagesBundle\Service\LanguagesHandle $languages,
  22.                                 \Kiwee\PageBundle\Service\PageFrontendHandle $kiweePageFrontendHandle) {
  23.         $this->page_handle $page_handle;
  24.         $this->placeholders_handle $placeholders_handle;
  25.         $this->page_modules_handle $page_modules_handle;
  26.         $this->languages $languages;
  27.         $this->kiweePageFrontendHandle $kiweePageFrontendHandle;
  28.     }
  29.     public function setController($controller) {
  30.         $this->controller $controller;
  31.     }
  32.     public function setPage($lang$page_uid) {
  33.         $this->page $this->page_handle->getPageBySeoName($page_uid);
  34.         $this->lang $lang;
  35.     }
  36.     public function setPageByReference($lang, \Kiwi\PageBundle\Entity\PageTree $page) {
  37.         $this->page $page;
  38.         $this->lang $lang;
  39.     }
  40.     private function setDefaultPage() {
  41.     }
  42.     public function setRequest(\Symfony\Component\HttpFoundation\Request $request) {
  43.         $this->request $request;
  44.     }
  45.     public function setResponse(\Symfony\Component\HttpFoundation\Response $response) {
  46.         $this->response $response;
  47.     }
  48.     public function setConfig(Array $config) {
  49.         $this->config $config;
  50.     }
  51.     public function getPageRedirectUrl() {
  52.         $ret false;
  53.         if($this->page->getRedirect()) {
  54.             $page_seo_name $this->languages->getLangEntry($this->page->getRedirect()->getPageName(),$this->lang);
  55.             $ret $this->getDevPrefix().'/'.$this->lang.'/'.$page_seo_name;
  56.         }
  57.         return $ret;
  58.     }
  59.     public function getRedirectSuffix() {
  60.         $ret null;
  61.         if($this->page->getRedirect()) {
  62.             $ret $this->page->getRedirectSuffix();
  63.         }
  64.         return $ret;
  65.     }
  66.     private function getDevPrefix() {
  67.         $dev_prefix '';
  68.         if($this->controller->get'kernel' )->getEnvironment() == 'dev')
  69.             $dev_prefix '/app_dev.php';
  70.         return $dev_prefix;
  71.     }
  72.     private function getPageData() {
  73.         $ret = array();
  74.         $this->config['response'] = $this->response;
  75.         $this->config['lang'] = $this->lang;
  76.         $this->config['page_id'] = $this->page->getId();
  77.         $this->config['cookie_agree'] = $this->controller->get('cookie_agree_handle')->getHandle($this->lang);
  78.         //append info of eshop loged user
  79.         $this->config['eshop_user'] = $this->controller->get('eshop_users_handle')->getCurrentUser();
  80.         $this->config['eshop_basket'] = $this->controller->get('eshop_basket_handle')->getBasketItems(0,$this->lang);
  81.         $this->config['last_products'] = $this->controller->get('eshop_products_handle')->getCookieProduct($this->request$this->lang);
  82.         $ret array_merge($ret,$this->config);
  83.         $page_placeholders $this->placeholders_handle->getPlaceholders($this->page->getLayout()->getId());
  84.         if($page_placeholders) {
  85.             foreach($page_placeholders as $placeholder) {
  86.                 $modules $this->page_modules_handle->getPlaceholderModules($placeholder,true);
  87.                 $placeholder_html '';
  88.                 if($modules) {
  89.                     foreach($modules as $module) {
  90.                         $append_module true;
  91.                         if($module->getLanguage()) {
  92.                             $append_module false;
  93.                             if($this->config['lang'] == $module->getLanguage()->GetCode())
  94.                                 $append_module true;
  95.                         }
  96.                         if($append_module) {
  97.                             $module_html $this->page_modules_handle->getKiwiModule(md5($module->getNamespace()))->getKiwiFrontendModuleBox($module,$this->config);
  98.                             if($this->getIsKewee()) {
  99.                                 $placeholder_html .= $this->kiweePageFrontendHandle->getModuleHtml(
  100.                                     $module->getNamespace(),
  101.                                     $module,
  102.                                     $this->config,
  103.                                     $module_html
  104.                                 );
  105.                             } else {
  106.                                 $placeholder_html .= $module_html;
  107.                             }
  108.                         }
  109.                     }
  110.                 }
  111.                 if($this->getIsKewee()) {
  112.                     $ret['d'][$placeholder->getId()] = $this->kiweePageFrontendHandle->getPlaceholderHtml($placeholder_html);
  113.                 } else {
  114.                     $ret['d'][$placeholder->getId()] = $placeholder_html;
  115.                 }
  116.             }
  117.         }
  118.         return $ret;
  119.     }
  120.     public function getPageHtml() {
  121.         if($this->page) {
  122.             $response = new Response();
  123.             $this->setResponse($response);
  124.             $this->page_modules_handle->setPage($this->page);
  125.             $this->page_modules_handle->setRequest($this->request);
  126.             $this->page_modules_handle->setResponse($response);
  127.             $twig = clone $this->controller->get('twig');
  128.             $page_html $twig->render($this->controller->get('BL')->cacheStringTemplate(
  129.                 '{% autoescape false %}'.$this->page->getLayout()->getTpl().'{% endautoescape %}'),
  130.                 $this->getPageData()
  131.             );
  132.             $response->setContent($page_html);
  133.             $response->setStatusCode(Response::HTTP_OK);
  134.             $response->headers->set('Content-Type''text/html');
  135.             $this->setPageMeta();
  136.             return $response;
  137.         } else {
  138.             $this->setPageMeta();
  139.             $this->setDefaultPage();
  140.             if($this->page) {
  141.             } else {
  142.                 trigger_error('Požadovaná stránka nebyla nalezena'E_USER_ERROR);
  143.             }
  144.         }
  145.     }
  146.     public function getIsKewee() {
  147.         return false;
  148.     }
  149.     public function setPageMeta($title null$image null$description null) {
  150.         $session = new Session();
  151.         $session->set('page_meta_title',$title);
  152.         $session->set('page_meta_image',$image);
  153.         $session->set('page_meta_description',$description);
  154.     }