Example #1
0
 /**
  * @param IFeedbackForm $form
  * @return bool
  */
 public function send(IFeedbackForm $form)
 {
     $feedback = new FeedBack();
     $feedback->setAttributes(['name' => $form->getName(), 'email' => $form->getEmail(), 'theme' => $form->getTheme(), 'text' => $form->getText(), 'phone' => $form->getPhone(), 'type' => $form->getType()]);
     if ($feedback->save()) {
         if ($this->module->sendConfirmation) {
             return $this->sendConfirmation($form, $feedback);
         }
         return true;
     }
     return false;
 }
Example #2
0
 public function send(FeedBackForm $form)
 {
     $feedback = new FeedBack();
     $feedback->setAttributes(array('name' => $form->name, 'email' => $form->email, 'theme' => $form->theme, 'text' => $form->text, 'phone' => $form->phone, 'type' => $form->type));
     if ($feedback->save()) {
         if ($this->module->sendConfirmation) {
             return $this->sendConfirmation($form, $feedback);
         }
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new FeedBack();
     if (isset($_POST['FeedBack'])) {
         $model->attributes = $_POST['FeedBack'];
         if ($model->save()) {
             Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, 'Сообщение сохранено!');
             $this->redirect(array('update', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #4
0
 public function actionIndex()
 {
     $form = new FeedBackForm();
     if (Yii::app()->request->isPostRequest && !empty($_POST['FeedBackForm'])) {
         $form->setAttributes($_POST['FeedBackForm']);
         $module = Yii::app()->getModule('feedback');
         if ($form->validate()) {
             // обработка запроса
             $backEnd = array_unique($module->backEnd);
             if (is_array($backEnd) && count($backEnd)) {
                 // запись в базу
                 if (in_array('db', $backEnd)) {
                     $feedback = new FeedBack();
                     $feedback->setAttributes(array('name' => $form->name, 'email' => $form->email, 'theme' => $form->theme, 'text' => $form->text, 'type' => $form->type));
                     if ($feedback->save()) {
                         Yii::log(Yii::t('feedback', 'Обращение пользователя добавлено в базу!'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
                         Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('feedback', 'Ваше сообщение отправлено! Спасибо!'));
                     } else {
                         $form->addErrors($feedback->getErrors());
                         Yii::log(Yii::t('feedback', 'Ошибка при добавлении обращения пользователя в базу!'), CLogger::LEVEL_ERROR, FeedbackModule::$logCategory);
                         Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('feedback', 'При отправке сообщения произошла ошибка! Повторите попытку позже!'));
                         $this->render('index', array('model' => $form));
                     }
                 }
                 if (in_array('email', $backEnd) && count($module->emails)) {
                     $emailBody = $this->renderPartial('application.modules.feedback.views.email.feedbackEmail', array('model' => $feedback), true);
                     foreach ($module->emails as $mail) {
                         Yii::app()->mail->send($module->notifyEmailFrom, $mail, $form->theme, $emailBody);
                     }
                     Yii::log(Yii::t('feedback', 'Обращение пользователя отправлено на email!'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('feedback', 'Ваше сообщение отправлено! Спасибо!'));
                     $this->redirect(array('/feedback/contact'));
                 }
             }
         }
     }
     $this->render('index', array('model' => $form));
 }
 /**
  * Сохраняем данные в СУБД, при наявности POST-запросаЖ
  *
  * @param AnswerForm $form - форма ответа
  * @param FeedBack $model - модель
  *
  * @return mixed
  */
 public function saveAnswer(AnswerForm $form, FeedBack $model)
 {
     if (Yii::app()->getRequest()->getIsPostRequest() && ($data = Yii::app()->getRequest()->getPost('AnswerForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             $model->setAttributes(['answer' => $form->answer, 'is_faq' => $form->is_faq, 'answer_user' => Yii::app()->user->getId(), 'answer_time' => new CDbExpression('NOW()'), 'status' => FeedBack::STATUS_ANSWER_SENDED]);
             if ($model->save()) {
                 //отправка ответа
                 $body = $this->renderPartial('answerEmail', ['model' => $model], true);
                 Yii::app()->mail->send(Yii::app()->getModule('feedback')->notifyEmailFrom, $model->email, 'RE: ' . $model->theme, $body);
                 if (Yii::app()->getRequest()->getIsAjaxRequest() == false) {
                     Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('FeedbackModule.feedback', 'Reply on message was sent!'));
                     $this->redirect(['/feedback/feedbackBackend/view/', 'id' => $model->id]);
                 } else {
                     Yii::app()->ajax->success(['message' => Yii::t('FeedbackModule.feedback', 'Reply on message was sent!')]);
                     return true;
                 }
             } else {
                 return [$form, $model];
             }
         }
     }
     return [$form, $model];
 }
Example #6
0
 public function actionIndex()
 {
     $form = new FeedBackForm();
     // если пользователь авторизован - подставить его данные
     if (Yii::app()->user->isAuthenticated()) {
         $form->email = Yii::app()->user->getState('email');
         $form->name = Yii::app()->user->getState('nick_name');
     }
     // проверить не передан ли тип и присвоить его аттрибуту модели
     $form->type = (int) Yii::app()->getRequest()->getParam('type', FeedBack::TYPE_DEFAULT);
     $module = Yii::app()->getModule('feedback');
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['FeedBackForm'])) {
         $form->setAttributes($_POST['FeedBackForm']);
         if ($form->validate()) {
             // обработка запроса
             $backEnd = array_unique($module->backEnd);
             if (is_array($backEnd) && count($backEnd)) {
                 // запись в базу
                 if (in_array('db', $backEnd)) {
                     unset($backEnd['db']);
                     $feedback = new FeedBack();
                     $feedback->setAttributes(array('name' => $form->name, 'email' => $form->email, 'theme' => $form->theme, 'text' => $form->text, 'phone' => $form->phone, 'type' => $form->type));
                     if ($feedback->save()) {
                         Yii::log(Yii::t('FeedbackModule.feedback', 'Feedback was inserted in DB'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
                         if ($module->sendConfirmation && !count($backEnd)) {
                             $this->feedbackConfirmationEmail($feedback);
                         }
                         Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('FeedbackModule.feedback', 'Your message sent! Thanks!'));
                         if (!count($backEnd)) {
                             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                                 Yii::app()->ajax->success(Yii::t('FeedbackModule.feedback', 'Your message sent! Thanks!'));
                             }
                             $this->redirect($module->successPage ? array($module->successPage) : array('/feedback/contact/faq'));
                         }
                     } else {
                         Yii::log(Yii::t('FeedbackModule.feedback', 'Error when trying to record feedback in DB'), CLogger::LEVEL_ERROR, FeedbackModule::$logCategory);
                         Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('FeedbackModule.feedback', 'There is an error when trying to send message! Please try later!'));
                         $this->render('index', array('model' => $form, 'module' => $module));
                     }
                 }
                 // отправка на почту
                 if (in_array('email', $backEnd) && count(explode(',', $module->emails))) {
                     $emailBody = $this->renderPartial('feedbackEmail', array('model' => $feedback), true);
                     foreach (explode(',', $module->emails) as $mail) {
                         Yii::app()->mail->send($feedback->email, $mail, $form->theme, $emailBody);
                     }
                     if ($module->sendConfirmation) {
                         $this->feedbackConfirmationEmail($feedback);
                     }
                     Yii::log(Yii::t('FeedbackModule.feedback', 'Feedback was send on e-mail'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
                     Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('FeedbackModule.feedback', 'Your message sent! Thanks!'));
                     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                         Yii::app()->ajax->success(Yii::t('FeedbackModule.feedback', 'Your message sent! Thanks!'));
                     }
                     $this->redirect($module->successPage ? array($module->successPage) : array('/feedback/contact/faq'));
                 }
             }
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('FeedbackModule.feedback', 'It is not possible to send message!'));
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->ajax->failure(Yii::t('FeedbackModule.feedback', 'It is not possible to send message!'));
             }
             $this->redirect(array('/feedback/contact/index/'));
         } else {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->ajax->failure(Yii::t('FeedbackModule.feedback', 'Please check e-mail and fill the form correct.'));
             }
         }
     }
     $this->render('index', array('model' => $form, 'module' => $module));
 }