Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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]);
     }
 }
Esempio n. 4
0
File: User.php Progetto: ppy/osu-web
 public function groupIds()
 {
     if ($this->groupIds === null) {
         $this->groupIds = model_pluck($this->userGroups(), 'group_id');
     }
     return $this->groupIds;
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 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');
 }
Esempio n. 8
0
 public function scopeFriendsOf($query, $user)
 {
     $userIds = model_pluck($user->friends(), 'zebra_id');
     $userIds[] = $user->user_id;
     return $query->whereIn('user_id', $userIds);
 }
Esempio n. 9
0
 public function scopeFriendsOf($query, $user)
 {
     return $query->whereIn('user_id', model_pluck($user->friends(), 'zebra_id'));
 }