_getDataObj()->getCategories(); $this->_idCategory = (int) Qs_Request::getRequestValue('idCategory', key($categories)); // дефолтна категорія $dataObj = new App_Settings_Obj([ 'idCategory' => $this->_idCategory, 'suMode' => $this->_doc->getAuth()->getSuMode(), ]); $this->setDataObj($dataObj); parent::_init(); $this->_setMessage('%itemsName% have been updated', static::MSG_UPDATED); $message = 'This category is currently being edited by "%firstName% %lastName%" %userRoleTitle%. ' . 'Please try again later.'; $this->_setMessage($message, static::MSG_LOCKED); return $this; } protected function _getEditForm(array $options = []) { $options['cancelUrl'] = Qs_Constant::get('BASE_URL_LANGUAGE') . '/' . Qs_Constant::get('CURRENT_PAGE') . '?action=cancel&idCategory=' . $this->_idCategory; $options['enctype'] = Qs_Form::ENCTYPE_MULTIPART; $options['idCategory'] = $this->_idCategory; return parent::_getEditForm($options); } protected function _getBackUrl($sessionName = null, $defaultUrl = null) { $options = ['idCategory' => $this->_idCategory]; return $this->url($options); } protected function _doEdit() { if (null === ($data = $this->_getDataObj()->getData())) { $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } if (App_Admin_Auth::getInstance()->getSuMode()) { $this->_addLinksItem(); } $this->_setPageHeader(); $this->_addCategoriesTabs(); if (!$this->_lock()) { $item = [ 'tpl' => $this->getTemplate('message-locked.tpl'), 'link' => $this->_getBackUrl(), 'message' => $this->_createMessage(static::MSG_LOCKED, $this->_getLocker()), ]; $this->_addItem($item); return $this; } $form = $this->_getEditForm(['defaults' => $data]); $form->setDefaults(); $this->_addFormItem($form); $this->_postEdit(); return $this; } protected function _doUpdate() { $this->_setPageHeader(); $this->_addCategoriesTabs(); return parent::_doUpdate(); } protected function _addCategoriesTabs() { $categories = $this->_getDataObj()->getCategories(); if (is_array($categories) && count($categories) > 1) { $buttons = []; foreach ($categories as $id => $label) { $click = "try {" . "document.location='" . BASE_URL . '/' . CURRENT_PAGE . '?idCategory=' . ((int) $id) . "'" . "} catch(e) {};" . "return false;"; $active = ($this->_idCategory == $id) ? true : false; $link = [ 'href' => '#', 'onclick' => $click, 'class' => 'nav-link', ]; if ($active) { $link['class'] = 'nav-link active'; } $buttons[] = ['html' => Html::renderContainer('a', $label, $link), 'active' => $active]; } $item = ['tpl' => $this->getTemplate('categories.tpl'), 'categories' => $buttons]; $this->_addItem($item); } return $this; } protected function _setPageHeader() { $categories = $this->_getDataObj()->getCategories(); $categoryId = $this->_getDataObj()->getPrimaryKey(); $this->_doc->setHeader('Edit ' . $categories[$categoryId]); return $this; } protected function _log() { if ($this->_hasLog && Qs_ViewController_Log::getEnabled()) { $options = [ 'categoryTitle' => Qs_Array::get($this->_getDataObj()->getCategories(), (string) $this->_idCategory), ]; $this->_getLog()->write($this->_action, $options); } return $this; } protected function _getDefaultLinks() { $url = Qs_SiteMap::findFirst(null, ['type' => 'Settings\Field\Admin\\'], null, 'url'); $links = [[ 'url' => $url . '?idCategory=' . $this->_idCategory, 'title' => 'Manage Fields', ]]; return $links; } }