public function store() { if (!(is_array($this->parameters) && strlen($this->blockName))) { return false; } $checkQuery = $this->domainDa->execute("SELECT id, params\n FROM innomedia_blocks\n WHERE block = " . $this->domainDa->formatText($this->blockName) . "\n AND counter = {$this->blockCounter}\n AND page " . (strlen($this->pageName) ? " = " . $this->domainDa->formatText($this->pageName) : " IS NULL") . "\n AND pageid " . ($this->pageId != 0 ? " = " . $this->pageId : " IS NULL")); $current_language = \Innomedia\Locale\LocaleWebApp::getCurrentLanguage('backend'); if ($checkQuery->getNumberRows() > 0) { $id = $checkQuery->getFields('id'); $this->id = $id; $params = \Innomedia\Locale\LocaleWebApp::getParamsDecodedByLocalesForUpdate($this->blockName, $checkQuery->getFields('params'), $this->parameters, 'backend'); return $this->domainDa->execute("UPDATE innomedia_blocks\n SET params=" . $this->domainDa->formatText(json_encode($params)) . " WHERE id={$id}"); } else { $id = $this->domainDa->getNextSequenceValue('innomedia_blocks_id_seq'); $this->id = $id; // $params = array(); // $params[$current_language] = $this->parameters; $params = \Innomedia\Locale\LocaleWebApp::getParamsDecodedByLocalesForUpdate($this->blockName, null, $this->parameters, 'backend'); return $this->domainDa->execute("INSERT INTO innomedia_blocks (id,block,counter,params" . (strlen($this->pageName) ? ",page" : "") . ($this->pageId != 0 ? ",pageid" : "") . ") VALUES ({$id}, " . $this->domainDa->formattext($this->blockName) . "," . $this->blockCounter . ',' . $this->domainDa->formatText(json_encode($params, true)) . (strlen($this->pageName) ? "," . $this->domainDa->formattext($this->pageName) : "") . ($this->pageId != 0 ? ",{$this->pageId}" : "") . ")"); } }
/** * 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}"); } }
public function savePageLevelParameters() { if ($this->id != 0) { return false; } // Check if parameters already exist in database $pagesParamsQuery = $this->domainDa->execute("SELECT params\n FROM innomedia_pages\n WHERE page=" . $this->domainDa->formatText($this->module . '/' . $this->page)); if ($pagesParamsQuery->getNumberRows() > 0) { $params = \Innomedia\Locale\LocaleWebApp::getParamsDecodedByLocalesForUpdate(null, $pagesParamsQuery->getFields('params'), $this->parameters, 'backend'); return $this->domainDa->execute("UPDATE innomedia_pages\n SET\n params =" . $this->domainDa->formatText(json_encode($params)) . "\n WHERE page=" . $this->domainDa->formatText($this->module . '/' . $this->page)); } else { $id = $this->domainDa->getNextSequenceValue('innomedia_pages_id_seq'); $current_language = \Innomedia\Locale\LocaleWebApp::getCurrentLanguage('backend'); $params = \Innomedia\Locale\LocaleWebApp::getParamsDecodedByLocalesForUpdate(null, null, $this->parameters, 'backend'); if ($this->domainDa->execute('INSERT INTO innomedia_pages (id, page, params) VALUES (' . $id . ',' . $this->domainDa->formatText($this->module . '/' . $this->page) . ',' . $this->domainDa->formatText(json_encode($params, true)) . ')')) { return true; } else { return false; } } }