_getDataObj()->setProductId($productId); return $this; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); $data['userId'] = $this->_doc->getAuthData('id'); $this->_getDataObj()->initFromForm($data); return $this; } /** * @return Qs_Doc_Item */ public function getListItem() { $this->_initListRedirection(); $item = $this->_getListItem(); $this->_initListPageNumber($item); if (empty($item['config'])) { $item['config'] = $this->getConfig()->toArray(); } $item['templatePath'] = $this->_getTemplatePath(); $docItem = new Qs_Doc_Item($item); $this->_doc->addItemResources($docItem); return $docItem; } /** * @return Qs_Doc_Item */ public function getNewFormItem() { $options['defaults']['productId'] = $this->_getDataObj()->getProductId(); if (($user = $this->_doc->getAuthData())) { $options['defaults']['name'] = $user['firstName'] . ' ' . $user['lastName']; $options['defaults']['email'] = $user['email']; } $options['action'] = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce\\Product\\Review\\'], null, 'url'); $options['attribs'] = [ 'id' => 'ecommerce-product-review-form', 'class' => 'ecommerce_product_review_form', ]; $form = $this->_getNewForm($options); $form->setDefaults(); $item = ['tpl' => $this->getTemplate('form.tpl'), 'html' => $form->render()]; if (empty($item['config'])) { $item['config'] = $this->getConfig()->toArray(); } $item['templatePath'] = $this->_getTemplatePath(); $docItem = new Qs_Doc_Item($item); $this->_doc->addItemResources($docItem); return $docItem; } protected function _doInsert() { $this->_do404(); return $this; } protected function _doInsertAjax() { $productId = Qs_Request::getPostValue('productId'); $this->setProductId($productId); $form = $this->_getNewForm(); $result = $form->validateAjax(); if ($result['isValid']) { $this->_initFromForm($form); if (false === $this->_getDataObj()->insert()) { $result['isValid'] = false; $result['formErrors'] = array_merge($result['formErrors'], $this->_getDataObj()->getErrors()); } else { $this->_postInsert(); } } $this->_displayJson($result); } protected function _postInsert() { parent::_postInsert(); $this->_sendAdminNotification(); return $this; } protected function _sendAdminNotification() { $data = $this->_getMailData(); $from = Settings::getEmailFrom('reviewFormEmailFrom'); $to = Settings::getFormEmails('reviewFormEmailTo'); $subject = Settings::get('reviewFormEmailSubject'); $subject = str_replace(array_keys($data), array_values($data), $subject); $body = Settings::get('reviewFormEmailBody'); $body = str_replace(array_keys($data), array_values($data), $body); return $this->_sendMail(compact('from', 'to', 'subject', 'body')); } protected function _getMailData() { $dataObj = $this->_getDataObj(); $data = $dataObj->clearData()->getData(); if (!$data) { return []; } $reviewUrl = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce\\Product\\Review\\Admin\\'], null, 'url'); $data['link'] = $reviewUrl . '/' . $data['productId'] . '?action=edit&id=' . $data['id']; $preparedData = []; $textareaFields = ['message']; foreach ($data as $key => $value) { if (in_array($key, $textareaFields)) { $preparedData['{' . $key . '}'] = nl2br(htmlspecialchars($value)); } else { $preparedData['{' . $key . '}'] = htmlspecialchars($value); } } return $preparedData; } }