コード例 #1
0
ファイル: Post.php プロジェクト: ppy/osu-web
 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;
 }
コード例 #2
0
ファイル: Post.php プロジェクト: WiiPlayer2/osu-web
 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;
 }
コード例 #3
0
ファイル: Topic.php プロジェクト: NiHikKi/osu-web
 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();
     }
 }