Пример #1
0
 /**
  * @inheritdoc
  */
 public function make()
 {
     // update readed marker
     $this->_post->readed = 1;
     $this->_post->save();
     // add new answer row in database
     $record = new FeedbackAnswer();
     $record->feedback_id = $this->_post->id;
     $record->name = $this->name;
     $record->email = $this->email;
     $record->message = $this->message;
     $record->user_id = $this->_userId;
     $record->is_admin = 1;
     $record->ip = $this->_ip;
     $record->save();
     // add user notification
     if ((int) $this->_post->user_id > 0 && $this->_userId !== (int) $this->_post->user_id) {
         $notify = new EntityAddNotification((int) $this->_post->user_id);
         $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
         $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($this->_post->message, 50)]);
     }
     // send email notification
     $this->sendEmail($this->_post);
     // unset message data
     $this->message = null;
 }
Пример #2
0
 /**
  * Save data to database
  */
 public function make()
 {
     $this->_record->name = $this->name;
     $this->_record->email = $this->email;
     $this->_record->message = $this->message;
     $this->_record->save();
 }
Пример #3
0
 /**
  * Add new row to database and set post is unreaded
  */
 public function make()
 {
     // update readed marker
     $this->_post->readed = 0;
     $this->_post->save();
     // add new answer row in database
     $record = new FeedbackAnswer();
     $record->feedback_id = $this->_post->id;
     $record->name = $this->name;
     $record->email = $this->email;
     $record->message = $this->message;
     if ($this->_userId > 0) {
         $record->user_id = $this->_userId;
     }
     $record->ip = $this->_ip;
     $record->save();
     // add notification msg
     $targetId = $this->_post->user_id;
     if ($targetId !== null && (int) $targetId > 0 && $targetId !== $this->_userId) {
         $notify = new EntityAddNotification($targetId);
         $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
         $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($this->_post->message, 50)]);
     }
 }
Пример #4
0
 /**
  * Delete feedback post or answer
  * @param string $type
  * @param int $id
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws NotFoundException
  * @throws \Exception
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionDelete($type, $id)
 {
     // try to get active record by type
     $record = null;
     switch ($type) {
         case 'post':
             $record = FeedbackPost::find($id);
             break;
         case 'answer':
             $record = FeedbackAnswer::find($id);
             break;
     }
     // check if we get the row
     if ($record === null || $record === false) {
         throw new NotFoundException(__('Feedback item is not founded'));
     }
     // if delete is submited
     if ($this->request->request->get('deleteFeedback')) {
         // remove all answers
         if ($type === 'post') {
             FeedbackAnswer::where('feedback_id', '=', $record->id)->delete();
             // remove item
             $record->delete();
             App::$Session->getFlashBag()->add('success', __('Feedback record is successful removed'));
             $this->response->redirect('feedback/index');
         } else {
             // its a answer, lets remove it and redirect back in post
             $postId = $record->feedback_id;
             $record->delete();
             $this->response->redirect('feedback/read/' . $postId);
         }
     }
     // render view
     return $this->view->render('delete', ['type' => $type, 'record' => $record]);
 }