Esempio n. 1
0
 public function __invoke(\Cms\Entity\Page $page, $side)
 {
     $strBlocks = null;
     if (is_object($page) && !empty($page)) {
         $serviceLocator = $this->getServiceLocator()->getServiceLocator();
         $theblock = $serviceLocator->get('BlockService');
         $settings = $serviceLocator->get('SettingsService');
         $layout = new \Cms\Model\Layout($page, $settings);
         $translator = $serviceLocator->get('translator');
         $locale = $translator->getLocale();
         $fallback = $translator->getFallbackLocale();
         $this->getNestedBlockItems($page);
         if (!empty($side)) {
             $blocks = $layout->getBlocks();
             foreach ($blocks as $block) {
                 if (!empty($block['side']) && $side == $block['side']) {
                     // check and get the locale version if it is not exists a fallback version will be print
                     $theBlock = $theblock->findByPlaceholder($block['block']['name'], $locale);
                     if (!empty($theBlock)) {
                         $strBlocks .= $theBlock->getContent();
                     } else {
                         $theBlock = $theblock->findByPlaceholder($block['block']['name'], $fallback);
                         if (!empty($theBlock)) {
                             $strBlocks .= $theBlock->getContent();
                         } else {
                             $strBlocks .= "<div class=\"alert alert-danger\">" . sprintf($translator->translate("Block %s%s%s doesn't found!"), "<strong>", $block['block']['name'], "</strong>") . "</div>";
                         }
                     }
                 }
             }
         }
     }
     return $strBlocks;
 }
Esempio n. 2
0
 /**
  * Show the page selected by its slug code 
  */
 public function pageAction()
 {
     $slug = $this->params()->fromRoute('slug');
     if (empty($slug)) {
         return $this->redirect()->toRoute('home');
     }
     // get the page by its slug code
     $page = $this->pageService->findByUri($slug, $this->translator->getLocale());
     if ($page) {
         // get the parent page
         $parent = $this->pageService->find($page->getParentId());
         // get the layout of the page
         $layout = new \Cms\Model\Layout($page, $this->cmsSettings);
         // get the template set for the page
         $template = $layout->getTemplate();
         // set the view for the page
         $viewModel = new ViewModel(array('page' => $page, 'parent' => $parent));
         $viewModel->setTemplate('cms/index/' . $template);
     } else {
         $this->flashMessenger()->setNamespace('danger')->addMessage(sprintf($this->translator->translate('The page with the slug "%s" has been not found!'), $slug));
         $viewModel = new ViewModel();
         $viewModel->setTemplate('cms/index/notfound');
     }
     return $viewModel;
 }