コード例 #1
0
ファイル: Forum.php プロジェクト: ameliaikeda/osu-web
 public function allSubforums($forum_ids = null, $new_forum_ids = null)
 {
     if ($forum_ids === null) {
         $forum_ids = $new_forum_ids = [$this->forum_id];
     }
     $new_forum_ids = model_pluck(static::whereIn('parent_id', $new_forum_ids), 'forum_id');
     $new_forum_ids = array_map('intval', $new_forum_ids);
     $forum_ids = array_merge($forum_ids, $new_forum_ids);
     if (count($new_forum_ids) === 0) {
         return $forum_ids;
     } else {
         return $this->allSubforums($forum_ids, $new_forum_ids);
     }
 }
コード例 #2
0
ファイル: PollOption.php プロジェクト: ppy/osu-web
 public static function summary($topic, $user)
 {
     $summary = ['options' => [], 'total' => 0, 'user_votes' => 0];
     if ($topic->poll()->exists()) {
         $userVotes = [];
         if ($user !== null) {
             $userVotes = model_pluck($topic->pollVotes()->where('vote_user_id', $user->getKey()), 'poll_option_id');
         }
         foreach ($topic->pollOptions as $poll) {
             $votedByUser = in_array($poll->poll_option_id, $userVotes, true);
             $summary['options'][$poll->poll_option_id] = ['textHTML' => $poll->optionTextHTML(), 'total' => $poll->poll_option_total, 'voted_by_user' => $votedByUser];
             $summary['total'] += $poll->poll_option_total;
             $summary['user_votes'] += $votedByUser ? 1 : 0;
         }
     }
     return $summary;
 }
コード例 #3
0
ファイル: NotifyEmail.php プロジェクト: ppy/osu-web
 public function notifyReply($event)
 {
     $topic = $event->topic->fresh();
     $userIds = model_pluck(TopicWatch::where(['topic_id' => $topic->topic_id, 'notify_status' => false]), 'user_id');
     foreach (User::whereIn('user_id', $userIds)->get() as $user) {
         if (!present($user->user_email)) {
             continue;
         }
         if ($user->user_id === $topic->last_poster_id) {
             continue;
         }
         if (!priv_check_user($user, 'ForumTopicWatchAdd', $topic)->can()) {
             continue;
         }
         Mail::queue(['text' => i18n_view('emails.forum.new_reply')], compact('topic', 'user'), function ($message) use($topic, $user) {
             $message->to($user->user_email);
             $message->subject(trans('forum.email.new_reply', ['title' => $topic->topic_title]));
         });
         TopicWatch::where(['topic_id' => $topic->topic_id, 'user_id' => $user->user_id])->update(['notify_status' => true]);
     }
 }
コード例 #4
0
ファイル: User.php プロジェクト: ppy/osu-web
 public function groupIds()
 {
     if ($this->groupIds === null) {
         $this->groupIds = model_pluck($this->userGroups(), 'group_id');
     }
     return $this->groupIds;
 }
コード例 #5
0
ファイル: Authorize.php プロジェクト: ameliaikeda/osu-web
 public function scopeRoleAcl($query, $groupIds, $authOptionId)
 {
     $roleIds = model_pluck(AuthRole::where(['auth_setting' => 1, 'auth_option_id' => $authOptionId]), 'role_id');
     return $query->where(['auth_setting' => 0])->whereIn('auth_role_id', $roleIds)->whereIn('group_id', $groupIds);
 }
