_setMessage($this->_messagePostAdded, self::MSG_ADDED); return parent::_init(); } protected function _doDelete() { if ($this->_doc->getAuth()->isLoggedIn() && $this->_doc->getUserId() == $this->_getDataObj()->getData('submitterUserId') ) { parent::_doDelete(); } $this->_doBack(); } protected function _doRenew() { $days = (int) App_Settings_Obj::get('classifiedDays'); $actualDate = $this->_getDataObj()->getData('expirationDate'); if (date("Ymd", strtotime($actualDate)) < date("Ymd")) { $actualDate = date("Y-m-d"); } $data = [ 'expirationDate' => date( 'Y-m-d', strtotime($actualDate . " + " . $days . " day") ) ]; if (false === $this->_getDataObj()->update($data)) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $this->_postUpdate(); $this->_setBackMessage(static::MSG_UPDATED); } $this->_doBack(); } protected function _doNewForSale() { return $this->_doNewByType(AbstractObj::TYPE_FOR_SALE); } protected function _doNewWanted() { return $this->_doNewByType(AbstractObj::TYPE_WANTED); } protected function _doNewHelpWanted() { return $this->_doNewByType(AbstractObj::TYPE_HELP_WANTED); } protected function _doNewOther() { return $this->_doNewByType(AbstractObj::TYPE_OTHER); } protected function _doNewByType($type) { $form = $this->_getNewForm(['type' => $type]); $form->setDefaults(); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _getEditForm(array $options = array()) { $options = $this->_addType4Options($options); return parent::_getEditForm($options); } protected function _getNewForm(array $options = array()) { $options = $this->_addType4Options($options); return parent::_getNewForm($options); } protected function _getDefaultLinks() { $links = array(); $types = (new Qs_Db_Table('ClassifiedType'))->get4Select(); foreach ($types as $type => $label) { $links['new' . ucfirst($type)] = $label; } return $links; } /** * @param array $options * @return array */ protected function _addType4Options(array $options) { if (empty($options['type'])) { if (null === ($data = $this->_getDataObj()->getData())) { $type = \Qs_Request::getPostValue('type'); } else { $type = $data['type']; } $options['type'] = $type; return $options; } return $options; } }