Skip to content

Instantly share code, notes, and snippets.

@dgalarza
Created September 7, 2010 18:52
Show Gist options
  • Save dgalarza/568839 to your computer and use it in GitHub Desktop.
Save dgalarza/568839 to your computer and use it in GitHub Desktop.
function fetchGuildDkp ($filter = NULL) {
$filter = $this->db->escape_str($filter);
$guild = 'SELECT char_name,char_class,crucApplications.user_id, attendance,sum(transaction_value)AS AvailDkp,round((count(DISTINCT dkp_raids.raid_id)/(SELECT count(raid_id) FROM dkp_raids WHERE raid_date >= join_date)*100))AS RaidAttend,round((count(DISTINCT dkp_raids.raid_id)/(SELECT count(raid_id) FROM dkp_raids)*100))AS OverallAttend, PastMonth.MonthAttend
FROM crucApplications
LEFT JOIN dkp_naxx_attend ON crucApplications.user_id = dkp_naxx_attend.user_id
LEFT JOIN dkp_transactions ON crucApplications.user_id = dkp_transactions.user_id
LEFT JOIN dkp_events ON dkp_transactions.event_id = dkp_events.event_id
LEFT JOIN dkp_raids ON dkp_events.raid_id = dkp_raids.raid_id
LEFT JOIN(
SELECT crucApplications.user_id, round((count(DISTINCT dkp_raids.raid_id)/(SELECT count(raid_id) FROM dkp_raids WHERE raid_date >= DATE_SUB(curdate(), INTERVAL 1 MONTH) AND raid_date >= join_date)*100))AS MonthAttend
FROM crucApplications
LEFT JOIN dkp_transactions ON crucApplications.user_id = dkp_transactions.user_id
INNER JOIN dkp_events ON dkp_transactions.event_id = dkp_events.event_id
INNER JOIN dkp_raids ON dkp_events.raid_id = dkp_raids.raid_id
INNER JOIN cruc_chars ON dkp_transactions.char_id = cruc_chars.char_id
WHERE status=1
AND (raid_date >= DATE_SUB(curdate(), INTERVAL 1 MONTH))
GROUP BY crucApplications.user_id ORDER BY char_name
)PastMonth ON crucApplications.user_id = PastMonth.user_id
INNER JOIN (
SELECT char_name,char_class, user_id FROM cruc_chars WHERE char_rank = 1
)cName ON crucApplications.user_id = cName.user_id
WHERE crucApplications.status=1
AND transaction_status = 1 ';
/*
* Build Filter if we're using one
*/
if($filter != NULL){
$tokens = array (
'CONQUEROR',
'PROTECTOR',
'VANQUISHER'
);
$tokenList = array(
'CONQUEROR' => '"Paladin", "Priest", "Warlock"',
'PROTECTOR' => '"Warrior", "Hunter", "Shaman"',
'VANQUISHER' => '"Rogue", "Death Knight", "Mage", "Druid"'
);
//Check if we're working with a token
if( in_array($filter, $tokens)) {
$filter = $tokenList[$filter];
}else{
$filter = '"' . $filter . '"';
}
$guild .= 'AND char_class IN(' . $filter . ')';
}
$guild .= 'GROUP BY crucApplications.user_id ORDER BY char_name';
$query = $this->db->query($guild);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment