_addMessageTemplate(static::MSG_UNKNOWN_STATUS, 'Unknown Post Status'); return $this; } public function exec() { $params = $this->getRestParams(); if (count($params) == 1 && is_numeric($params[0])) { $id = $params[0]; $this->_getDataObj()->setIdPost($id); if (($title = $this->_getDataObj()->getPostTitle())) { $url = htmlspecialchars(\Qs_SiteMap::getAliasByItem('Blog\\Admin\\') . '?action=edit&id=' . $id); $title = htmlspecialchars($title); $itemsName = htmlspecialchars($this->getConfig('itemsName')); $this->_doc->setHeader('' . $title . ' ' . $itemsName); } } else { $this->_doc->display404(); } return parent::exec(); } protected function _getEditForm(array $options = []) { list($options['defaults']['postingDate'], $options['defaults']['postingTime']) = explode(' ', $options['defaults']['date']); return $this->_getFormInstance('edit', $options); } protected function _getNewForm(array $options = []) { $options = ['defaults' => ['idPost' => $this->_getDataObj()->getIdPost()]]; return $this->_getFormInstance('new', $options)->setDefaults($this->_getUserInfo()); } protected function _doView() { $item = $this->_getDataObj()->getData(); if (empty($item)) { $this->_doc->displayError('Invalid comment ID'); return false; } $item['tpl'] = $this->getTemplate('view.tpl'); $this->_doc->addItem($item); $this->_postView(); return $this; } protected function _doChangeStatus() { if (null === ($data = $this->_getDataObj()->getData())) { $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } if (!$this->_lock()) { $this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker())); $this->_doBack(); } $status = \Qs_Request::getRequestValue('status'); if ($this->_getDataObj()->changeStatus($status)) { $this->_setBackMessage(static::MSG_UPDATED); $this->_postChangeStatus(); } else { $this->_setBackError(static::MSG_UNKNOWN_STATUS); } $this->_doBack(); } protected function _postChangeStatus() { if ($this->_hasLog) { $this->_getLog()->setAction('changeStatus', 'Set "%status%" Status for "%itemTitle%" Post'); $this->_log(); } return $this; } protected function _addListItem() { $this->_initListRedirection(); $item = $this->_getListItem(); if (!count($item['list']) && $this->_getDataObj()->getFilter('status')) { \Qs_Http::redirect($this->url()); } $this->_addLinksItem(); $item['tpl'] = $this->getTemplate('list.tpl'); $item['statuses'] = Form\FilterForm::$commentStatusLinks; $this->_addItem($item); return $this; } protected function _initFromForm(\Qs_Form $form) { $data = $form->getValues(); $data['date'] = $data['postingDate'] . ' ' . $data['postingTime']; $this->_getDataObj()->initFromForm($data); return $this; } protected function _doInsert() { $this->_getDataObj()->setAction($this->_action); return parent::_doInsert(); } protected function _doGoBack() { $backUrl = $this->_getBackUrl(PARENT_PAGE_FINAL, BASE_URL_LANGUAGE . '/' . PARENT_PAGE_FINAL); $this->_clearBackUrl(); \Qs_Http::redirect($backUrl); } protected function _getDefaultLinks() { $links = ['goBack' => 'Back to ' . \Qs_Application::getConfig('Blog\\Admin\\')->get('itemsName')]; $links += parent::_getDefaultLinks(); return $links; } protected function _getFilterFormOptions() { $options = parent::_getFilterFormOptions(); $options['postId'] = $this->_getDataObj()->getIdPost(); return $options; } }