2012-05-25 09:48:56 +00:00
< ? php
2012-08-20 15:41:46 +00:00
/*
* The Achievement class that holds one achievement . It is able to load one an the same task an treat is as both ,
* open and done .
*/
2012-05-25 09:48:56 +00:00
class AchAchievement extends AchList {
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-06-25 13:03:14 +00:00
protected $parent_id ;
protected $category ;
2012-12-10 14:07:13 +00:00
#protected $tie_race;
#protected $tie_civ;
#protected $tie_cult;
2012-06-25 13:03:14 +00:00
protected $image ;
protected $name ;
protected $template ;
2012-08-20 13:52:35 +00:00
protected $sticky ;
2012-06-25 13:03:14 +00:00
function AchAchievement ( $data , $parent ) {
2012-12-10 14:07:13 +00:00
global $DBc , $_USER , $_CONF ;
2012-07-08 16:11:25 +00:00
parent :: __construct ();
2012-06-25 13:03:14 +00:00
2012-08-20 15:41:46 +00:00
$this -> setParent ( $parent ); // real parent node
2012-06-25 13:03:14 +00:00
$this -> setID ( $data [ 'aa_id' ]);
2012-08-20 15:41:46 +00:00
$this -> parent_id = $data [ 'aa_parent' ]; // id of parent
2012-05-25 09:48:56 +00:00
$this -> category = $data [ 'aa_category' ];
2012-12-10 14:07:13 +00:00
#$this->tie_race = $data['aa_tie_race'];
#$this->tie_civ = $data['aa_tie_civ'];
#$this->tie_cult = $data['aa_tie_cult'];
2012-05-25 09:48:56 +00:00
$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-08-20 13:52:35 +00:00
$this -> sticky = $data [ 'aa_sticky' ];
2012-05-25 09:48:56 +00:00
2012-12-10 14:07:13 +00:00
if ( $this -> name == null ) {
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_achievement_lang WHERE aal_lang=' " . $_CONF [ 'default_lang' ] . " ' AND aal_achievement=' " . $this -> id . " ' " );
$this -> name = $res [ 0 ][ 'aal_name' ];
$this -> template = $res [ 0 ][ 'aal_template' ];
}
2012-08-20 13:52:35 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_task LEFT JOIN (ach_task_lang) ON (atl_lang=' " . $_USER -> getLang () . " ' AND atl_task=at_id) LEFT JOIN (ach_player_task) ON (apt_task=at_id AND apt_player=' " . $_USER -> getID () . " ') WHERE at_achievement=' " . $this -> id . " ' ORDER by at_torder ASC " );
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-08-22 13:29:29 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
$curr -> loadHeritage ();
}
2012-06-21 18:55:52 +00:00
}
2012-08-20 15:41:46 +00:00
function parentDone () { // check if the parent is complete
2012-08-20 13:52:35 +00:00
if ( $this -> parent_id == null ) {
return true ;
}
else {
$p = $this -> parent -> getChildDataByID ( $this -> parent_id );
2012-12-10 14:07:13 +00:00
if ( $p == null ) {
return true ;
}
2012-08-20 13:52:35 +00:00
return ( $p -> hasOpen () == false );
}
}
2012-08-20 15:41:46 +00:00
#@override Parentum::makeChild()
2012-06-25 13:03:14 +00:00
protected function makeChild ( $a ) {
2012-08-20 13:52:35 +00:00
return new AchTask ( $a , $this );
2012-05-25 09:48:56 +00:00
}
2012-06-25 13:03:14 +00:00
function getParentID () {
return $this -> parent_id ;
2012-05-25 09:48:56 +00:00
}
function getTieRace () {
2012-12-10 14:07:13 +00:00
#return $this->tie_race;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> hasTieRace ()) {
return true ;
}
}
return false ;
2012-05-25 09:48:56 +00:00
}
function getTieCiv () {
2012-12-10 14:07:13 +00:00
#return $this->tie_civ;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> hasTieCiv ()) {
return true ;
}
}
return false ;
2012-05-25 09:48:56 +00:00
}
function getTieCult () {
2012-12-10 14:07:13 +00:00
#return $this->tie_cult;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> hasTieCult ()) {
return true ;
}
}
return false ;
}
function isTiedRace ( $r ) {
#return $this->tie_race;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> isTiedRace ( $r )) {
return true ;
}
}
return false ;
}
function isTiedCiv ( $c ) {
#return $this->tie_civ;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> isTiedCiv ( $c )) {
return true ;
}
}
return false ;
}
function isTiedCult ( $c ) {
#return $this->tie_cult;
$iter = $this -> nodes -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> isTiedCult ( $c )) {
return true ;
}
}
return false ;
2012-05-25 09:48:56 +00:00
}
function getImage () {
return $this -> image ;
}
function getName () {
return $this -> name ;
}
2012-08-20 15:41:46 +00:00
function getValueDone () { // calculate the yubopoints that are already done
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
2012-08-20 15:41:46 +00:00
function getValueOpen () { // get the yubopoints of the next open task
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-08-20 15:41:46 +00:00
function fillTemplate ( $insert = array ()) { // fill the naming template with given value
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-08-20 13:52:35 +00:00
function getSticky () {
return $this -> sticky ;
}
function isSticky () {
return ( $this -> sticky == 1 );
}
2012-08-20 15:41:46 +00:00
function isHeroic () { // check parent category if it is heroic
2012-08-20 13:52:35 +00:00
return $this -> parent -> isHeroic ();
}
2012-12-10 14:07:13 +00:00
function isContest () {
return $this -> parent -> isContest ();
}
2012-07-01 18:04:01 +00:00
2012-05-25 09:48:56 +00:00
}
?>