/** * @copydoc ExtendedSaver::setData */ public function setData(Data $data) { parent::setData($data); if (!$data->getFieldByName('news_segment')->getRowData(0)) { $f = new Field('news_segment'); $translitedTitle = Translit::asURLSegment($data->getFieldByName('news_title')->getRowData(0)); $filter = array(); $pkF = $this->getData()->getFieldByName($this->getPK()); if ($pkF = $pkF->getRowData(0)) { $filter[$this->getPK()] = $pkF; } for ($i = 0; $i < 30; $i++) { $tempTitle = $translitedTitle; if ($i) { $tempTitle = $translitedTitle . '-' . $i; } $filter = array('news_segment' => $tempTitle); if (!$this->dbh->getScalar($this->getTableName(), 'news_segment', $filter)) { break; } else { $tempTitle = $translitedTitle . '-' . $i; } } $translitedTitle = $tempTitle; for ($i = 0, $l = sizeof(E()->getLanguage()->getLanguages()); $i < $l; $i++) { $f->setRowData($i, $translitedTitle); } $data->addField($f); } }
/** * @copydoc ExtendedSaver::save */ public function save() { if (($f = $this->getData()->getFieldByName('smap_segment')) && !$f->getRowData(0)) { $f->setData(Translit::asURLSegment($this->getData()->getFieldByName('smap_name')->getRowData(0)), true); } //Выставляем фильтр для родительского идентификатора $PID = $this->getData()->getFieldByName('smap_pid')->getRowData(0); if (empty($PID)) { $PID = NULL; } //$this->setFilter(array('smap_pid'=>$PID)); //Проверяем изменился ли лейаут или контент //Значит - редактирование if ($prevTemplateData = $this->dbh->select('share_sitemap', ['smap_layout', 'smap_content'], ['smap_id' => $_POST['share_sitemap']['smap_id']])) { list($prevTemplateData) = $prevTemplateData; } $result = parent::save(); $smapID = $this->getMode() == QAL::INSERT ? $result : $this->getData()->getFieldByName('smap_id')->getRowData(0); if ($this->getMode() !== QAL::INSERT) { $data = []; if (isset($_POST[$this->getTableName()]['smap_content_xml'])) { $data['smap_content_xml'] = $_POST[$this->getTableName()]['smap_content_xml']; } //Для апдейта - проверяем не изменился ли лейаут if ($prevTemplateData['smap_layout'] != $this->getData()->getFieldByName('smap_layout')->getRowData(0)) { $data['smap_layout_xml'] = ''; } //а может изменился контент if ($prevTemplateData['smap_content'] != $this->getData()->getFieldByName('smap_content')->getRowData(0)) { $data['smap_content_xml'] = ''; } if (!empty($data)) { $this->dbh->modify(QAL::UPDATE, 'share_sitemap', $data, ['smap_id' => $smapID]); } } $rights = $_POST['right_id']; //Удаляем все предыдущие записи в таблице прав $this->dbh->modify(QAL::DELETE, 'share_access_level', NULL, ['smap_id' => $smapID]); foreach ($rights as $groupID => $rightID) { if ($rightID != ACCESS_NONE) { $this->dbh->modify(QAL::INSERT, 'share_access_level', ['smap_id' => $smapID, 'right_id' => $rightID, 'group_id' => $groupID]); } } /** * @todo remove */ if (class_exists('AdsManager', false) && AdsManager::isActive() && isset($_POST[AdsManager::TABLE_NAME]) && is_array($adsData = $_POST[AdsManager::TABLE_NAME])) { $ads = new AdsManager(); $adsData['smap_id'] = $smapID; $ads->save($adsData); } return $result; }
/** * Save new template. * * @throws SystemException 'ERR_INSUFFICIENT_DATA' * @throws SystemException 'ERR_BAD_XML' */ protected function saveNewTemplate() { if (!isset($_POST['xml'])) { throw new SystemException('ERR_INSUFFICIENT_DATA'); } $xml = $_POST['xml']; if (!simplexml_load_string($xml)) { throw new SystemException('ERR_BAD_XML'); } $title = $_POST['title']; $contentFileName = ($contentName = Translit::asURLSegment($title)) . '.content.xml'; //Создаем контентный файл file_put_contents($target = 'site/modules/' . ($moduleName = E()->getSiteManager()->getCurrentSite()->folder) . '/templates/content/' . $contentFileName, $xml); $symlink = self::createSymlink($contentFileName, $moduleName); //изменяем шаблон страницы $this->dbh->modify(QAL::UPDATE, 'share_sitemap', array('smap_content_xml' => QAL::EMPTY_STRING, 'smap_content' => $symlink), array('smap_id' => $this->document->getID())); //вносим перевод, если не существует $ltagName = strtoupper('CONTENT_' . $contentName); $ltagID = $this->dbh->getScalar('share_lang_tags', array('ltag_id'), array('ltag_name' => $ltagName)); if (!$ltagID) { $ltagID = $this->dbh->modify(QAL::INSERT, 'share_lang_tags', array('ltag_name' => $ltagName)); foreach (array_keys(E()->getLanguage()->getLanguages()) as $langID) { $this->dbh->modify(QAL::INSERT, 'share_lang_tags_translation', array('lang_id' => $langID, 'ltag_value_rtf' => $title, 'ltag_id' => $ltagID)); } } //формируем ответ $b = new JSONCustomBuilder(); $b->setProperties(array('xml' => $xml, 'result' => true, 'mode' => 'none')); $this->setBuilder($b); }
/** * Save data in directory. * @throws SystemException 'ERR_NO_DATA' * @throws SystemException 'ERR_BAD_PID' */ protected function saveDir() { $transactionStarted = $this->dbh->beginTransaction(); try { if (!isset($_POST[$this->getTableName()]) || !isset($_POST[$this->getTableName()][$this->getPK()]) || !isset($_POST[$this->getTableName()]['upl_title']) || !isset($_POST[$this->getTableName()]['upl_pid'])) { throw new SystemException('ERR_NO_DATA'); } $data = $_POST[$this->getTableName()]; if (!$data['upl_pid']) { throw new SystemException('ERR_BAD_PID'); } // получаем instance IFileRepository $repository = $this->repoinfo->getRepositoryInstanceById($data['upl_pid']); $mode = empty($data[$this->getPK()]) ? QAL::INSERT : QAL::UPDATE; if ($mode == QAL::INSERT) { $parentPath = $this->dbh->getScalar($this->getTableName(), ['upl_path'], ['upl_id' => $data['upl_pid']]); if (!$parentPath) { throw new SystemException('ERR_BAD_PID'); } unset($data[$this->getPK()]); $data['upl_name'] = $data['upl_filename'] = Translit::asURLSegment($data['upl_title']); $data['upl_mime_type'] = 'unknown/mime-type'; $data['upl_internal_type'] = FileRepoInfo::META_TYPE_FOLDER; $data['upl_childs_count'] = 0; $data['upl_publication_date'] = date('Y-m-d H:i:s'); $data['upl_path'] = $parentPath . (substr($parentPath, -1) != '/' ? '/' : '') . $data['upl_filename']; $where = false; $repository->createDir($data['upl_path']); } else { $where = ['upl_id' => $data['upl_id']]; /*$currentUplPath = simplifyDBResult($this->dbh->select($this->getTableName(), array('upl_path'), array('upl_id' => $data['upl_id'])), 'upl_path', true); $data['upl_name'] = $data['upl_filename'] = Translit::asURLSegment($data['upl_title']); if($currentUplPath != $data['upl_path']){ rename($currentUplPath, $data['upl_path']); }*/ } $result = $this->dbh->modify($mode, $this->getTableName(), $data, $where); $transactionStarted = !$this->dbh->commit(); $uplID = is_int($result) ? $result : (int) $_POST[$this->getTableName()][$this->getPK()]; $args = [$uplID, date('Y-m-d H:i:s')]; $this->dbh->call('proc_update_dir_date', $args); $b = new JSONCustomBuilder(); $b->setProperties(['data' => $uplID, 'result' => true, 'mode' => is_int($result) ? 'insert' : 'update']); $this->setBuilder($b); } catch (SystemException $e) { if ($transactionStarted) { $this->dbh->rollback(); } throw $e; } }