Inheritance: extends Illuminate\Database\Eloquent\Model
 public function show($id)
 {
     $forum = Forum::with("subForums")->findOrFail($id);
     $this->authorizeView($forum);
     $pinnedTopics = $forum->topics()->pinned()->orderBy("topic_type", "desc")->recent()->get();
     $topics = $forum->topics()->normal()->recent()->paginate(15);
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $pinnedTopics, $topics);
     return view("forum.forums.show", compact("forum", "topics", "pinnedTopics", "topicReadStatus"));
 }
Exemple #2
0
 public function show($id)
 {
     $forum = Forum::with('subForums')->findOrFail($id);
     $this->authorizeView($forum);
     $pinnedTopics = $forum->topics()->pinned()->orderBy('topic_type', 'desc')->recent()->get();
     $topics = $forum->topics()->normal()->recent()->paginate(15);
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $pinnedTopics, $topics);
     return view('forum.forums.show', compact('forum', 'topics', 'pinnedTopics', 'topicReadStatus'));
 }
 public function show($id)
 {
     $forum = Forum::with('subForums')->findOrFail($id);
     $sort = explode('_', Request::input('sort'));
     $withReplies = Request::input('with_replies', '');
     priv_check('ForumView', $forum)->ensureCan();
     $cover = json_item($forum->cover()->firstOrNew([]), new ForumCoverTransformer());
     $pinnedTopics = $forum->topics()->pinned()->orderBy('topic_type', 'desc')->recent()->get();
     $topics = $forum->topics()->normal()->recent(compact('sort', 'withReplies'))->paginate(15);
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $pinnedTopics, $topics);
     return view('forum.forums.show', compact('forum', 'topics', 'pinnedTopics', 'topicReadStatus', 'cover'));
 }
Exemple #4
0
 public static function lastUnreadByUser($topic, $user)
 {
     if ($user === null) {
         return;
     }
     $startTime = TopicTrack::where('topic_id', $topic->topic_id)->where('user_id', $user->user_id)->value('mark_time');
     if ($startTime === null) {
         return;
     }
     $unreadPostId = $topic->posts()->where('post_time', '>=', $startTime->getTimestamp())->value('post_id');
     if ($unreadPostId === null) {
         return $topic->posts()->orderBy('post_id', 'desc')->value('post_id');
     }
     return $unreadPostId;
 }
Exemple #5
0
 public static function lastUnreadByUser($topic, $user)
 {
     if ($user === null) {
         return null;
     }
     $startTime = TopicTrack::where("topic_id", $topic->topic_id)->where("user_id", $user->user_id)->value("mark_time");
     if ($startTime === null) {
         return null;
     }
     $unreadPostId = $topic->posts()->where("post_time", ">=", $startTime->getTimestamp())->value("post_id");
     if ($unreadPostId === null) {
         return $topic->posts()->orderBy("post_id", "desc")->value("post_id");
     }
     return $unreadPostId;
 }
 public function watch($id)
 {
     $topic = Topic::findOrFail($id);
     $state = get_bool(Request::input('watch'));
     $privName = 'ForumTopicWatch' . ($state ? 'Add' : 'Remove');
     $type = 'watch';
     priv_check($privName, $topic)->ensureCan();
     TopicWatch::toggle($topic, Auth::user(), $state);
     switch (Request::input('page')) {
         case 'manage':
             $topics = Topic::watchedByUser(Auth::user())->get();
             $topicReadStatus = TopicTrack::readStatus(Auth::user(), $topics);
             // there's currently only destroy action from watch index
             return js_view('forum.topic_watches.destroy', compact('topic', 'topics', 'topicReadStatus'));
         default:
             return js_view('forum.topics.replace_button', compact('topic', 'type', 'state'));
     }
 }
Exemple #7
0
 public function markRead($user, $markTime)
 {
     if ($user === null) {
         return;
     }
     $status = TopicTrack::where(['user_id' => $user->user_id, 'topic_id' => $this->topic_id]);
     if ($status->first() === null) {
         // first time seeing the topic, create tracking entry
         // and increment views count
         TopicTrack::create(['user_id' => $user->user_id, 'topic_id' => $this->topic_id, 'forum_id' => $this->forum_id, 'mark_time' => $markTime]);
         $this->increment('topic_views');
     } elseif ($status->first()->mark_time < $markTime) {
         // laravel doesn't like composite key ;_;
         // and the setMarkTimeAttribute doesn't work here
         $status->update(['mark_time' => $markTime->getTimeStamp()]);
     }
     if ($this->topic_last_view_time < $markTime) {
         $this->topic_last_view_time = $markTime;
         $this->save();
     }
 }
 public function index()
 {
     $topics = Topic::watchedByUser(Auth::user())->get();
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $topics);
     return view('forum.topic_watches.index', compact('topics', 'topicReadStatus'));
 }