2012-05-25 09:48:56 +00:00
< ? php
class AchAchievement extends AchList {
2012-07-08 16:11:25 +00:00
use InDev ;
2012-06-25 13:03:14 +00:00
protected $parent_id ;
protected $category ;
protected $tie_race ;
protected $tie_civ ;
protected $tie_cult ;
protected $image ;
protected $name ;
protected $template ;
function AchAchievement ( $data , $parent ) {
2012-05-31 13:15:36 +00:00
global $DBc , $_USER ;
2012-07-08 16:11:25 +00:00
parent :: __construct ();
2012-06-25 13:03:14 +00:00
$this -> setParent ( $parent );
$this -> setID ( $data [ 'aa_id' ]);
$this -> parent_id = $data [ 'aa_parent' ];
2012-05-25 09:48:56 +00:00
$this -> category = $data [ 'aa_category' ];
$this -> tie_race = $data [ 'aa_tie_race' ];
$this -> tie_civ = $data [ 'aa_tie_civ' ];
$this -> tie_cult = $data [ 'aa_tie_cult' ];
$this -> image = $data [ 'aa_image' ];
$this -> name = $data [ 'aal_name' ];
2012-05-31 13:15:36 +00:00
$this -> template = $data [ 'aal_template' ];
2012-06-14 09:23:52 +00:00
$this -> dev = $data [ 'aa_dev' ];
2012-05-25 09:48:56 +00:00
2012-05-31 13:15:36 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_perk LEFT JOIN (ach_perk_lang) ON (apl_lang=' " . $_USER -> getLang () . " ' AND apl_perk=ap_id) LEFT JOIN (ach_player_perk) ON (app_perk=ap_id AND app_player=' " . $_USER -> getID () . " ') WHERE ap_achievement=' " . $this -> id . " ' AND ap_parent IS NULL " );
2012-07-08 16:11:25 +00:00
2012-05-25 09:48:56 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-06-21 20:45:27 +00:00
$tmp = $this -> makeChild ( $res [ $i ]);
2012-05-25 09:48:56 +00:00
2012-05-27 19:08:28 +00:00
if ( $tmp -> isDone ()) {
2012-06-25 13:03:14 +00:00
$this -> addDone ( $tmp );
2012-05-25 09:48:56 +00:00
}
else {
2012-06-25 13:03:14 +00:00
$this -> addOpen ( $tmp );
2012-05-27 19:08:28 +00:00
}
2012-05-25 09:48:56 +00:00
}
2012-06-21 18:55:52 +00:00
}
2012-06-25 13:03:14 +00:00
protected function makeChild ( $a ) {
return new AchPerk ( $a , $this );
2012-05-25 09:48:56 +00:00
}
2012-07-08 16:11:25 +00:00
function unlockedByParent () {
if ( $this -> parent_id != null ) {
$tmp = $this -> parent -> getChildByID ( $this -> parent_id );
return ( $tmp -> hasOpen () == false );
}
return true ;
}
2012-06-25 13:03:14 +00:00
function getParentID () {
return $this -> parent_id ;
2012-05-25 09:48:56 +00:00
}
function getTieRace () {
return $this -> tie_race ;
}
function getTieCiv () {
return $this -> tie_civ ;
}
function getTieCult () {
return $this -> tie_cult ;
}
function getImage () {
return $this -> image ;
}
function getName () {
return $this -> name ;
}
2012-05-27 19:08:28 +00:00
function getValueDone () {
2012-05-25 09:48:56 +00:00
$val = 0 ;
2012-06-25 13:03:14 +00:00
$iter = $this -> getDone ();
while ( $iter -> hasNext ()) {
2012-07-08 16:11:25 +00:00
$curr = $iter -> getNext ();
2012-06-25 13:03:14 +00:00
$val += $curr -> getValue ();
2012-05-25 09:48:56 +00:00
}
return $val ;
}
2012-05-27 19:08:28 +00:00
function getValueOpen () {
2012-07-01 18:04:01 +00:00
$iter = $this -> getOpen ();
2012-06-25 13:03:14 +00:00
if ( $iter -> hasNext ()) {
2012-07-08 16:11:25 +00:00
$curr = $iter -> getNext ();
2012-06-25 13:03:14 +00:00
return $curr -> getValue ();
}
return 0 ;
2012-05-27 19:08:28 +00:00
}
2012-05-31 13:15:36 +00:00
2012-07-01 18:04:01 +00:00
function fillTemplate ( $insert = array ()) {
2012-05-31 13:15:36 +00:00
if ( $this -> template == null ) {
return implode ( " ; " , $insert );
}
else {
$tmp = $this -> template ;
$match = array ();
preg_match_all ( '#\[([0-9]+)\]#' , $this -> template , $match );
foreach ( $match [ 0 ] as $key => $elem ) {
$tmp = str_replace ( " [ " . $match [ 1 ][ $key ] . " ] " , $insert [ $key ], $tmp );
}
return $tmp ;
}
}
2012-07-01 18:04:01 +00:00
function getTemplate () {
return $this -> template ;
}
2012-06-14 09:23:52 +00:00
2012-07-01 18:04:01 +00:00
function getCategory () {
return $this -> category ;
2012-06-14 09:23:52 +00:00
}
2012-07-01 18:04:01 +00:00
2012-05-25 09:48:56 +00:00
}
?>