Example #1
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 #2
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}");
     }
 }