Пример #1
0
 public function get_index($threadID = '', $threadAlias = '', $page = 1)
 {
     $ajaxRequest = false;
     $thread = false;
     $numbered = false;
     if (Request::ajax()) {
         $ajaxRequest = true;
     }
     //we need to check the threadID.
     if (is_numeric($threadID)) {
         $threadLookup = Thread::where("id", '=', $threadID)->first();
         if ($threadLookup) {
             $thread = true;
             //we got it right... //we got at least ONE thread!
             if (empty($threadAlias)) {
                 return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
             } else {
                 //we dont have to do anything if we have /id/alias/ schema.
             }
         }
     }
     /*
      * In above if condition corrects if there is no alias given to URL.
      * Above also correts the URL and returns it as corrected way.
      */
     if (!$thread) {
         $threadLookup = Thread::where('title', '=', $threadID)->first();
         if ($threadLookup) {
             /*
             We got the thread by looking at its raw format. "bla bla bla".
             This is usually false. browsers dont like spaces and special characters
             So we need to put them to a true format and redirect it.
             */
             return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
         }
         $threadLookup = Thread::where('alias', '=', $threadID)->first();
         if ($threadLookup) {
             /*
             We got the thread by looking at its alias format. "bla-bla-bla".
             This is usually false. Because we also need ID
             So we need to put them to a true format and redirect it.
             */
             return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
         }
         /*
         if we are still going on with !$thread that means there is no thread! so
         do the suggestion!
         
         TODO :: Suggestion!
         */
     }
     if (Sentry::check()) {
         $tms = ThreadsMember::where('thread_id', '=', $threadID)->where('user_id', '=', Sentry::user()->id)->first();
         if ($tms == null) {
             ThreadsMember::create(array('thread_id' => $threadID, 'user_id' => Sentry::user()->id, 'read_flag' => 1));
         }
     }
     $total = Post::where('thread_id', '=', $threadID)->count();
     $Query = Post::with('author')->where('thread_id', '=', $threadID)->order_by('id', 'asc')->paginate(static::$per_page);
     print_r($threadLookup);
     $paginator = Paginator::make($Query, $total, static::$per_page);
     if ($ajaxRequest) {
         //json returns if we get ajax request
         $view = View::make('entry.entryajax');
         $view->title = $threadLookup->title;
         $view->threadinfo = $threadLookup;
         $view->posts = $Query;
         $view->paginate = $paginator;
         return $view;
     } else {
         $view = View::make('entry.entry');
         $view->title = $threadLookup->title;
         $view->threadinfo = $threadLookup;
         $view->posts = $Query;
         $view->paginate = $paginator;
         return $view;
     }
 }