예제 #1
0
 /**
  * @copydoc DataSet::__construct
  */
 public function __construct($name, array $params = null)
 {
     parent::__construct($name, $params);
     if (!AdsManager::isActive()) {
         $this->disable();
     }
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * @copydoc Grid::edit
  */
 protected function edit()
 {
     parent::edit();
     $this->buildRightsTab($smapID = $this->getData()->getFieldByName('smap_id')->getRowData(0));
     //Выводим УРЛ в поле сегмента
     $field = $this->getData()->getFieldByName('smap_pid');
     $site = E()->getSiteManager()->getSiteByID($this->getData()->getFieldByName('site_id')->getRowData(0));
     foreach ([Document::TMPL_CONTENT, Document::TMPL_LAYOUT] as $type) {
         if ($f = $this->getDataDescription()->getFieldDescriptionByName('smap_' . $type)) {
             $f->setType(FieldDescription::FIELD_TYPE_SELECT);
             $old_value = $this->getData()->getFieldByName('smap_' . $type)->getRowData(0);
             $template_data = $this->loadTemplateData($type, $site->folder, $old_value);
             $f->loadAvailableValues($template_data, 'key', 'value');
         }
     }
     //Если изменен  - вносим исправления в список возможных значений
     if ($contentXMLFieldData = $this->dbh->getScalar($this->getTableName(), 'smap_content_xml', ['smap_id' => $this->getData()->getFieldByName('smap_id')->getRowData(0)])) {
         $contentFilename = $this->getData()->getFieldByName('smap_content')->getRowData(0);
         $contentFD = $this->getDataDescription()->getFieldDescriptionByName('smap_content');
         $contentFD->setProperty('reset', $this->translate('TXT_RESET_CONTENT'));
         $av =& $contentFD->getAvailableValues();
         if (isset($av[$contentFilename])) {
             $av[$contentFilename]['value'] .= ' - ' . $this->translate('TXT_CHANGED');
         }
         $newField = new FieldDescription('smap_content_xml');
         $newField->setProperty('nullable', true);
         $newField->setType(FieldDescription::FIELD_TYPE_CODE);
         $newField->setProperty('tableName', $this->getTableName());
         $newField->setProperty('tabName', $contentFD->getPropertyValue('tabName'));
         $this->getDataDescription()->addFieldDescription($newField, DataDescription::FIELD_POSITION_AFTER, 'smap_content');
         $newField = new Field('smap_content_xml');
         $doc = new \DOMDocument();
         $doc->loadXML($contentXMLFieldData);
         $doc->formatOutput = true;
         $doc->preserveWhiteSpace = true;
         $newField->setData($doc->saveXML(null, LIBXML_NOEMPTYTAG), true);
         $this->getData()->addField($newField);
         unset($contentFilename, $contentFD, $av, $doc, $newField);
     }
     $smapSegment = '';
     if ($field->getRowData(0) !== null) {
         $smapSegment = E()->getMap($site->id)->getURLByID($field->getRowData(0));
         $this->getDataDescription()->getFieldDescriptionByName('smap_segment')->removeProperty('nullable');
     } else {
         $this->getDataDescription()->getFieldDescriptionByName('smap_pid')->setMode(FieldDescription::FIELD_MODE_READ)->setType(FieldDescription::FIELD_TYPE_HIDDEN);
         foreach (['smap_is_disabled', 'smap_segment', 'smap_redirect_url', 'smap_meta_robots', 'smap_meta_keywords', 'smap_meta_description'] as $fieldName) {
             if ($f = $this->getDataDescription()->getFieldDescriptionByName($fieldName)) {
                 $this->getDataDescription()->removeFieldDescription($f);
             }
         }
     }
     $smapName = $this->dbh->getScalar($this->getTranslationTableName(), 'smap_name', ['smap_id' => $field->getRowData(0), 'lang_id' => $this->document->getLang()]);
     for ($i = 0; $i < ($langs = count(E()->getLanguage()->getLanguages())); $i++) {
         $field->setRowProperty($i, 'data_name', $smapName);
         $field->setRowProperty($i, 'segment', $smapSegment);
     }
     $tm = new TagManager($this->getDataDescription(), $this->getData(), $this->getTableName());
     $tm->createFieldDescription();
     $tm->createField();
     $this->getDataDescription()->getFieldDescriptionByName('smap_id')->setType(FieldDescription::FIELD_TYPE_INT)->setMode(FieldDescription::FIELD_MODE_READ);
     if (class_exists('AdsManager', false) && AdsManager::isActive()) {
         $ads = new AdsManager();
         $ads->edit($this->getData(), $this->getDataDescription());
     }
 }