'added DESC'); protected $_columns4ExportCsv; protected $_hasFilter = true; protected $_thanksPageAlias = 'thanks.html'; protected $_exportFileName; protected $_settingsPrefix; protected $_userUnsetFields = array('id', 'salt', 'autologinCode', 'recoverCode', 'recoverCodeExpirationDate', 'enabled', 'added', 'changed'); /** * Fields array with callbacks. For example: * * array( * 'userName' => array($this, 'prepareUserName') * ); * ... * public function prepareUserName(array $userData) * { * return $userData['firstName'] . ' ' . $userData['lastName']; * } * * @var array */ protected $_userFieldRules = array(); protected function _getNewForm(array $options = array()) { if ($this->_doc->hasAuth() && ($userData = $this->_doc->getAuthData())) { foreach ($this->_userUnsetFields as $field) { unset($userData[$field]); } if (!array_key_exists('defaults', $options)) { $options['defaults'] = array(); } foreach ($this->_userFieldRules as $field => $callback) { if (is_callable($callback)) { $userData[$field] = call_user_func($callback, $userData); } } $options['defaults'] = array_merge($userData, $options['defaults']); } return $this->_getFormInstance('new', $options); } protected function _postInsert() { $data = $this->_getDataObj()->clearData()->getData(); $this->_sendAdminNotification($data); $this->_log(); $this->_redirect(); return $this; } protected function _redirect() { $this->redirect($this->url() . '/' . $this->_thanksPageAlias); } protected function _sendAdminNotification($data) { $to = App_Settings_Obj::getFormEmails($this->_settingsPrefix . 'To'); $body = App_Settings_Obj::get($this->_settingsPrefix . 'Body'); if (empty($to) || empty($body)) { return false; } $subject = App_Settings_Obj::get($this->_settingsPrefix . 'Subject'); $from = App_Settings_Obj::getEmailFrom($this->_settingsPrefix . 'From'); $mailData = $this->_getMailData($data); foreach ($mailData as $field => $value) { $body = str_replace('{' . $field . '}', $value, $body); } $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, BASE_URL); $mail->setHtml($body, null, WWW_PATH); $mail->addTo($to); $mail->send(); return $this; } protected function _doView() { $item = $this->_getDataObj()->getData(); if (empty($item)) { $this->_doc->displayError('Invalid submission ID'); return $this; } $this->_getDataObj()->setViewed(); $this->_prepareItem($item); $item['config'] = $this->getConfig()->toArray(); $item['tpl'] = $this->getTemplate('view.tpl'); $this->_doc->addItem($item); // $this->_doc->addStylesheet('css/admin-print.css', array('media' => 'print')); $this->_postView(); return $this; } protected function _getDefaultLinks() { $links = parent::_getDefaultLinks(); $params = array(); if ($orderBy = Qs_Request::getGetValue('orderBy')) { $params['orderBy'] = $orderBy; } $filter = $this->_dataObj->getFilter(); foreach ($filter as $field => $value) { if ($value) { $params[$field] = $value; } } $params['action'] = 'exportCsv'; $links['exportCsv'] = array('title' => 'Export to CSV', 'url' => $this->url($params)); return $links; } /** * @param array $data * @return array * @throws Qs_Exception */ protected function _getMailData(array $data) { throw new Qs_Exception('_getMailData() not implemented'); } protected function _getFilterFields() { if (null === $this->_filterFields) { $this->_filterFields = $this->_getDataObj()->getFilterFields(); foreach ($this->_filterFields as $key => $value) { if (!is_scalar($value)) { unset($this->_filterFields[$key]); } } $this->_filterFields = array_flip($this->_filterFields); $columns = $this->_getDataObj()->getExportColumns(); $this->_filterFields = array_intersect_key($columns, $this->_filterFields); } return $this->_filterFields; } public function getApplicationName() { if (null === $this->_applicationName) { $name = get_class($this); $name = substr($name, 4); $this->_applicationName = substr($name, 0, strrpos($name, '_') ?: null); } return $this->_applicationName; } protected function _getLog() { if (null === $this->_log) { parent::_getLog(); $this->_log->removeAction('new'); $this->_log->setAction('insert', 'Submitted new "%formHeader%" Form'); } return $this->_log; } protected function _getThankYouMessage() { // $content = ''; // $currentItem = str_replace(array('App_', 'App\\', 'View'), '', get_class($this)); // $currentPage = Qs_SiteMap::findFirst(null, array('type' => $currentItem)); // // if ($currentPage // && !empty($currentPage['sub']) // && array_key_exists($this->_thanksPageAlias, $currentPage['sub']) // ) { // $page = $currentPage['sub'][$this->_thanksPageAlias]; // $htmlBlock = null; // // foreach ($page['items'] as $item) { // if ($item['type'] == 'HtmlBlock_') { // $htmlBlock = $item; // break; // } // } // // if (!empty($htmlBlock)) { // $htmlBlockView = new App_HtmlBlock_View($htmlBlock); // $data = $htmlBlockView->getData(); // if (is_array($data) && array_key_exists('content', $data)) { // $content = $data['content']; // } // } // } // ; $thankYouMessage = App_Settings_Obj::get(strtolower(str_replace(array('_','Form'),'',$currentItem)).'ThankYouMassage'); return $thankYouMessage; } }