_getDataObj()->getData(); if (empty($data)) { $this->_do404(); } $this->_doc->setHeader('Job Details'); $this->_addItem(array( 'tpl' => $this->getTemplate('view.tpl'), 'data' => $data, )); return $this; } public function preDispatch(&$items) { if (!$this->_restAlias && \App\Job\Form\ConfigForm::TYPE_ADD_JOB != $this->getConfig('type')) { return $this; } foreach ($items as $index => $item) { if ('HtmlBlock_' == $item['type'] && 'ITEMS' == $item['groupName']) { unset($items[$index]); } } return $this; } protected function _doCancel() { $this->_unlock(); \Qs_Http::redirect(\Qs_SiteMap::findFirst(null, array('type' => 'Job\\'), array('type' => \App\Job\Form\ConfigForm::TYPE_DEFAULT), 'url')); } protected function _doInsert() { $form = $this->_getNewForm(); if ($form->validate()) { $this->_initFromForm($form); if (false === $this->_getDataObj()->insert()) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $this->_postInsert(); $this->_setBackMessage(static::MSG_ADDED); } \Qs_Http::redirect(BASE_URL_LANGUAGE . '/' . CURRENT_PAGE . '/' . $this->_thankYouPageAlias); } else { $this->_addFormItem($form); } return $this; } protected function _postInsert() { $this->_sendAdminNotification(); return parent::_postInsert(); } protected function _sendAdminNotification() { $settingsPrefix = 'jobListingAdded2Admin'; $template = $this->_getMailTemplateData($settingsPrefix); $data = $this->_getDataObj()->getData(); $data['link'] = \Qs_SiteMap::findFirst(null, array('type' => 'Job\\Admin\\'), null, 'url') . '?action=edit&id=' . $this->_getDataObj()->getPrimaryKey(); if (!empty($template['to'])) { $this->_prepareMailBody($template['body'], $data); $this->_sendMail($template); } return $this; } protected function _prepareMailBody(&$body, $data) { foreach ($data as $field => $value) { if (empty($value)) { $value = '-'; } $body = str_replace('{' . $field . '}', $value, $body); } return $this; } /** * Return array mail template data from settings * * @param string $settingsPrefix * @return array */ protected function _getMailTemplateData($settingsPrefix) { $data = false; if (!empty($settingsPrefix)) { $data = array(); $data['subject'] = \App_Settings_Obj::get($settingsPrefix . 'Subject'); $data['body'] = \App_Settings_Obj::get($settingsPrefix . 'Body'); $data['from'] = \App_Settings_Obj::get($settingsPrefix . 'From'); $data['to'] = \App_Settings_Obj::getFormEmails($settingsPrefix . 'To'); } return $data; } protected function _initAction() { if (\App\Job\Form\ConfigForm::TYPE_ADD_JOB == $this->getConfig('type')) { if (!\App_User_Auth::getInstance()->isLoggedIn()) { $this->_do404(); } $this->_actions[] = 'new'; $this->_actions[] = 'insert'; $this->_action = \Qs_Request::getRequestValue('action') ? \Qs_Request::getRequestValue('action') : 'new'; return parent::_initAction(); } if ($this->_restAlias) { $parts = explode('/', $this->_restAlias); if (count($parts) > 1) { $this->_do404(); } $this->_getDataObj()->setPrimaryKey($parts[0]); $this->_action = 'view'; } return parent::_initAction(); } }