Example #1
0
    /**
     * updates a wow guild rank list from Battle.NET API -- except guildless
     *
     * @param array $memberdata
     * @param int $guild_id
     * @param string $region
     */
    public function WoWArmoryUpdate($memberdata, $guild_id, $region)
    {
        global $db;
        $newranks = array();
        //init the rank counts per rank
        foreach ($memberdata as $new) {
            $newranks[$new['rank']] = 0;
        }
        //count the number of members per rank
        foreach ($memberdata as $new) {
            $newranks[$new['rank']] += 1;
        }
        ksort($newranks);
        /* GET OLD RANKS */
        $sql = ' select rank_id from ' . MEMBER_RANKS_TABLE . ' WHERE
				 guild_id =  ' . (int) $guild_id . ' and rank_id < 90 order by rank_id ASC';
        $result = $db->sql_query($sql);
        $oldranks = array();
        while ($row = $db->sql_fetchrow($result)) {
            $oldranks[(int) $row['rank_id']] = 0;
        }
        $db->sql_freeresult($result);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $oldranks[(int) $row['rank_id']] += 1;
        }
        $db->sql_freeresult($result);
        // get the new ranks not yet created
        $diff = array_diff_key($newranks, $oldranks);
        foreach ($diff as $key => $count) {
            $newrank = new \bbdkp\controller\guilds\Ranks($guild_id);
            $newrank->RankName = 'Rank' . $key;
            $newrank->RankId = $key;
            $newrank->RankGuild = $guild_id;
            $newrank->RankHide = 0;
            $newrank->RankPrefix = '';
            $newrank->RankSuffix = '';
            $newrank->Makerank();
            unset($newrank);
        }
    }
Example #2
0
 /**
  * Add a guild rank
  * @param $updateguild
  */
 private function AddRank(\bbdkp\controller\guilds\Guilds $updateguild)
 {
     global $user;
     $newrank = new \bbdkp\controller\guilds\Ranks($updateguild->guildid);
     $newrank->RankName = utf8_normalize_nfc(request_var('nrankname', '', true));
     $newrank->RankId = request_var('nrankid', 0);
     $newrank->RankGuild = $updateguild->guildid;
     $newrank->RankHide = isset($_POST['nhide']) ? 1 : 0;
     $newrank->RankPrefix = utf8_normalize_nfc(request_var('nprefix', '', true));
     $newrank->RankSuffix = utf8_normalize_nfc(request_var('nsuffix', '', true));
     $newrank->Makerank();
     $success_message = $user->lang['ADMIN_RANKS_ADDED_SUCCESS'];
     trigger_error($success_message . $this->link);
 }