/** * Выводит список топиков * */ protected function EventShowTopics() { /** * Меню */ $this->sMenuSubItemSelect = $this->sCurrentEvent; /* * Получаем тип контента */ if (!($this->oType = E::ModuleTopic()->GetContentType($this->sCurrentEvent))) { return parent::EventNotFound(); } /** * Устанавливаем title страницы */ E::ModuleViewer()->AddHtmlTitle($this->oType->getContentTitleDecl()); /** * Передан ли номер страницы */ $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1; /** * Получаем список топиков */ $aResult = E::ModuleTopic()->GetTopicsByType($iPage, Config::Get('module.topic.per_page'), $this->oType->getContentUrl()); $aTopics = $aResult['collection']; /** * Формируем постраничность */ $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), R::GetPath('filter') . $this->sCurrentEvent); /** * Загружаем переменные в шаблон */ E::ModuleViewer()->Assign('aPaging', $aPaging); E::ModuleViewer()->Assign('aTopics', $aTopics); $this->SetTemplateAction('index'); }
/** * Обновляет топик * * @param ModuleTopic_EntityContentType $oContentType Объект типа контента * * @return bool */ public function DeleteContentType($oContentType) { $aFilter = array('topic_type' => $oContentType->getContentUrl()); $iCount = $this->GetCountTopicsByFilter($aFilter); if (!$iCount && $this->oMapper->DeleteContentType($oContentType->getId())) { //чистим зависимые кеши E::ModuleCache()->CleanByTags(array('content_new', 'content_update', 'topic_update')); E::ModuleCache()->Delete("content_type_{$oContentType->getId()}"); return true; } return false; }
/** * Обновляет тип контента * * @param ModuleTopic_EntityContentType $oContentType Объект типа контента * * @return bool */ public function UpdateContentType($oContentType) { $sql = "UPDATE ?_content\n\t\t\tSET\n\t\t\t\tcontent_title=?,\n\t\t\t\tcontent_title_decl=?,\n\t\t\t\tcontent_url=?,\n\t\t\t\tcontent_sort=?d,\n\t\t\t\tcontent_candelete=?d,\n\t\t\t\tcontent_active=?d,\n\t\t\t\tcontent_access=?d,\n\t\t\t\tcontent_config=?\n\t\t\tWHERE\n\t\t\t\tcontent_id = ?d\n\t\t"; $bResult = $this->oDb->query($sql, $oContentType->getContentTitle(), $oContentType->getContentTitleDecl(), $oContentType->getContentUrl(), $oContentType->getContentSort(), $oContentType->getContentCandelete(), $oContentType->getContentActive(), $oContentType->getContentAccess(), $oContentType->getExtra(), $oContentType->getContentId()); return $bResult !== false; }
/** * Редактирование топика * */ protected function EventEdit() { // * Получаем номер топика из URL и проверяем существует ли он $iTopicId = intval($this->GetParam(0)); if (!$iTopicId || !($oTopic = E::ModuleTopic()->GetTopicById($iTopicId))) { return parent::EventNotFound(); } // * Получаем тип контента if (!($this->oContentType = E::ModuleTopic()->GetContentTypeByUrl($oTopic->getType()))) { return parent::EventNotFound(); } E::ModuleViewer()->Assign('oContentType', $this->oContentType); $this->sMenuSubItemSelect = $this->oContentType->getContentUrl(); // * Есть права на редактирование if (!E::ModuleACL()->IsAllowEditTopic($oTopic, $this->oUserCurrent)) { return parent::EventNotFound(); } $aBlogFilter = array('user' => $this->oUserCurrent, 'content_type' => $this->oContentType); $aBlogsAllow = $this->_getAllowBlogs($aBlogFilter); // Такой тип контента не разрешен для пользователя ни в одном из типов блогов if (!$aBlogsAllow) { return parent::EventNotFound(); } // * Вызов хука E::ModuleHook()->Run('topic_edit_show', array('oTopic' => $oTopic)); // * Загружаем переменные в шаблон E::ModuleViewer()->Assign('bPersonalBlog', $this->bPersonalBlogEnabled); E::ModuleViewer()->Assign('aBlogsAllow', $aBlogsAllow); E::ModuleViewer()->Assign('bEditDisabled', $oTopic->getQuestionCountVote() == 0 ? false : true); E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('topic_topic_edit')); // * Устанавливаем шаблон вывода $this->SetTemplateAction('add'); E::ModuleViewer()->Assign('sMode', 'edit'); // * Проверяем, отправлена ли форма с данными if ($this->IsPost()) { // * Обрабатываем отправку формы $xResult = $this->SubmitEdit($oTopic); if ($xResult !== false) { return $xResult; } } else { /** * Заполняем поля формы для редактирования * Только перед отправкой формы! */ $_REQUEST['topic_title'] = $oTopic->getTitle(); $_REQUEST['topic_text'] = $oTopic->getTextSource(); $_REQUEST['blog_id'] = $oTopic->getBlogId(); $_REQUEST['topic_id'] = $oTopic->getId(); $_REQUEST['topic_publish_index'] = $oTopic->getPublishIndex(); $_REQUEST['topic_forbid_comment'] = $oTopic->getForbidComment(); $_REQUEST['topic_main_photo'] = $oTopic->getPhotosetMainPhotoId(); $_REQUEST['topic_field_link'] = $oTopic->getSourceLink(); $_REQUEST['topic_field_tags'] = $oTopic->getTags(); $_REQUEST['topic_field_question'] = $oTopic->getQuestionTitle(); $_REQUEST['topic_field_answers'] = array(); $_REQUEST['topic_show_photoset'] = $oTopic->getShowPhotoset(); $aAnswers = $oTopic->getQuestionAnswers(); foreach ($aAnswers as $aAnswer) { $_REQUEST['topic_field_answers'][] = $aAnswer['text']; } foreach ($this->oContentType->getFields() as $oField) { if ($oTopic->getField($oField->getFieldId())) { $sValue = $oTopic->getField($oField->getFieldId())->getValueSource(); if ($oField->getFieldType() == 'file') { $sValue = unserialize($sValue); } $_REQUEST['fields'][$oField->getFieldId()] = $sValue; } } } $sUrlMask = R::GetTopicUrlMask(); if (strpos($sUrlMask, '%topic_url%') === false) { // Нет в маске URL $aEditTopicUrl = array('before' => $oTopic->getLink($sUrlMask), 'input' => '', 'after' => ''); } else { // В маске есть URL, вместо него нужно вставить <input> $aUrlMaskParts = explode('%topic_url%', $sUrlMask); $aEditTopicUrl = array('before' => $aUrlMaskParts[0] ? $oTopic->getLink($aUrlMaskParts[0]) : F::File_RootUrl(), 'input' => $oTopic->getTopicUrl() ? $oTopic->getTopicUrl() : $oTopic->MakeTopicUrl(), 'after' => isset($aUrlMaskParts[1]) && $aUrlMaskParts[1] ? $oTopic->getLink($aUrlMaskParts[1], false) : ''); } if (!isset($_REQUEST['topic_url_input'])) { $_REQUEST['topic_url_input'] = $aEditTopicUrl['input']; } else { $aEditTopicUrl['input'] = $_REQUEST['topic_url_input']; } if (!isset($_REQUEST['topic_url_short'])) { $_REQUEST['topic_url_short'] = $oTopic->getUrlShort(); } E::ModuleViewer()->Assign('aEditTopicUrl', $aEditTopicUrl); // Old style templates compatibility $_REQUEST['topic_url_before'] = $aEditTopicUrl['before']; $_REQUEST['topic_url'] = $aEditTopicUrl['input']; $_REQUEST['topic_url_after'] = $aEditTopicUrl['after']; E::ModuleViewer()->Assign('oTopic', $oTopic); // Добавим картинки фотосета для вывода E::ModuleViewer()->Assign('aPhotos', E::ModuleMresource()->GetMresourcesRelByTarget('photoset', $oTopic->getId())); }
/** * @param ModuleTopic_EntityContentType $oContentType * * @return bool */ protected function _eventContentTypesEditSubmit($oContentType) { // * Проверяем отправлена ли форма с данными if (!F::isPost('submit_type_add')) { return false; } // * Проверка корректности полей формы if (!$this->CheckContentFields()) { return false; } $sTypeOld = $oContentType->getContentUrl(); $oContentType->setContentTitle(F::GetRequest('content_title')); $oContentType->setContentTitleDecl(F::GetRequest('content_title_decl')); $oContentType->setContentUrl(F::GetRequest('content_url')); $oContentType->setContentAccess(F::GetRequest('content_access')); $aConfig = F::GetRequest('config'); if (is_array($aConfig)) { $oContentType->setExtraValue('photoset', isset($aConfig['photoset']) ? 1 : 0); $oContentType->setExtraValue('link', isset($aConfig['link']) ? 1 : 0); $oContentType->setExtraValue('question', isset($aConfig['question']) ? 1 : 0); } else { $oContentType->setExtra(''); } if (E::ModuleTopic()->UpdateContentType($oContentType)) { if ($oContentType->getContentUrl() != $sTypeOld) { //меняем у уже созданных топиков системный тип E::ModuleTopic()->ChangeType($sTypeOld, $oContentType->getContentUrl()); } E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('action.admin.contenttypes_success_edit'), null, true); R::Location('admin/settings-contenttypes/'); } return false; }