['new', 'list']]; protected $_settingsPrefix = 'blogComment'; public function setIdPost($idPost) { $this->_getDataObj()->setIdPost($idPost); return $this; } protected function _getDefaultLinks() { return []; } protected function _getListOptions() { $options = parent::_getListOptions(); $options['postTitle'] = $this->_getDataObj()->getPostTitle(); $options['viewAlias'] = $this->_getViewAlias(); return $options; } protected function _doList() { parent::_doList(); $this->_doNew(); return $this; } protected function _getNewForm(array $options = []) { $options['defaults']['identity'] = $this->_getAdminOrUserIdentity(); $options['defaults']['idPost'] = $this->_getDataObj()->getIdPost(); return parent::_getNewForm($options); } protected function _doInsert() { $this->_getDataObj()->setAction($this->_action); return parent::_doInsert(); } protected function _addFormItem(\Qs_Form $form) { $item = []; $item['commentSubmitted'] = $this->getShowThankYou(); $item['tpl'] = $this->getTemplate('form.tpl', false); $item['form'] = $form->render(); $this->_addItem($item); if ($item['commentSubmitted']) { $this->_doc->addScript('js/jquery.scrollTo.js'); $this->_doc->addScript('js/app/blog.js'); $this->_doc->addInitFunction('Blog.initComments'); } return $this; } protected function _setBackMessage($messageKey) { return $this; } protected function _postInsert() { parent::_postInsert(); $this->setShowThankYou(); $this->_sendAdminNotification(); return $this; } public function setShowThankYou() { $session = $this->_getSession(); $session->commentFormSubmitted = true; $session->setExpirationHops(1, 'commentFormSubmitted'); return $this; } protected function _getSession() { if (null === $this->_session) { $this->_session = new \Qs_Session_Namespace(get_class($this), true); } return $this->_session; } public function getShowThankYou() { $session = $this->_getSession(); return (bool) $session->commentFormSubmitted; } protected function _getMailData() { $dataObj = $this->_getDataObj(); $data = $dataObj->clearData()->getData(); $data['postTitle'] = $dataObj->getPostTitle(); $data['comment'] = $data['content']; $data['link'] = \Qs_SiteMap::findFirst(null, ['type' => 'Blog\\Comment\\Admin\\'], null, 'url') . '/' . $data['idPost'] . '?action=edit&id=' . $data['id']; $preparedData = []; foreach ($data as $key => $value) { $preparedData['{' . $key . '}'] = htmlspecialchars($value); } return $preparedData; } protected function _sendAdminNotification() { $data = $this->_getMailData(); $from = \App_Settings_Obj::getEmailFrom($this->_settingsPrefix . 'EmailFrom'); $to = \App_Settings_Obj::getFormEmails($this->_settingsPrefix . 'EmailTo'); $subject = \App_Settings_Obj::get($this->_settingsPrefix . 'EmailSubject'); $body = \App_Settings_Obj::get($this->_settingsPrefix . 'EmailBody'); $body = str_replace(array_keys($data), array_values($data), $body); $this->_sendMail(compact('from', 'to', 'subject', 'body')); return $this; } }