Example #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());
     }
 }
Example #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;
 }
Example #3
0
 /**
  * Get parameters to json decoding them according to the language 
  * for update database
  * @param  array  $blockName  block name
  * @param  array  $params_db  field params
  * @param  array  $params_new field params
  * @param  string $scope      scope language
  * @return array param decoding by language
  */
 public static function getParamsDecodedByLocalesForUpdate($blockName, $params_db, $params_new, $scope = "backend")
 {
     $context = \Innomedia\Context::instance('\\Innomedia\\Context');
     list($module, $block) = explode('/', $blockName);
     if (\Innomedia\Block::isNoLocale($context, $module, $block)) {
         $params = array();
         $current_language = 'nolocale';
     } else {
         $default_languate = self::getDefaultLanguage();
         $current_language = self::getCurrentLanguage($scope);
         $json_params = json_decode($params_db, true);
         if (!self::isTranslatedParams($json_params)) {
             if ($current_language == $default_languate) {
                 $params = array();
             } else {
                 $params[$default_languate] = $json_params;
             }
         } else {
             $params = $json_params;
         }
     }
     $params[$current_language] = $params_new;
     return $params;
 }
Example #4
0
 protected function setUp()
 {
     $this->context = \Innomedia\Context::instance('\\Innomedia\\Context', 'innomatic');
 }
Example #5
0
 /**
  * Gets a list of all the blocks supporting at least one of the given types.
  *
  * @param array $searchTypes an array of types to check
  * @static
  * @access public
  * @return array
  */
 public static function getBlocksByTypes($searchTypes)
 {
     $blocks = array();
     $modulesList = Context::instance('\\Innomedia\\Context')->getModulesList();
     foreach ($modulesList as $module) {
         $moduleObj = new Module($module);
         $blocksList = $moduleObj->getBlocksList();
         foreach ($blocksList as $block) {
             $blockDefFileBase = Context::instance('\\Innomedia\\Context')->getModulesHome() . $module . '/blocks/' . $block;
             if (file_exists($blockDefFileBase . '.local.yml')) {
                 // Local block definition file
                 $blockDefFile = $blockDefFileBase . '.local.yml';
             } elseif (file_exists($blockDefFileBase . '.yml')) {
                 // Standard block definition file
                 $blockDefFile = $blockDefFileBase . '.yml';
             } else {
                 // Block definition file doesn't exist
                 continue;
             }
             // Get block definition
             $blockDef = yaml_parse_file($blockDefFile);
             if (!(isset($blockDef['types']) && is_array($blockDef['types']))) {
                 // The block has no types
                 continue;
             }
             // Check if at least one of the given types is support by the
             // current block
             foreach ($searchTypes as $searchType) {
                 if (in_array($searchType, $blockDef['types'])) {
                     // Type found
                     $blocks[] = $module . '/' . $block;
                     continue;
                 }
             }
         }
     }
     return $blocks;
 }
Example #6
0
 /**
  * Delete a object media from innomedia_blocks
  * @param string $fieldName name of field image in innomedia_blocks
  * @return boolean return if the action is successful or not
  */
 public function deleteFromBlock($fieldName)
 {
     // Delete ref image from innomedia_blocks
     $domainDa = InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getCurrentDomain()->getDataAccess();
     $checkQuery = $domainDa->execute("SELECT     id, params\n                FROM    innomedia_blocks\n                WHERE   block = '{$this->blockName}'\n                    AND counter = {$this->blockCounter}\n                    AND page " . (!empty($this->pageName) ? "= '{$this->pageName}'" : "is NULL") . "\n                    AND pageid " . ($this->pageId != 0 ? "= {$this->pageId}" : "is NULL"));
     if ($checkQuery->getNumberRows() > 0) {
         $row_id = $checkQuery->getFields('id');
         $json_params = json_decode($checkQuery->getFields('params'), true);
         // $ris = \Innomedia\Locale\LocaleWebApp::isTranslatedParams($json_params);
         list($blockModule, $blockName) = explode("/", $this->blockName);
         $context = \Innomedia\Context::instance('\\Innomedia\\Context');
         $is_nolocale = \Innomedia\Block::isNoLocale($context, $blockModule, $blockName);
         if ($is_nolocale) {
             $current_language = 'nolocale';
         } else {
             $current_language = \Innomedia\Locale\LocaleWebApp::getCurrentLanguage('backend');
         }
         $params = \Innomedia\Locale\LocaleWebApp::getParamsDecodedByLocales($this->blockName, $json_params, 'backend');
         $key = @array_search($this->id, $params[$fieldName]);
         // remove id image selected
         unset($params[$fieldName][$key]);
         // convet array in a not-associative array
         $params[$fieldName] = @array_values($params[$fieldName]);
         $json_params[$current_language] = $params;
         $domainDa->execute("UPDATE innomedia_blocks\n                SET params=" . $domainDa->formatText(json_encode($json_params)) . " WHERE id={$row_id}");
     }
 }