// we have everything we need for this challenge to be opened :)
// we have everything we need for this challenge to be opened :)
@ -356,6 +356,11 @@ function getChallenge($challenge_id, $buffer = TRUE) {
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
}
}
function getResult($challenge_id) {
// clan_challenge_participants
}
function getOpenChallengeRequests($clanid) {
function getOpenChallengeRequests($clanid) {
$array = array();
$array = array();
if(isClanLocked($clanid)) {
if(isClanLocked($clanid)) {
@ -414,6 +419,24 @@ function getActiveChallengeIDs($clanid) {
return $array;
return $array;
}
}
/**
* Returns the ChallengeIDs that are finished but not yet processed by the cronjob!!
* @param int $clanid
* @return array an array containing the ids of the clan_challenges
*/
function getAwatingChallengeIDs() {
// before doing anything check if we are locked
$array = array();
$sql = 'SELECT distinct(cc.clan_challenge_id) FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE elo_change is null AND calculated = TRUE AND enddate <now()';
// echo $sql . '<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
// returns the last challenge ids (beginning with the latest to the first)
// returns the last challenge ids (beginning with the latest to the first)
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
@ -432,7 +455,7 @@ function getHistoricalChallengeIDs($clanid, $limit = NULL) {
function getParticipatingClanIDs($clan_challenge_id) {
function getParticipatingClanIDs($clan_challenge_id) {
$array = array();
$array = array();
$sql = 'SELECT clan_id FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id;
$sql = 'SELECT clan_id FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id . ' ORDER BY id';
$qry = mysql_query($sql);
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
$array[] = $row[0];
@ -441,6 +464,12 @@ function getParticipatingClanIDs($clan_challenge_id) {
return $array;
return $array;
}
}
function getParticipatingClanData($clan_challenge_id, $clan_id) {
$sql = 'SELECT * FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id;
$qry = mysql_query($sql);
return mysql_fetch_assoc($qry);
}
function isCharBusyWithClanfighting($char_id) {
function isCharBusyWithClanfighting($char_id) {
$sql = 'SELECT count(*) as anzahl FROM clan_challenge_participants ccp INNER JOIN clan_challenges cc on ccp.clan_challenge_id = cc.clan_challenge_id WHERE cc.calculated = FALSE AND char_id = ' .$char_id;
$sql = 'SELECT count(*) as anzahl FROM clan_challenge_participants ccp INNER JOIN clan_challenges cc on ccp.clan_challenge_id = cc.clan_challenge_id WHERE cc.calculated = FALSE AND char_id = ' .$char_id;
$row = mysql_fetch_row(mysql_query($sql));
$row = mysql_fetch_row(mysql_query($sql));
@ -498,7 +527,6 @@ function isClanLocked($clanid) {
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>';
// echo $sql.'<br>';
mysql_query($sql);
mysql_query($sql);
// FIXME: We were not locked but now we are! -> deactivate all outstanding clan_challenge_requests
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE (clan_challenged = '.$clanid.' OR clan_requester = '.$clanid);
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE (clan_challenged = '.$clanid.' OR clan_requester = '.$clanid);
mysql_query('DELETE FROM clan_challenges WHERE calculated = FALSE AND clan_challenge_id IN (SELECT clan_challenge_id from clan_challenge_clans WHERE clan_id = '.$clanid.')');
mysql_query('DELETE FROM clan_challenges WHERE calculated = FALSE AND clan_challenge_id IN (SELECT clan_challenge_id from clan_challenge_clans WHERE clan_id = '.$clanid.')');