public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(Auth::user(), $topic)) {
         Auth::user()->favoriteTopics()->detach($topic->id);
     } else {
         Auth::user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', Auth::user(), $topic->user, $topic);
     }
     flash()->success('hello!', lang('Operation succeeded.'));
     return Redirect::route('topics.show', $topic->id);
 }
Beispiel #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $topic = Topic::find($id);
     $topic->content = $request->content;
     $topic->title = $request->title;
     $topic->save();
     return Redirect::action('TopicController@show', ['id' => $id]);
 }
 public function detail($topic_id)
 {
     $topic = Topic::find($topic_id);
     if (!$topic) {
         return redirect()->guest('');
     }
     return view('webboarddetail', ['topic' => $topic, 'channels' => Channel::all(), 'user' => Auth::user()]);
 }
 public function add_topic_edit(Request $request)
 {
     $topic = Topic::find($request->input('topic_id'));
     $topic->timestamps = false;
     $topic->opening_post = $request->input('opening_post');
     $topic->op_edited_at = date('Y-m-d H:i:s');
     $topic->save();
     return redirect('comment/' . $topic->id);
 }
Beispiel #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['ip' => 'required|ip', 'content' => 'required', 'user_id' => 'required']);
     if ($comment = Comment::create($request->all())) {
         Topic::find($comment->topic_id)->increment('comments');
         return redirect()->route('bbs.topic.show', [$comment->topic_id]);
     } else {
         return redirect()->back()->withInput()->withErrors('发表回帖失败!');
     }
 }
 public function showPosts($id)
 {
     $topic = Topic::find($id);
     $posts = $topic->posts_paginated;
     $data = $posts->map(function ($item, $key) {
         $item->user = User::find($item->user_id);
         $item->user->postsCount;
         return $item;
     });
     return response()->json(['posts' => $data])->header('X-Page-Total', ceil($posts->total() / 10))->header('X-Page', $posts->currentPage());
 }
Beispiel #7
0
 public function editTopic()
 {
     Input::merge(array_map('trim', Input::all()));
     $id = (int) Input::get('id');
     $topic = Topic::find($id);
     if ($topic->exists()) {
         $topic->title = ucwords(Input::get('val'));
         $topic->save();
     }
     return 1;
 }
Beispiel #8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $topic = Topic::find($id, ['id', 'title', 'user_id', 'ip', 'content', 'created_at']);
     $topic->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $comments = Comment::withTrashed()->select('user_id', 'ip', 'content', 'deleted_at', 'created_at')->where('topic_id', $id)->orderBy('id')->paginate(100);
     $comments->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     return view('bbs.topic', ['topic' => $topic, 'comments' => $comments]);
 }
Beispiel #9
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['body' => 'required']);
     $input = Input::all();
     $input['user_id'] = Auth::user()->id;
     Reply::create($input);
     $topic = Topic::find($input['topic_id']);
     $topic->last_reply_user_id = Auth::id();
     $topic->reply_count++;
     $topic->save();
     return Redirect::route('topics.show', [Input::get('topic_id')]);
 }
Beispiel #10
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(auth()->user(), $topic)) {
         auth()->user()->favoriteTopics()->detach($topic->id);
     } else {
         auth()->user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', auth()->user(), $topic->user, $topic);
     }
     Flash::success(lang('Operation succeeded.'));
     return redirect()->route('topics.show', $topic->id);
 }
Beispiel #11
0
 public function store(Request $request)
 {
     $input = $request->all();
     $input['detail'] = delFontInline(delScriptTag($input['detail']));
     $comment = Comment::create($input);
     $content = Content::find($comment->content_id);
     $topic = Topic::find($comment->content_id);
     if ($content) {
         return redirect(route('content', $content->link));
     } elseif ($topic) {
         return redirect(route('read_topic', $topic->id));
     }
 }
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Attention::isUserAttentedTopic(Auth::user(), $topic)) {
         $message = lang('Successfully remove attention.');
         Auth::user()->attentTopics()->detach($topic->id);
     } else {
         $message = lang('Successfully_attention');
         Auth::user()->attentTopics()->attach($topic->id);
         Notification::notify('topic_attent', Auth::user(), $topic->user, $topic);
     }
     flash()->success('hello!', $message);
     return Redirect::route('topics.show', $topic->id);
 }
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Attention::isUserAttentedTopic(auth()->user(), $topic)) {
         $message = lang('Successfully remove attention.');
         auth()->user()->attentTopics()->detach($topic->id);
     } else {
         $message = lang('Successfully_attention');
         auth()->user()->attentTopics()->attach($topic->id);
         Notification::notify('topic_attent', auth()->user(), $topic->user, $topic);
     }
     Flash::success($message);
     return redirect()->route('topics.show', $topic->id);
 }
 public function edit(Request $request, $lecture_id, $subject_id, $topic_id, $knowledgeunit_id, $question_id)
 {
     $lecture = Lecture::find($lecture_id);
     $subject = Subject::find($subject_id);
     $topic = Topic::find($topic_id);
     $knowledgeunit = KnowledgeUnit::find($knowledgeunit_id);
     $question = Question::find($question_id);
     $data["nav"] = "<a href=\"" . url('/lectures/') . "\">" . $lecture->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/') . "\">" . $subject->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/') . "\">" . $topic->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/' . $topic->id . '/knowledgeunits') . "\">" . $knowledgeunit->title . "</a> <span class=\"fa fa-chevron-right\"></span> <a href=\"" . url('/lectures/' . $lecture->id . '/subjects/' . $subject->id . '/topics/' . $topic->id . '/knowledgeunits/' . $knowledgeunit->id . '/questions') . "\">" . $question->title . "</a>";
     $data["lecture_id"] = $lecture_id;
     $data["subject_id"] = $subject_id;
     $data["topic_id"] = $topic_id;
     $data["knowledgeunit_id"] = $knowledgeunit_id;
     $data["question"] = $question;
     return view('question.edit', $data);
 }
