_idItem) { $this->_idItem = abs(crc32(__CLASS__)); } return $this; } public function getSideBlockItem(array $blockData = array()) { $item = array(); $this->_initAction(); if ('insert' == $this->_action) { $this->exec(); } else { $form = $this->_getNewForm(); $form->setDefaults(); $item = array( 'tpl' => $this->getTemplate('text.tpl'), 'formId' => $form->getId(), 'isSideBlock' => true, 'thankYouMessage' => $this->_getThankYouMessage(), 'text' => $form->render() ); } return $item; } protected function _doInsertAjax() { $this->_doInsert(); } protected function _doInsert() { $form = $this->_getNewForm(); $result = $form->validateAjax(); if ($result['isValid']) { $this->_initFromForm($form); if (false === $this->_getDataObj()->insert()) { $result['idValid'] = false; $result['formErrors'] = $this->_getDataObj()->getErrors(); } else { $this->_postInsert(); } } $this->_displayJson($result); } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); if (empty($data['fullName'])) { $data['fullName'] = $data['firstName'] . ' ' . $data['lastName']; } $this->_getDataObj()->initFromForm($data); return $this; } protected function _getMailData(array $data) { $mailData = array( 'name' => htmlspecialchars($data['fullName']), 'email' => htmlspecialchars($data['email']), 'link' => Qs_SiteMap::findFirst(null, array('type' => 'Form_Newsletter_Admin_'), null, 'url') . '?action=view&id=' . $data['id'], ); return $mailData; } protected function _postInsert() { $data = $this->_getDataObj()->clearData()->getData(); $this->_sendAdminNotification($data); $this->_sendUserNotification($data); $this->_log(); return $this; } protected function _sendUserNotification(array $data) { $to = $data['email']; $body = App_Settings_Obj::get($this->_settingsUserPrefix . 'Body'); if (empty($to) || empty($body)) { return false; } $subject = App_Settings_Obj::get($this->_settingsUserPrefix . 'Subject'); $from = App_Settings_Obj::getEmailFrom($this->_settingsUserPrefix . 'From'); $mailData = $this->_getMailData($data); foreach ($mailData as $field => $value) { $body = str_replace('{' . $field . '}', $value, $body); } $options = array( 'from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $body, ); $this->_sendMail($options); return $this; } protected function _addFormItem(Qs_Form $form) { $item['tpl'] = $this->getTemplate('text.tpl'); $item['header'] = $this->getConfig('formHeader'); $item['thankYouMessage'] = $this->_getThankYouMessage(); $item['text'] = $form->render(); $this->_addItem($item); return $this; } }