示例#1
0
 public function addComment($postId)
 {
     if ($this->auth->guest()) {
         $this->app->redirect('/login');
         $this->app->flash('info', 'you must log in to do that');
     } else {
         $author = $_SESSION['user'];
         $text = $this->app->request->post("text");
         $token = $this->app->request->post("csrf_token");
         $post = $this->postRepository->find($postId);
         $validation = new PostValidation('title', $author, $text, $token, false);
         if ($validation->isGoodToGo()) {
             # When the post is paid for, and not answered by a doctor
             # the doctor gets 7 $ and the user pays 10 $.
             if ($post->isPayedPost() and !$post->isAnswered() and $this->auth->user()->isDoctor()) {
                 $this->addTransaction($post);
             }
             $comment = new Comment();
             $comment->setAuthor($author);
             $comment->setText($text);
             $comment->setDate(date("dmY"));
             $comment->setPost($postId);
             $this->commentRepository->save($comment);
             $this->app->redirect('/posts/' . $postId);
         }
     }
     $this->app->flashNow('error', join('<br>', $validation->getValidationErrors()));
     $this->app->render('createpost.twig');
 }
示例#2
0
 public function addComment($postId)
 {
     if (!$this->auth->guest()) {
         $comment = new Comment();
         $comment->setAuthor($_SESSION['user']);
         $comment->setText($this->app->request->post("text"));
         $comment->setDate(date("dmY"));
         $comment->setPost($postId);
         $comment->setAnsDoc($this->app->request->post('ansdoc'));
         $this->commentRepository->save($comment);
         $this->app->redirect('/posts/' . $postId);
     } else {
         $this->app->redirect('/login');
         $this->app->flash('info', 'you must log in to do that');
     }
 }
示例#3
0
 public function addComment($postId)
 {
     if ($this->postRepository->checkAnsweredByDoctor($postId) == 0) {
         if ($this->auth->doctor()) {
             //Add 7$ to doctor's wallet
             $user = $this->auth->user();
             $this->userRepository->saveEarnings($user, 7);
             //Add 7$ to the post-author spent.
             $authorName = $this->postRepository->find($postId)->getAuthor();
             $author = $this->userRepository->findByUser($authorName);
             //$author->setTotalpayed($author->getTotalPayed()+7);
             $this->userRepository->saveSpendings($author, 7);
             //Set doctoranswered flag.
             $post = $this->postRepository->find($postId);
             $post->setDoctor(1);
             $this->postRepository->saveExistingPost($post);
         }
     }
     if (!$this->auth->guest()) {
         if ($_POST['csrf_token'] !== $_SESSION['csrf_token']) {
             $this->app->flash("info", "Something went wrong. Please reload the page and try again.");
             $this->app->redirect('/posts/' . $postId);
         }
         $isDoctor = $this->userRepository->getIsDoctor($_SESSION['user']);
         if ($isDoctor == 1) {
             $this->postRepository->updateDoctor($postId, 1);
         }
         $comment = new Comment();
         $comment->setAuthor($_SESSION['user']);
         $comment->setText($this->app->request->post("text"));
         $comment->setDate(date("dmY"));
         $comment->setPost($postId);
         $this->commentRepository->save($comment);
         $this->app->redirect('/posts/' . $postId);
     } else {
         $this->app->redirect('/login');
         $this->app->flash('info', 'you must log in to do that');
     }
 }
示例#4
0
 public function addComment($postId)
 {
     if (!$this->auth->guest()) {
         //now we save the comment with checking :-)
         $request = $this->app->request;
         $validation = new CommentValidation($request->post("text"), $postId, $request->post("csrftoken"));
         if ($validation->isGoodToGo()) {
             $author_name = $_SESSION['user'];
             $author = $this->userRepository->findByUser($author_name);
             if ($author->isDoctor() == true) {
                 $post = $this->postRepository->find($postId);
                 if ($post->getAnswerByDoctor() == 0) {
                     if (!$this->postRepository->acquireLock($postId, $_SESSION['user'])) {
                         $this->app->flash("info", "The post is now locked by another doctor and therefore cannot be saved");
                         $this->app->redirect("/posts/" . $postId);
                     }
                     $post->setAnswerByDoctor(1);
                     $this->postRepository->answeredByDoctor($postId);
                     $this->userRepository->payMoney($post->getAuthor(), $author_name, 10);
                     $this->postRepository->releaseLock($postId, $_SESSION['user']);
                 } else {
                     $this->app->flash("info", "The post was already answered by another doctor and therefore you did not get a payment for your answer");
                 }
             }
             $comment = new Comment($request->post("text"));
             $comment->setAuthor($_SESSION['user']);
             $comment->setText($this->app->request->post("text"));
             $comment->setDate(date("dmY"));
             $comment->setPost($postId);
             $this->commentRepository->save($comment);
             $this->app->redirect('/posts/' . $postId);
         } else {
             $this->app->flash('error', join("\n", $validation->getValidationErrors()));
             $this->app->redirect('/posts/' . $postId);
         }
     } else {
         $this->app->redirect('/login');
         $this->app->flash('info', 'you must log in to do that');
     }
 }