Beispiel #15
0
 public function topicAction()
 {
     $topic_id = (int) Input::get('id', 0);
     $currtopic = Topic::find($topic_id);
     if ($currtopic->exists()) {
         $menu_id = $currtopic->menu_id;
         $topicarr = Menu::find($menu_id)->topics()->orderBy('level', 'ASC')->orderBy('title', 'ASC')->get()->toArray();
         $topics = $this->clubarr($topicarr);
         $childtopics = $this->findTopics($topics, $topic_id);
         $allmenus = Menu::orderBy('level', 'ASC')->orderBy('title', 'ASC')->get()->toArray();
         $menus = $this->clubarr($allmenus);
         $articles = Menu::find($menu_id)->articles()->join('article_contents', 'article_contents.article_id', '=', 'articles.id')->whereIn('articles.topic_id', $childtopics)->get(['articles.*', 'article_contents.title'])->toArray();
         $viewarr = array('articles' => $articles, 'menus' => $menus, 'menuid' => $menu_id, 'topics' => $topics, 'topicid' => $topic_id);
         \View::share('pagetitle', $currtopic->title);
         return view('civil.menulist')->with($viewarr);
     }
 }
Beispiel #16
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['topic_id' => 'required|integer', 'content' => 'required']);
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->errors()], 400);
     }
     $topic = Topic::find($request->topic_id);
     // use exception instead later
     if ($topic) {
         $post = new Post();
         $post->content = $request->content;
         $post->user()->associate($this->user);
         $post->topic()->associate($topic);
         $post->save();
     }
     return response()->json(['post' => $post], 201);
 }
Beispiel #17
0
 public function create(CreatorListener $observer, $data)
 {
     $data['user_id'] = auth()->id();
     $data['body'] = $this->mentionParser->parse($data['body']);
     $markdown = app('markdown');
     $data['body_original'] = $data['body'];
     $data['body'] = $markdown->convertMarkdownToHtml($data['body']);
     $reply = Reply::create($data);
     if (!$reply) {
         return $observer->creatorFailed($reply->getErrors());
     }
     // Add the reply user
     $topic = Topic::find($data['topic_id']);
     $topic->last_reply_user_id = auth()->id();
     $topic->reply_count++;
     $topic->updated_at = Carbon::now();
     $topic->save();
     auth()->user()->increment('reply_count', 1);
     // TODO
     //App::make('Phphub\Notification\Notifier')->newReplyNotify(Auth::user(), $this->mentionParser, $topic, $reply);
     //Robot::notify($data['body_original'], 'Reply', $topic, Auth::user());
     return $observer->creatorSucceed($reply);
 }
 public function create(CreatorListener $observer, $data)
 {
     $data['user_id'] = Auth::id();
     $data['body'] = $this->mentionParser->parse($data['body']);
     $markdown = new Markdown();
     $data['body_original'] = $data['body'];
     $data['body'] = $markdown->convertMarkdownToHtml($data['body']);
     // Validation
     $this->form->validate($data);
     $reply = Reply::create($data);
     if (!$reply) {
         return $observer->creatorFailed($reply->getErrors());
     }
     // Add the reply user
     $topic = Topic::find($data['topic_id']);
     $topic->last_reply_user_id = Auth::id();
     $topic->reply_count++;
     $topic->updated_at = Carbon::now()->toDateTimeString();
     $topic->save();
     Auth::user()->increment('reply_count', 1);
     App::make('App\\good\\Notification\\Notifier')->newReplyNotify(Auth::user(), $this->mentionParser, $topic, $reply);
     Robot::notify($data['body_original'], 'Reply', $topic, Auth::user());
     return $observer->creatorSucceed($reply);
 }
