2012-05-25 09:48:56 +00:00
< ? php
2012-06-25 13:03:14 +00:00
class AchPerk extends Parentum {
2012-08-07 15:41:50 +00:00
#########################
# PHP 5.3 compatible
# InDev_trait replaces this in PHP 5.4
2012-07-09 17:10:44 +00:00
protected $dev ;
function inDev () {
return ( $this -> dev == 1 );
}
function getDev () {
return $this -> dev ;
}
function setInDev ( $tf ) {
if ( $tf == true ) {
$this -> setDev ( 1 );
}
else {
$this -> setDev ( 0 );
}
$this -> update ();
}
function setDev ( $d ) {
$this -> dev = $d ;
}
2012-08-07 15:41:50 +00:00
#########################
2012-05-25 09:48:56 +00:00
2012-06-25 13:03:14 +00:00
protected $achievement ;
protected $value ;
protected $name ;
protected $done ;
2012-07-01 18:04:01 +00:00
protected $template ;
protected $parent_id ;
2012-05-25 09:48:56 +00:00
2012-06-25 13:03:14 +00:00
function AchPerk ( $data , $parent ) {
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 [ 'ap_id' ]);
2012-05-25 09:48:56 +00:00
$this -> achievement = $data [ 'ap_achievement' ];
$this -> value = $data [ 'ap_value' ];
$this -> name = $data [ 'apl_name' ];
2012-05-27 19:08:28 +00:00
$this -> done = $data [ 'app_date' ];
2012-06-14 09:23:52 +00:00
$this -> dev = $data [ 'ap_dev' ];
2012-07-01 18:04:01 +00:00
$this -> template = $data [ 'apl_template' ];
$this -> parent_id = $data [ 'ap_parent' ];
2012-05-25 09:48:56 +00:00
2012-06-21 20:03:36 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_objective LEFT JOIN (ach_objective_lang) ON (aol_lang=' " . $_USER -> getLang () . " ' AND aol_objective=ao_id) LEFT JOIN (ach_player_objective) ON (apo_objective=ao_id AND apo_player=' " . $_USER -> getID () . " ') LEFT JOIN (ach_achievement) ON (aa_id=ao_metalink) WHERE ao_perk=' " . $this -> id . " ' " );
2012-05-25 09:48:56 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-06-25 13:03:14 +00:00
$this -> addChild ( $this -> makeChild ( $res [ $i ]));
2012-05-25 09:48:56 +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 AchObjective ( $a , $this );
2012-05-25 09:48:56 +00:00
}
function getAchievement () {
return $this -> achievement ;
}
function getValue () {
return $this -> value ;
}
2012-07-01 18:04:01 +00:00
function getDisplayName () {
return $this -> parent -> fillTemplate ( explode ( " ; " , $this -> name ));
}
2012-05-25 09:48:56 +00:00
function getName () {
2012-07-01 18:04:01 +00:00
return $this -> name ;
2012-05-25 09:48:56 +00:00
}
2012-05-27 19:08:28 +00:00
function objDrawable () {
2012-06-25 13:03:14 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> getDisplay () != " hidden " ) {
2012-05-27 19:08:28 +00:00
return true ;
}
}
2012-06-25 13:03:14 +00:00
2012-05-27 19:08:28 +00:00
return false ;
}
function isDone () {
return ( $this -> done > 0 );
}
function getDone () {
return $this -> done ;
}
2012-06-14 09:23:52 +00:00
2012-07-01 18:04:01 +00:00
function fillTemplate ( $insert = array ()) {
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 ;
}
}
function getTemplate () {
return $this -> template ;
}
function getParentID () {
return $this -> parent_id ;
}
2012-05-25 09:48:56 +00:00
}
?>