2012-05-31 13:15:36 +00:00
< ? php
2012-06-03 21:03:33 +00:00
class AchCategory extends AchList implements Tieable {
2012-06-25 13:03:14 +00:00
protected $ties_cult ;
protected $ties_civ ;
2012-07-08 16:11:25 +00:00
protected $ties_race ;
protected $ties_race_dev ;
2012-06-25 13:03:14 +00:00
protected $ties_cult_dev ;
protected $ties_civ_dev ;
protected $cult ;
protected $civ ;
2012-08-20 13:52:35 +00:00
protected $heroic ;
2012-05-31 13:15:36 +00:00
2012-07-08 16:11:25 +00:00
function AchCategory ( $id , $race = null , $cult = null , $civ = null ) {
2012-05-31 13:15:36 +00:00
global $DBc , $_USER ;
2012-07-08 16:11:25 +00:00
parent :: __construct ();
2012-07-09 17:10:44 +00:00
$civ = $DBc -> sqlEscape ( $civ );
$cult = $DBc -> sqlEscape ( $cult );
$race = $DBc -> sqlEscape ( $race );
2012-07-08 16:11:25 +00:00
if ( $race == null ) {
$race = $_USER -> getRace ();
}
2012-07-02 16:55:13 +00:00
2012-06-03 13:04:04 +00:00
if ( $cult == null ) {
$cult = $_USER -> getCult ();
}
if ( $civ == null ) {
$civ = $_USER -> getCiv ();
}
$this -> cult = $cult ;
$this -> civ = $civ ;
2012-07-09 17:10:44 +00:00
$this -> id = $DBc -> sqlEscape ( $id );
2012-06-03 13:04:04 +00:00
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_achievement LEFT JOIN (ach_achievement_lang) ON (aal_lang=' " . $_USER -> getLang () . " ' AND aal_achievement=aa_id) WHERE aa_category=' " . $this -> id . " ' AND (aa_tie_race IS NULL OR aa_tie_race LIKE ' " . $race . " ') AND (aa_tie_cult IS NULL OR aa_tie_cult LIKE ' " . $cult . " ') AND (aa_tie_civ IS NULL OR aa_tie_civ LIKE ' " . $civ . " ') ORDER by aa_sticky DESC, aal_name ASC " );
2012-05-31 13:15:36 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-06-21 18:55:52 +00:00
$tmp = $this -> makeChild ( $res [ $i ]);
2012-06-25 13:03:14 +00:00
2012-05-31 13:15:36 +00:00
if ( $tmp -> hasOpen ()) {
2012-07-08 16:11:25 +00:00
$this -> addOpen ( $tmp ); #AchList::addOpen()
2012-05-31 13:15:36 +00:00
}
if ( $tmp -> hasDone ()) {
2012-07-08 16:11:25 +00:00
$this -> addDone ( $tmp ); #AchList::addDone()
2012-05-31 13:15:36 +00:00
}
}
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT ac_heroic FROM ach_category WHERE ac_id=' " . $this -> id . " ' " );
$this -> heroic = $res [ 0 ][ 'ac_heroic' ];
2012-07-08 16:11:25 +00:00
//load counts for tie determination
2012-06-14 09:23:52 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_cult IS NOT NULL AND aa_category=' " . $this -> id . " ' AND aa_dev='0' " );
2012-05-31 13:15:36 +00:00
$this -> ties_cult = $res [ 0 ][ 'anz' ];
2012-06-14 09:23:52 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_civ IS NOT NULL AND aa_category=' " . $this -> id . " ' AND aa_dev='0' " );
2012-05-31 13:15:36 +00:00
$this -> ties_civ = $res [ 0 ][ 'anz' ];
2012-06-14 09:23:52 +00:00
2012-07-08 16:11:25 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_race IS NOT NULL AND aa_category=' " . $this -> id . " ' AND aa_dev='0' " );
$this -> ties_race = $res [ 0 ][ 'anz' ];
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_race IS NOT NULL AND aa_category=' " . $this -> id . " ' " );
$this -> ties_race_dev = $res [ 0 ][ 'anz' ];
2012-06-14 09:23:52 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_cult IS NOT NULL AND aa_category=' " . $this -> id . " ' " );
$this -> ties_cult_dev = $res [ 0 ][ 'anz' ];
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_civ IS NOT NULL AND aa_category=' " . $this -> id . " ' " );
$this -> ties_civ_dev = $res [ 0 ][ 'anz' ];
2012-05-31 13:15:36 +00:00
}
2012-07-08 16:11:25 +00:00
#@override Parentum::makeChild()
2012-06-25 13:03:14 +00:00
protected function makeChild ( $a ) {
return new AchAchievement ( $a , $this );
2012-06-21 18:55:52 +00:00
}
2012-05-31 13:15:36 +00:00
function isTiedCult () {
return ( $this -> ties_cult > 0 );
}
function isTiedCiv () {
return ( $this -> ties_civ > 0 );
}
2012-06-03 13:04:04 +00:00
2012-06-14 09:23:52 +00:00
function isTiedCultDev () {
return ( $this -> ties_cult_dev > 0 );
}
function isTiedCivDev () {
return ( $this -> ties_civ_dev > 0 );
}
2012-06-03 13:04:04 +00:00
function getCurrentCiv () {
return $this -> civ ;
}
function getCurrentCult () {
return $this -> cult ;
}
2012-08-20 13:52:35 +00:00
function isHeroic () {
return ( $this -> heroic == 1 );
}
2012-05-31 13:15:36 +00:00
}
?>