public function __construct(\phpbb\cache\service $cache, \phpbb\request\request_interface $request, \phpbb\user $user)
 {
     $this->cache = $cache;
     $this->request = $request;
     $this->user = $user;
     $this->ranks = $this->cache->obtain_ranks();
 }
Exemple #2
0
 /**
  * This is a modified copy of the get_user_rank function, as found in functions_display.php
  * It has been put here so it can be called from any page, which is needed for some PBWoW
  * features. It also reduces the risk of undefined function errors.
  *
  * @param int    $user_rank     the current stored users rank id
  * @param int    $user_posts    the users number of posts
  * @param string &$rank_title   the rank title will be stored here after execution
  * @param string &$rank_img     the rank image as full img tag is stored here after execution
  * @param string &$rank_img_src the rank image source is stored here after execution
  *
  * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
  */
 public function get_user_rank_global($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
 {
     $ranks = $this->ranks;
     if (empty($ranks)) {
         $ranks = $this->ranks = $this->cache->obtain_ranks();
     }
     if (!empty($user_rank)) {
         $rank_title = isset($ranks['special'][$user_rank]['rank_title']) ? $ranks['special'][$user_rank]['rank_title'] : '';
         $rank_img = !empty($ranks['special'][$user_rank]['rank_image']) ? '<img src="' . $this->root_path . $this->config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
         $rank_img_src = !empty($ranks['special'][$user_rank]['rank_image']) ? $this->root_path . $this->config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
     } else {
         if ($user_posts !== false) {
             if (!empty($ranks['normal'])) {
                 foreach ($ranks['normal'] as $rank) {
                     if ($user_posts >= $rank['rank_min']) {
                         $rank_title = $rank['rank_title'];
                         $rank_img = !empty($rank['rank_image']) ? '<img src="' . $this->root_path . $this->config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
                         $rank_img_src = !empty($rank['rank_image']) ? $this->root_path . $this->config['ranks_path'] . '/' . $rank['rank_image'] : '';
                         break;
                     }
                 }
             }
         }
     }
 }
    /**
     * Obtain an array of users in a rank.
     *
     * @return array
     */
    protected function get_user_rank_data($rank_id)
    {
        $rank_data = $rank_users = array();
        if (($rank_data = $this->cache->get('_rank_data')) === false) {
            $ranks = $this->cache->obtain_ranks();
            $where = $this->config['userranks_ignore_bots'] ? 'WHERE user_type <> ' . USER_IGNORE . '' : '';
            $sql = 'SELECT user_id, user_colour, username, user_rank, user_posts
				FROM ' . USERS_TABLE . "\n\t\t\t\t\t{$where}\n\t\t\t\tORDER BY username_clean ASC";
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                if (!empty($row['user_rank'])) {
                    $rank_data[$row['user_id']] = $row;
                } else {
                    if ($row['user_posts'] !== false) {
                        if (!empty($ranks['normal'])) {
                            foreach ($ranks['normal'] as $rank) {
                                if ($row['user_posts'] >= $rank['rank_min']) {
                                    $row['user_rank'] = $rank['rank_id'];
                                    $rank_data[$row['user_id']] = $row;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            $this->db->sql_freeresult($result);
            // Cache this data to save processing
            $this->cache->put('_rank_data', $rank_data, $this->config['load_online_time']);
        }
        foreach ($rank_data as $user_rank) {
            if ($user_rank['user_rank'] == $rank_id) {
                $rank_users[$user_rank['user_id']] = $user_rank;
            }
        }
        return $rank_users;
    }