2012-05-31 13:15:36 +00:00
< ? php
2012-06-03 21:03:33 +00:00
class AchSummary extends AchList implements Tieable {
2012-05-31 13:15:36 +00:00
private $menu ;
private $stats ;
function AchSummary ( & $menu , $size = 10 ) {
global $DBc , $_USER ;
2012-07-08 16:11:25 +00:00
parent :: __construct ();
2012-05-31 13:15:36 +00:00
$this -> menu = $menu ;
//read all recent perks of user
//make distinct achievement list
$res = $DBc -> sqlQuery ( " SELECT DISTINCT aa_id,ach.*,(SELECT aal_name FROM ach_achievement_lang WHERE aal_lang=' " . $_USER -> getLang () . " ' AND aal_achievement=ach.aa_id) as aal_name FROM ach_achievement as ach,ach_perk,ach_player_perk WHERE ap_achievement=aa_id AND app_player=' " . $_USER -> getID () . " ' AND app_perk=ap_id ORDER by app_date DESC LIMIT 0, " . ( $size - 1 ));
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-06-25 13:03:14 +00:00
$this -> addDone ( $this -> makeChild ( $res [ $i ]));
2012-05-31 13:15:36 +00:00
}
2012-07-01 18:04:01 +00:00
#echo var_export($this->child_done,true);
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 getSummary () {
if ( ! is_array ( $this -> stats )) { // only load if needed
//now we have to find the # of perks for each main menu entry
//and also sum up how many have been completed
$this -> stats = array (); // [][name,done,total]
2012-06-25 13:03:14 +00:00
$iter = $this -> menu -> getIterator ();
while ( $iter -> hasNext ()) {
2012-07-01 18:04:01 +00:00
#echo "1";
2012-06-25 13:03:14 +00:00
$curr = $iter -> getNext ();
2012-07-01 18:04:01 +00:00
2012-06-25 13:03:14 +00:00
if ( $curr -> getID () == 0 || $curr -> inDev ()) {
2012-05-31 13:15:36 +00:00
continue ; // skip summary page
}
2012-07-01 18:04:01 +00:00
#echo $curr->getID().",";
#echo var_export($curr,true);
2012-06-25 13:03:14 +00:00
$res = $this -> sumStats ( $curr );
$this -> stats [] = array ( $curr -> getName (), $res [ 0 ], $res [ 1 ]);
2012-05-31 13:15:36 +00:00
}
}
return $this -> stats ;
}
private function sumStats ( & $node ) {
global $DBc , $_USER ;
2012-07-01 18:04:01 +00:00
#return array(0,0);
#echo ">".gettype($node)."<";
2012-05-31 13:15:36 +00:00
$done = 0 ;
$total = 0 ;
//read for current ID
//sum
$res = $DBc -> sqlQuery ( " SELECT count(ap_id) as anz FROM ach_perk,ach_achievement,ach_player_perk WHERE aa_category=' " . $node -> getID () . " ' AND ap_achievement=aa_id AND app_player=' " . $_USER -> getID () . " ' AND app_perk=ap_id " );
$done += $res [ 0 ][ " anz " ];
2012-06-14 09:23:52 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(ap_id) as anz FROM ach_perk,ach_achievement WHERE aa_category=' " . $node -> getID () . " ' AND ap_achievement=aa_id AND aa_dev='0' AND ap_dev='0' " );
2012-05-31 13:15:36 +00:00
$total += $res [ 0 ][ " anz " ];
2012-06-25 13:03:14 +00:00
$iter = $node -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
2012-07-01 18:04:01 +00:00
$res = $this -> sumStats ( $curr );
2012-05-31 13:15:36 +00:00
$done += $res [ 0 ];
$total += $res [ 1 ];
}
return array ( $done , $total );
}
2012-06-03 21:03:33 +00:00
function isTiedCult () {
return false ;
}
function isTiedCiv () {
return false ;
}
function getCurrentCiv () {
return " c_neutral " ;
}
function getCurrentCult () {
return " c_neutral " ;
}
2012-05-31 13:15:36 +00:00
}
?>