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 ;
2012-12-10 14:07:13 +00:00
#die("x:".$size);
2012-08-20 13:52:35 +00:00
//read all recent tasks of user
2012-05-31 13:15:36 +00:00
//make distinct achievement list
2013-02-15 13:51:41 +00:00
$res = $DBc -> sqlQuery ( " SELECT DISTINCT apt_date,aa_id,ach.*,(SELECT aal_name FROM ach_achievement_lang WHERE aal_lang=' " . $_USER -> getLang () . " ' AND aal_achievement=ach.aa_id) as aal_name, (SELECT aal_template FROM ach_achievement_lang WHERE aal_lang=' " . $_USER -> getLang () . " ' AND aal_achievement=ach.aa_id) as aal_template FROM ach_achievement as ach,ach_task,ach_player_task WHERE at_achievement=aa_id AND ach.aa_dev='0' AND apt_player=' " . $_USER -> getID () . " ' AND apt_task=at_id ORDER by apt_date DESC LIMIT 0, " . $size );
2012-12-10 14:07:13 +00:00
#echo var_export($res,true);
2012-05-31 13:15:36 +00:00
$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-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
2012-08-20 13:52:35 +00:00
//now we have to find the # of tasks for each main menu entry
2012-05-31 13:15:36 +00:00
//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 ()) {
$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-08-20 13:52:35 +00:00
2012-06-25 13:03:14 +00:00
$res = $this -> sumStats ( $curr );
2012-08-20 13:52:35 +00:00
$this -> stats [] = array ( $curr -> getName (), $res [ 0 ], $res [ 1 ], $res [ 2 ]);
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 ;
2012-08-20 13:52:35 +00:00
$hero = false ;
2012-05-31 13:15:36 +00:00
//read for current ID
//sum
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(at_id) as anz FROM ach_task,ach_achievement,ach_player_task WHERE aa_category=' " . $node -> getID () . " ' AND at_achievement=aa_id AND apt_player=' " . $_USER -> getID () . " ' AND apt_task=at_id " );
2012-05-31 13:15:36 +00:00
$done += $res [ 0 ][ " anz " ];
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT count(at_id) as anz FROM ach_task,ach_achievement WHERE aa_category=' " . $node -> getID () . " ' AND at_achievement=aa_id AND aa_dev='0' AND at_dev='0' " );
2012-05-31 13:15:36 +00:00
$total += $res [ 0 ][ " anz " ];
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT ac_heroic FROM ach_category WHERE ac_id=' " . $node -> getID () . " ' AND ac_dev='0' " );
if ( $res [ 0 ][ " ac_heroic " ] == 1 ) {
$hero = true ;
}
2012-05-31 13:15:36 +00:00
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 ];
2012-08-20 13:52:35 +00:00
$hero = ( $hero == true || $res [ 2 ] == true );
2012-05-31 13:15:36 +00:00
}
2012-08-20 13:52:35 +00:00
return array ( $done , $total , $hero );
2012-05-31 13:15:36 +00:00
}
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-08-20 13:52:35 +00:00
2013-02-15 13:51:41 +00:00
function getCurrentRace () {
return " r_matis " ;
}
2012-08-20 13:52:35 +00:00
function isHeroic () {
return false ;
}
2012-12-10 14:07:13 +00:00
function isContest () {
return false ;
}
2013-02-15 13:51:41 +00:00
function hasTieRace_open ()
{
return false ;
}
function hasTieAlign_open ()
{
return false ;
}
function hasTieRace_done ()
{
return false ;
}
function hasTieAlign_done ()
{
return false ;
}
function hasTieRaceDev ()
{
return false ;
}
function hasTieAlignDev ()
{
return false ;
}
function isTiedRace_open ( $r )
{
return true ;
}
function isTiedAlign_open ( $cult , $civ )
{
return true ;
}
function isTiedRace_done ( $r )
{
return true ;
}
function isTiedAlign_done ( $cult , $civ )
{
return true ;
}
2012-05-31 13:15:36 +00:00
}
?>