Beispiel #19
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $topic = Topic::find((int) $id);
     $topic->update($request->all());
     return redirect('/forum/topic');
 }
 public function show($id)
 {
     $contents = Topic::find($id);
     return view('posts.show')->with('contents', $contents);
 }
Beispiel #21
0
 /**
  * Show the 'edit topic' view
  *
  * @param \Illuminate\Http\Request $id
  * @return \Illuminate\Request
  */
 public function edit($id)
 {
     $topic = Topic::find($id);
     return view('topics.update', compact('topic'));
 }
 public function downvote($id)
 {
     $topic = Topic::find($id);
     app('App\\good\\Vote\\Voter')->topicDownVote($topic);
     return Redirect::route('topics.show', $topic->id);
 }
Beispiel #23
0
 /**
  * Display a listing of the resource.
  *
  * @param integer $topic
  * @return Response
  */
 public function index($id)
 {
     $topic = Topic::find((int) $id);
     return view('debate.index', compact('topic'));
 }
 public function showByTopicId($topic_id)
 {
     $subtopic = Topic::find($topic_id)->subtopics;
     $topic = Topic::find($topic_id)->toArray();
     return response()->json(['error' => false, 'topic_name' => $topic['name'], 'sub_topic' => $subtopic->toArray()]);
 }
 /**
  * Toggle lock topic
  *
  * @param  Request  $request
  * @param  Int      $id
  * @return Response
  */
 public function lock(Request $request, $id)
 {
     $topic = App\Topic::find($id);
     if (empty($topic)) {
         return view('topic.notFound');
     }
     if (!$topic->canEdit()) {
         return redirect()->action('TopicController@show', ['id' => $topic->id]);
     }
     $topic->toggleLock();
     $topic->save();
     return redirect()->action('TopicController@show', ['id' => $topic->id]);
 }
Beispiel #26
0
 public function destroy(Request $request, $lecture_id, $subject_id, $topic_id)
 {
     $topic = Topic::find($topic_id);
     $topic->delete();
     return redirect('/lectures/' . $lecture_id . '/subjects/' . $subject_id . '/topics');
 }
Beispiel #27
0
 public function downvote($id)
 {
     $topic = Topic::find($id);
     app('App\\Services\\Voter')->topicDownVote($topic);
     return redirect()->route('topics.show', $topic->id);
 }
Beispiel #28
0
 /**
  * Show the topic.
  *
  * @return Response
  */
 public function getTopic($id)
 {
     $topic = Topic::find($id);
     $tags = $topic->tags()->get();
     if (\Session::has('flashTag') && $tags->contains(\Session::get('flashTag'))) {
         \Session::reflash('flashTag');
         $mainTag = \Session::get('flashTag');
     } else {
         $mainTag = $tags->first();
     }
     $posts = $topic->posts()->with(['user', 'likeCounter'])->get();
     $firstPost = $posts->shift();
     return view('forum.topic')->with(['topic' => $topic, 'tags' => $tags, 'mainTag' => $mainTag, 'firstPost' => $firstPost, 'posts' => $posts]);
 }
Beispiel #29
0
 /**
  * Update content
  *
  * @param  \Illuminate\Http\Request  $request
  */
 public function update(Request $request)
 {
     $data = $request->data;
     $topic = Topic::find($data['topic_id']);
     //Images
     if (!empty($data['images'])) {
         $topicImages = new TopicImages();
         //Clean all the existing images
         $topicImages->purgeImages($data['topic_uuid']);
         $num_img = 0;
         //Insert images in another table
         foreach ($data['images'] as $image) {
             $img_data[$num_img] = array('topic_uuid' => $data['topic_uuid'], 'user_uuid' => Auth::user()->uuid, 'filename' => $image, 'created_at' => date("Y-m-d H:i:s"));
             $num_img++;
         }
         TopicImages::insert($img_data);
     }
     $topic->is_edited = true;
     $topic->body = preg_replace('/(<[^>]+) style=".*?"/i', '$1', clean(trim($data['body'])));
     $topic->text = $data['text'];
     $topic->num_img = $num_img;
     $topic->save();
 }
Beispiel #30
0
 private function vote($topicId, $value)
 {
     if ($topicId) {
         $topic = Topic::find($topicId);
         $topic->vote = $topic->vote + 1;
         $topic->save();
         $vote = new Vote();
         $vote->topic_id = $topicId;
         $vote->voter_id = $this->user->id;
         $vote->value = $value;
         $vote->save();
         return response()->json($vote, 200);
     } else {
         return response()->json(['error' => "topicId not found!"], 404);
     }
 }