コード例 #6
0
ファイル: Beatmapset.php プロジェクト: ameliaikeda/osu-web
 public static function searchES(array $params = [])
 {
     extract($params);
     $count = config('osu.beatmaps.max', 50);
     $offset = max(0, $page - 1) * $count;
     $current_user = Auth::user();
     $searchParams['index'] = config('osu.elasticsearch.index');
     $searchParams['type'] = 'beatmaps';
     $searchParams['size'] = $count;
     $searchParams['from'] = $offset;
     $searchParams['body']['sort'] = [$sort_field => ['order' => $sort_order]];
     $searchParams['fields'] = ['id'];
     $matchParams = [];
     $shouldParams = [];
     if (presence($genre) !== null) {
         $matchParams[] = ['match' => ['genre_id' => (int) $genre]];
     }
     if (presence($language) !== null) {
         $matchParams[] = ['match' => ['language_id' => (int) $language]];
     }
     if (is_array($extra) && !empty($extra)) {
         foreach ($extra as $val) {
             switch ($val) {
                 case 0:
                     // video
                     $matchParams[] = ['match' => ['video' => 1]];
                     break;
                 case 1:
                     // storyboard
                     $matchParams[] = ['match' => ['storyboard' => 1]];
                     break;
             }
         }
     }
     if (presence($query) !== null) {
         $matchParams[] = ['query_string' => ['query' => $query]];
     }
     if (!empty($rank)) {
         $klass = presence($mode) !== null ? Score\Best\Model::getClass(intval($mode)) : Score\Best\Combined::class;
         $scores = model_pluck($klass::forUser($current_user)->whereIn('rank', $rank), 'beatmapset_id');
         $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $scores]];
     }
     // TODO: This logic probably shouldn't be at the model level... maybe?
     if (presence($status) !== null) {
         switch ((int) $status) {
             case 0:
                 // Ranked & Approved
                 $shouldParams[] = [['match' => ['approved' => self::STATES['ranked']]], ['match' => ['approved' => self::STATES['approved']]]];
                 break;
             case 1:
                 // Approved
                 $matchParams[] = ['match' => ['approved' => self::STATES['approved']]];
                 break;
             case 2:
                 // Favourites
                 $favs = model_pluck($current_user->favouriteBeatmapsets(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $favs]];
                 break;
             case 3:
                 // Mod Requests
                 $maps = model_pluck(ModQueue::select(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $maps]];
                 $matchParams[] = ['match' => ['approved' => self::STATES['pending']]];
                 break;
             case 4:
                 // Pending
                 $shouldParams[] = [['match' => ['approved' => self::STATES['wip']]], ['match' => ['approved' => self::STATES['pending']]]];
                 break;
             case 5:
                 // Graveyard
                 $matchParams[] = ['match' => ['approved' => self::STATES['graveyard']]];
                 break;
             case 6:
                 // My Maps
                 $maps = model_pluck($current_user->beatmapsets(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $maps]];
                 break;
             case 7:
                 // Explicit Any
                 break;
             default:
                 // null, etc
                 break;
         }
     } else {
         $matchParams[] = ['range' => ['approved' => ['gte' => self::STATES['pending']]]];
     }
     if (presence($mode) !== null) {
         $matchParams[] = ['match' => ['playmode' => (int) $mode]];
     }
     if (!empty($matchParams)) {
         $searchParams['body']['query']['bool']['must'] = $matchParams;
     }
     if (!empty($shouldParams)) {
         $searchParams['body']['query']['bool']['should'] = $shouldParams;
         $searchParams['body']['query']['bool']['minimum_should_match'] = 1;
     }
     try {
         $results = Es::search($searchParams);
         $beatmap_ids = array_map(function ($e) {
             return $e['_id'];
         }, $results['hits']['hits']);
     } catch (\Exception $e) {
         $beatmap_ids = [];
     }
     return $beatmap_ids;
 }
コード例 #7
0
ファイル: Topic.php プロジェクト: ppy/osu-web
 public function scopeWatchedByUser($query, $user)
 {
     return $query->with('forum')->whereIn('topic_id', model_pluck(TopicWatch::where('user_id', $user->user_id), 'topic_id'))->orderBy('topic_last_post_time', 'DESC');
 }
コード例 #8
0
ファイル: Model.php プロジェクト: ppy/osu-web
 public function scopeFriendsOf($query, $user)
 {
     $userIds = model_pluck($user->friends(), 'zebra_id');
     $userIds[] = $user->user_id;
     return $query->whereIn('user_id', $userIds);
 }
コード例 #9
0
ファイル: Model.php プロジェクト: ameliaikeda/osu-web
 public function scopeFriendsOf($query, $user)
 {
     return $query->whereIn('user_id', model_pluck($user->friends(), 'zebra_id'));
 }