Exemplo n.º 1
0
 public function show($id, $slug)
 {
     // Show a thread
     // Get the OP
     $post = Post::find($id);
     // Get the replies
     $replies = Post::where('thread_id', $id)->paginate(15);
     // Add a view to this thread
     $view = new ThreadView();
     $view->user_id = Auth::user()->id;
     $view->post_id = $id;
     $view->save();
     return view('forums.thread')->withThread($post)->withReplies($replies);
 }
Exemplo n.º 2
0
 /**
  *インデックスアクション
  */
 public function index()
 {
     //ソート状況配列初期化
     $order = array();
     $order[0] = array('thread' => 'DESC', 'amount' => 'DESC', 'user' => 'DESC');
     $order[1] = array('thread' => '▼', 'amount' => '▼', 'user' => '▼');
     //ソート要求があるか否か
     if (Input::has('sort') && Input::has('order')) {
         $threads = ThreadView::getThreadInfo(Input::get('sort'), Input::get('order'));
         $sort = Input::get('sort');
         $order[0][$sort] = Input::get('order') == 'DESC' ? 'ASC' : 'DESC';
         $order[1][$sort] = $order[0][$sort] == 'DESC' ? '▼' : '▲';
     } else {
         $threads = ThreadView::getThreadInfo();
     }
     return view('board.index')->with('threads', $threads)->with('order', $order);
 }
Exemplo n.º 3
0
 public static function getThreadInfo($sort = '', $order = '')
 {
     //ソートの種類によってデータベースアクセス方法を分岐
     switch ($sort) {
         case 'thread':
             $threads = ThreadView::select('id', 'amount', 'thread', 'user')->orderBy('created_at', $order)->get();
             break;
         case 'user':
             $threads = ThreadView::select('id', 'amount', 'thread', 'user')->orderBy($sort, $order)->get();
             break;
         case 'amount':
             $threads = ThreadView::select('id', 'amount', 'thread', 'user')->orderBy($sort, $order)->get();
             break;
         default:
             $threads = ThreadView::all();
     }
     return $threads;
 }
Exemplo n.º 4
0
 public function dashboard()
 {
     $threads = ThreadView::getThreadInfo();
     return view('dashboard.index')->with('threads', $threads);
 }
Exemplo n.º 5
0
Arquivo: Post.php Projeto: unbolt/imp
 public function getViewCountAttribute()
 {
     return ThreadView::where('post_id', $this->id)->count();
 }
Exemplo n.º 6
0
 public function index()
 {
     if (!Request::all()) {
         return view('search.index');
     }
     //バリデーションの設定
     $validation = Validator::make(['search' => Input::get('search'), 'user' => Input::get('user'), 'thread' => Input::get('thread'), 'keyword' => Input::get('keyword'), 'content' => Input::get('content')], ['search' => 'required', 'user' => 'required_with:search|accepted', 'thread' => 'required_with:search|accepted', 'keyword' => 'required_with:search|accepted', 'content' => 'required_with:search|accepted'], ['required' => '検索語句を入力してください', 'required_with' => '検索条件が設定されていません', 'accepted' => '検索フォームから検索してください']);
     //バリデーション失敗時
     if ($validation->fails()) {
         return redirect()->back()->withErrors($validation->errors());
     }
     $scope = array('keyword' => 0, 'thread' => 0, 'user' => 0, 'content' => 0);
     foreach ($scope as $key => $val) {
         $scope[$key] = Input::has($key) ? 1 : $val;
     }
     $words = Input::get('search');
     $words = trim($words);
     $words = str_replace(" ", " ", $words);
     if (stristr($words, " ")) {
         $words = explode(" ", $words);
     } else {
         $words = array($words);
     }
     //検索結果格納配列の初期化
     $result = array();
     //検索方法ごとに検索ワードを検索
     foreach ($scope as $key => $val) {
         if (!$val) {
             continue;
         }
         switch ($key) {
             case 'keyword':
                 foreach ($words as $word) {
                     $result[$key][$word] = Comment::select('thread_view.id', 'thread', 'content', 'comments.user as commentator', 'amount', 'thread_view.user')->join('thread_view', 'thread_view.id', '=', 'comments.thread_id')->where('thread', 'Like', "%{$word}%")->orWhere('content', 'Like', "%{$word}%")->orWhere('comments.user', 'Like', "%{$word}%")->groupBy('thread')->groupBy('content')->groupBy('comments.user')->get();
                     if (!isset($result[$key][$word][0])) {
                         continue;
                     }
                     //ヒット個所の強調
                     foreach ($result[$key][$word] as $row) {
                         $row['thread'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['thread']);
                         $row['commentator'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['commentator']);
                         $row['content'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['content']);
                     }
                 }
                 break;
             case 'thread':
                 foreach ($words as $word) {
                     $result[$key][$word] = ThreadView::select('id', 'thread', 'thread_view.user', 'amount')->where('thread', 'like', "%{$word}%")->groupBy('thread')->get();
                     if (!isset($result[$key][$word][0])) {
                         continue;
                     }
                     //ヒット個所の強調
                     foreach ($result[$key][$word] as $row) {
                         //ヒット個所の強調
                         $row['thread'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['thread']);
                     }
                 }
                 break;
             case 'user':
                 foreach ($words as $word) {
                     $result[$key][$word] = Comment::select('thread_view.id', 'thread', 'comments.user as commentator', 'thread_view.user', 'amount')->join('thread_view', 'thread_view.id', '=', 'comments.thread_id')->where('comments.user', 'Like', "%{$word}%")->groupBy('comments.user')->get();
                     if (!isset($result[$key][$word][0])) {
                         continue;
                     }
                     //ヒット個所の強調
                     foreach ($result[$key][$word] as $row) {
                         $row['commentator'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['commentator']);
                     }
                 }
                 break;
             case 'content':
                 foreach ($words as $word) {
                     $result[$key][$word] = Comment::select('thread_view.id', 'thread', 'content', 'thread_view.user', 'amount')->join('thread_view', 'thread_view.id', '=', 'comments.thread_id')->where('content', 'Like', "%{$word}%")->groupBy('content')->get();
                     if (!isset($result[$key][$word][0])) {
                         continue;
                     }
                     //ヒット個所の強調
                     foreach ($result[$key][$word] as $row) {
                         $row['content'] = preg_replace('/' . $word . '/', '~~~~' . $word . '####', $row['content']);
                     }
                 }
                 break;
         }
     }
     return view('search.index')->with('threads', $result);
 }