_idItem) { $this->_idItem = abs(crc32(__CLASS__)); } $this->_userFieldRules['name'] = array($this, 'prepareUserName'); return $this; } protected function prepareUserName(array $userData) { return $userData['firstName'] . ' ' . $userData['lastName']; } protected function _getMailData(array $data) { $viewUrl = Qs_SiteMap::findFirst(null, array('type' => 'Form_Contact_Admin_'), null, 'url'); $emptyValue = $this->getConfig('emptyFieldText'); $mailData = array( 'name' => htmlspecialchars($data['name']), 'email' => htmlspecialchars((empty($data['email']) ? $emptyValue : $data['email'])), 'phone' => htmlspecialchars((empty($data['phone']) ? $emptyValue : $data['phone'])), 'comments' => nl2br(htmlspecialchars($data['comments'])), 'link' => $viewUrl . '?action=view&id=' . $data['id'], ); if ($this->getConfig('contactReasonEnabled', true)) { $reasons = $this->_getDataObj()->getDContactReason4Select(); $mailData['reason'] = Qs_Array::get($reasons, $data['idReason']); } return $mailData; } protected function _addThankYouMessage(array &$item) { $item['isThankYouMessage'] = $this->getShowThankYou(); if ($item['isThankYouMessage']) { $item['thankYouMessage'] = $this->_getThankYouMessage(); $this->_doc->addInitFunction('qs.scrollToNode', array('#contact-form-thanks', 250)); if ($this->_doc->isGtmEnabled()) { $this->_doc->addInitFunction('dataLayer.push', [[ 'event' => 'gaTriggerEvent', 'gaEventCategory' => 'Contact Form', 'gaEventAction' => 'Submit', 'gaEventLabel' => 'Main' ]]); } } return $this; } protected function _addFormItem(Qs_Form $form) { $item['tpl'] = $this->getTemplate('text.tpl'); $item['header'] = $this->getConfig('formHeader'); $item['text'] = $form->render(); $item['address'] = App_Settings_Obj::get('Address'); $item['map'] = App_Settings_Obj::get('Map'); $this->_addThankYouMessage($item); $this->_addItem($item); return $this; } protected function _postInsert() { $data = $this->_getDataObj()->clearData()->getData(); $this->_sendAdminNotification($data); $this->setShowThankYou(); $this->_log(); return $this; } public function setShowThankYou() { $session = $this->_getSession(); $session->contactBlockAdminNotification = true; $session->setExpirationHops(1, 'contactBlockAdminNotification'); return $this; } /** * @return Qs_Session_Namespace */ 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->contactBlockAdminNotification; } protected function _setBackMessage($msg = null) { return true; } protected function _getNewForm(array $options = array()) { if (null === $this->_form) { $options['hasReason'] = $this->_getDataObj()->hasReason(); $options['reasons'] = $this->_getDataObj()->getDContactReason4Select(); $this->_form = parent::_getNewForm($options); } return $this->_form; } public function getSideBlockItem(array $blockData = array()) { $item = array(); $this->_initAction(); if ('insert' == $this->_action) { $this->exec(); // якщо в exec() не відбувся редірект, то значить форма не провалідувалась, і треба її показати $item = array( 'tpl' => $this->getTemplate('text.tpl'), 'text' => $this->_getNewForm()->render(), 'isSideBlock' => true ); } else { $form = $this->_getNewForm(); $form->setDefaults(); $item = array('tpl' => $this->getTemplate('text.tpl'), 'text' => $form->render(), 'isSideBlock' => true); $this->_addThankYouMessage($item); } return $item; } 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); } $this->_doBack(); } return $this; } }