Exemple #1
0
 public function build()
 {
     $this->loadBlocks();
     if (is_object($this->grid)) {
         echo $this->grid->parse();
     } else {
         $this->context->getResponse()->sendError(\Innomatic\Webapp\WebAppResponse::SC_NOT_FOUND, $this->context->getRequest()->getRequestURI());
     }
 }
Exemple #2
0
 /**
  * Adds a Block to the grid at the given position.
  *
  * @param Block $block    Block object to be added at the grid
  * @param int   $row      Block row in the grid
  * @param int   $column   Block column in the grid
  * @param int   $position Block position in the cell
  *
  * @return Grid grid object
  */
 public function addBlock(Block $block, $row, $column, $position)
 {
     // Process the block and build the block HTML.
     $block->run($this->context->getRequest(), $this->context->getResponse());
     // Set default row if not given.
     if (!$row) {
         $row = 1;
     }
     // Set default column it not given.
     if (!$column) {
         $column = 1;
     }
     // Set default position inside the cell if not given.
     if (!$position) {
         $position = 1;
     }
     // Set block name.
     $block_name = 'block_' . $row . '_' . $column . '_' . $position;
     $this->set($block_name, $block);
     $this->blocks[$row][$column][$position] = $block_name;
     return $this;
 }
Exemple #3
0
 public static function load(Context $context, Page $page, Grid $grid, $module, $name, $counter, $row, $column, $position, $params = array())
 {
     if (!strlen($module)) {
         return;
     }
     $block_yml_file = $context->getBlocksHome($module) . $name . '.local.yml';
     if (!file_exists($block_yml_file)) {
         $block_yml_file = $context->getBlocksHome($module) . $name . '.yml';
     }
     if (!file_exists($block_yml_file)) {
         $context->getResponse()->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'Missing block definition file ' . $name . '.yml');
         return;
     }
     // Imports block class and return an instance
     $def = yaml_parse_file($block_yml_file);
     $fqcn = $def['class'];
     if (!strlen($fqcn)) {
         // @todo convert to new class loader
         $fqcn = '\\Innomedia\\EmptyBlock';
     }
     // @todo convert to new namespace convention
     if (!class_exists($fqcn)) {
         $context->getResponse()->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'Missing class ' . $fqcn);
         return;
     }
     $tpl_root = $context->getBlocksHome($module);
     $tpl_file = '';
     $locales = $context->getLocales();
     foreach ($locales as $locale) {
         if (file_exists($tpl_root . $name . '_' . $locale . '.local.tpl.php')) {
             // Local template for given language exists
             $tpl_file = $tpl_root . $name . '_' . $locale . '.local.tpl.php';
             break;
         }
         if (file_exists($tpl_root . $name . '_' . $locale . '.tpl.php')) {
             // Template for given language exists
             $tpl_file = $tpl_root . $name . '_' . $locale . '.tpl.php';
             break;
         }
     }
     if (!strlen($tpl_file)) {
         $webapp = WebAppContainer::instance('\\Innomatic\\Webapp\\WebAppContainer')->getCurrentWebApp();
         if (file_exists($tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.local.tpl.php')) {
             // Local template for default language exists
             $tpl_file = $tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.local.tpl.php';
         } elseif (file_exists($tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.tpl.php')) {
             // Template for default language exists
             $tpl_file = $tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.tpl.php';
         } elseif (file_exists($tpl_root . $name . '.local.tpl.php')) {
             // Local template for no specific language exists
             $tpl_file = $tpl_root . $name . '.local.tpl.php';
         } else {
             // Template for no specific language exists
             $tpl_file = $tpl_root . $name . '.tpl.php';
         }
     }
     // Build block
     $obj = new $fqcn($tpl_file);
     $obj->setPage($page)->setGrid($grid);
     // Set block counter
     $obj->setCounter($counter)->setRow($row)->setColumn($column)->setPosition($position);
     // Set block parameters
     $obj->setParameters($params);
     // Set block types
     $obj->setTypes(isset($def['types']) && is_array($def['types']) ? $def['types'] : array());
     return $obj;
 }