예제 #1
0
 public function create()
 {
     foreach ($this->required as $required => $strlen) {
         if (!Input::has($required) || strlen(Input::get($required)) < $strlen) {
             return Response::make(['error' => 'You must introduce a ' . $required . ' with ' . $strlen . ' of length...'], 404);
         }
     }
     $new = new Topic();
     $new->fill(Input::only(['title', 'author', 'message']));
     $new->place = $this->place;
     $new->save();
     return Response::make(['success' => 'You just created a new topic!', 'topic' => $new->toArray()], 404);
 }
예제 #2
0
 /**
  * Transform the \Topic entity.
  *
  * @param Topic $model
  *
  * @return array
  */
 public function transformData($model)
 {
     $data = $model->toArray();
     $data['links'] = ['details_web_view' => route('topic.web_view', $model->id), 'replies_web_view' => route('replies.web_view', $model->id), 'web_url' => trim(config('app.url'), '/') . '/topics/' . $model->id];
     return $data;
 }
예제 #3
0
 /**
  * Transform the \Topic entity.
  *
  * @param Topic $model
  *
  * @return array
  */
 public function transformData($model)
 {
     return $model->toArray();
     return ['id' => (int) $model->id, 'title' => $model->title, 'body' => $model->body, 'user_id' => (int) $model->user_id, 'node_id' => (int) $model->node_id, 'is_excellent' => (bool) $model->is_excellent, 'is_wiki' => (bool) $model->is_wiki, 'view_count' => (int) $model->view_count, 'reply_count' => (int) $model->reply_count, 'favorite_count' => (int) $model->favorite_count, 'vote_count' => (int) $model->vote_count, 'created_at' => $model->created_at, 'updated_at' => $model->updated_at];
 }
예제 #4
0
 /**
  * Crée un nouveau topic dans le forum désiré
  *
  * @param $slug Slug du forum dans lequel sera le topic
  * @param $id Id du forum dans lequel sera le topic
  */
 public function newTopic($slug, $id)
 {
     $user = Auth::user();
     $forum = Forum::find($id);
     $category = $forum->getCategory();
     $parsedContent = null;
     // L'utilisateur possède le droit de crée un topic ici
     if ($category->getPermission()->start_topic != true) {
         return Redirect::route('forum_index')->with('message', 'You can\'t start a new topic here');
     }
     // Prévisualisation du post
     if (Request::getMethod() == 'POST' && Input::get('preview') == true) {
         $code = new Decoda\Decoda(Input::get('content'));
         $code->defaults();
         $parsedContent = $code->parse();
     }
     if (Request::getMethod() == 'POST' && Input::get('post') == true) {
         // Crée le topic
         $topic = new Topic();
         $topic->name = Input::get('title');
         $topic->slug = Str::slug(Input::get('title'));
         $topic->state = 'open';
         $topic->first_post_user_id = $topic->last_post_user_id = $user->id;
         $topic->first_post_user_username = $topic->last_post_user_username = $user->username;
         $topic->views = 0;
         $topic->pinned = false;
         $topic->forum_id = $forum->id;
         $v = Validator::make($topic->toArray(), $topic->rules);
         if ($v->passes()) {
             $topic->save();
             $post = new Post();
             $post->content = Input::get('content');
             $post->user_id = $user->id;
             $post->topic_id = $topic->id;
             $v = Validator::make($post->toArray(), $post->rules);
             if ($v->passes()) {
                 $post->save();
                 $topic->num_post = 1;
                 $topic->save();
                 $forum->num_topic = $forum->getTopicCount($forum->id);
                 $forum->num_post = $forum->getPostCount($forum->id);
                 $forum->last_topic_id = $topic->id;
                 $forum->last_topic_name = $topic->name;
                 $forum->last_topic_slug = $topic->slug;
                 $forum->last_post_user_id = $user->id;
                 $forum->last_post_user_username = $user->username;
                 $forum->save();
                 return Redirect::route('forum_topic', array('slug' => $topic->slug, 'id' => $topic->id));
             } else {
                 // Impoossible de save le premier post donc delete le topic
                 $topic->delete();
             }
         } else {
             Session::put('message', 'An error has occurred with this topic. Try again.');
         }
     }
     return View::make('forum.new_topic', array('forum' => $forum, 'category' => $category, 'parsedContent' => $parsedContent, 'title' => Input::get('title'), 'content' => Input::get('content')));
 }