Example #1
0
 public function post($title, $body, $user = null)
 {
     if (!Auth::check()) {
         return false;
     }
     if (!$user) {
         $user = Auth::user();
     }
     if ($user->canAccessForum($this->id)) {
         $topic = new ForumTopic();
         $topic->forum_id = $this->id;
         $topic->title = $title;
         $topic->save();
         $post = new ForumPost();
         $post->topic_id = $topic->id;
         $post->body = $body;
         $post->posted_by = $user->id;
         $post->save();
         $topic->first_post = $post->id;
         $topic->save();
         return $topic;
     } else {
         return false;
     }
 }
Example #2
0
 public function postReply($user_id, $body)
 {
     $post = new ForumPost();
     $post->topic_id = $this->id;
     $post->body = $body;
     $post->posted_by = $user_id;
     $post->save();
     return $post;
 }
Example #3
0
 /**
  * Add new comment
  *
  * @param Request $request
  * @param $matches
  * @return mixed|string
  */
 public function post(Request $request, $matches)
 {
     $comment = trim($request->get('comment'));
     $topic = \ForumTheme::find($matches->get('topic'));
     // Assign com id
     $this->view->assign('topic', $topic);
     // Posting comment
     if ($request->isMethod('post')) {
         // Check comment
         if (!$topic || strlen($comment) < 2 || !$topic->active) {
             return static::json_response(['error' => 1, 'message' => $this->lang->translate('forum.post.failed')]);
         }
         // Check permissions
         if (!$this->user->can('write_forum')) {
             return static::json_response(['error' => 2, 'message' => $this->lang->translate('forum.post.denied')]);
         }
         // Create new comment
         $comment = new \ForumPost(['author_id' => $this->user->id, 'theme_id' => $topic->id, 'content' => $comment]);
         if ($comment->save()) {
             $status = ['success' => $comment->id, 'message' => $this->lang->translate('forum.post.success')];
         } else {
             $status = ['error' => 3, 'message' => $this->lang->translate('forum.post.failed')];
         }
         $this->view->assign('status', $status);
     }
     return $this->posts_list($request, $matches);
 }