2012-08-20 13:52:35 +00:00
< ? php
class AdmTask extends AchTask implements ADM {
#########################
# PHP 5.3 compatible
# AdmDispatcher_trait replaces this in PHP 5.4
function insertNode ( $n ) {
$n -> setParent ( $this );
$n -> insert ();
$this -> addChild ( $n );
}
function removeNode ( $id ) {
$res = $this -> getChildDataByID ( $id );
if ( $res != null ) {
$res -> delete_me ();
$this -> removeChild ( $id );
}
}
function updateNode ( $id ) { // PROBABLY USELESS!
$res = $this -> getChildDataByID ( $id );
if ( $res != null ) {
$res -> update ();
}
}
function getPathID ( $path = " " ) {
if ( $path != " " ) {
$path = " ; " . $path ;
}
$path = $this -> getID () . $path ;
if ( $this -> parent != null ) {
return $this -> parent -> getPathID ( $path );
}
return $path ;
}
function getElementByPath ( $pid ) {
$tmp = explode ( " ; " , $pid );
if ( $tmp [ 0 ] == $this -> getID ()) {
if ( sizeof ( $tmp ) > 1 ) {
$c = $this -> getChildDataByID ( $tmp [ 1 ]);
if ( $c != null ) {
unset ( $tmp [ 0 ]);
return $c -> getElementByPath ( implode ( " ; " , $tmp ));
}
return null ;
}
else {
return $this ;
}
}
return null ;
}
#########################
protected $condition ;
protected $condition_value ;
protected $torder ;
function AdmTask ( $data , $parent ) {
parent :: __construct ( $data , $parent );
$this -> condition = $data [ " at_condition " ];
$this -> condition_value = $data [ " at_condition_value " ];
$this -> torder = $data [ " at_torder " ];
}
protected function makeChild ( $d ) {
return new AdmObjective ( $d , $this );
}
2012-08-20 15:41:46 +00:00
function getLang ( $lang ) { // load language
2012-08-20 13:52:35 +00:00
global $DBc ;
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_task_lang WHERE atl_task=' " . $this -> getID () . " ' AND atl_lang=' " . $lang . " ' " );
return array ( 0 => $res [ 0 ][ 'atl_name' ], 1 => $res [ 0 ][ 'atl_template' ]);
}
2012-08-20 15:41:46 +00:00
function setLang ( $lang , $txt , $tpl ) { // write language
2012-08-20 13:52:35 +00:00
global $DBc , $_USER ;
2012-12-10 14:07:13 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_task_lang (atl_task,atl_lang,atl_name,atl_template) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $lang ) . " ',' " . $DBc -> sqlEscape ( $txt ) . " ', " . mkn ( $tpl ) . " ) ON DUPLICATE KEY UPDATE atl_name=' " . $DBc -> sqlEscape ( $txt ) . " ',atl_template= " . mkn ( $tpl ) . " " );
2012-08-20 13:52:35 +00:00
if ( $_USER -> getLang () == $lang ) {
$this -> name = $txt ;
$this -> template = $tpl ;
}
}
function delete_me () {
global $DBc ;
$DBc -> sqlQuery ( " DELETE FROM ach_task WHERE at_id=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_player_task WHERE apt_task=' " . $this -> getID () . " ' " );
2013-02-15 13:50:17 +00:00
$DBc -> sqlQuery ( " DELETE FROM ach_task_tie_align WHERE atta_task=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_task_tie_race WHERE attr_task=' " . $this -> getID () . " ' " );
2012-08-20 13:52:35 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
$curr -> delete_me ();
$this -> removeChild ( $curr -> getID ());
}
}
function update () {
global $DBc ;
2012-08-22 13:29:29 +00:00
$DBc -> sqlQuery ( " UPDATE ach_task SET at_parent= " . mkn ( $this -> getParentID ()) . " ,at_value=' " . $DBc -> sqlEscape ( $this -> getValue ()) . " ',at_condition=' " . $DBc -> sqlEscape ( $this -> getCondition ()) . " ',at_condition_value= " . mkn ( $this -> getConditionValue ()) . " ,at_dev=' " . $this -> getDev () . " ',at_torder=' " . $this -> torder . " ', at_inherit=' " . $this -> inherit_obj . " ' WHERE at_id=' " . $this -> getID () . " ' " );
2012-08-20 13:52:35 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_task_lang (atl_task,atl_lang,atl_name,atl_template) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ', " . mkn ( $this -> getTemplate ()) . " ) ON DUPLICATE KEY UPDATE atl_name=' " . $DBc -> sqlEscape ( $this -> getName ()) . " ',atl_template= " . mkn ( $this -> getTemplate ()) . " " );
2013-02-15 13:50:17 +00:00
$DBc -> sqlQuery ( " DELETE FROM ach_task_tie_align WHERE atta_task=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_task_tie_race WHERE attr_task=' " . $this -> getID () . " ' " );
foreach ( $this -> tie_race as $elem ) {
$DBc -> sqlQuery ( " INSERT INTO ach_task_tie_race (attr_task,attr_race) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $elem ) . " ') " );
}
foreach ( $this -> tie_align as $elem ) {
$DBc -> sqlQuery ( " INSERT INTO ach_task_tie_align (atta_task,atta_alignment) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $elem ) . " ') " );
}
2012-08-20 13:52:35 +00:00
}
function insert () {
global $DBc ;
$this -> dev = 1 ;
2012-08-22 13:29:29 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_task (at_achievement,at_parent,at_value,at_condition,at_condition_value,at_dev,at_torder,at_inherit) VALUES (' " . $this -> getAchievement () . " ', " . mkn ( $this -> getParentID ()) . " ,' " . $DBc -> sqlEscape ( $this -> getValue ()) . " ',' " . $DBc -> sqlEscape ( $this -> getCondition ()) . " ', " . mkn ( $this -> getConditionValue ()) . " ,'1',' " . $this -> torder . " ',' " . $this -> inherit_obj . " ') " );
2012-08-20 13:52:35 +00:00
$id = $DBc -> insertID ();
$this -> setID ( $id );
$DBc -> sqlQuery ( " INSERT INTO ach_task_lang (atl_task,atl_lang,atl_name,atl_template) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ', " . mkn ( $this -> getTemplate ()) . " ) " );
2013-02-15 13:50:17 +00:00
foreach ( $this -> tie_race as $elem ) {
$DBc -> sqlQuery ( " INSERT INTO ach_task_tie_race (attr_task,attr_race) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $elem ) . " ') " );
}
foreach ( $this -> tie_align as $elem ) {
$DBc -> sqlQuery ( " INSERT INTO ach_task_tie_align (atta_task,atta_alignment) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $elem ) . " ') " );
}
2012-08-20 13:52:35 +00:00
}
function setAchievement ( $a ) {
$this -> achievement = $a ;
}
function setName ( $name ) {
$this -> name = $name ;
}
function setTemplate ( $t ) {
$this -> template = $t ;
}
function setValue ( $v ) {
$this -> value = $v ;
}
2013-02-15 13:50:17 +00:00
function setTieRace ( $t ) {
$this -> tie_race = $t ;
}
function setTieAlign ( $t ) {
$this -> tie_align = $t ;
}
2012-08-20 13:52:35 +00:00
function getCondition () {
return $this -> condition ;
}
function getConditionValue () {
return $this -> condition_value ;
}
function setCondition ( $c ) {
$this -> condition = $c ;
}
function setConditionValue ( $v ) {
$this -> condition_value = $v ;
}
function getTorder () {
return $this -> torder ;
}
function setTorder ( $t ) {
$this -> torder = $t ;
}
2012-08-22 13:29:29 +00:00
function setHeritage ( $i ) {
$this -> inherit_obj = $i ;
}
2012-08-20 13:52:35 +00:00
function setParentID ( $p , $order = true ) { #reordering must happen A) after insert B) when updating
if ( $p == null || $p == " null " ) {
$this -> parent_id = null ;
}
else {
$this -> parent_id = $p ;
}
if ( $order == true ) {
$iter = $this -> parent -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
if ( $curr -> getID () == $this -> id ) {
continue ;
}
if ( $curr -> getParentID () == $this -> parent_id ) {
$curr -> setParentID ( $this -> id , false );
$curr -> update ();
break ;
}
}
}
}
2013-02-15 13:50:17 +00:00
function isTiedRace ( $r ) {
if ( sizeof ( $this -> tie_race ) == 0 ) {
return false ;
}
return in_array ( $r , $this -> tie_race );
}
function isTiedAlign ( $cult , $civ ) {
if ( sizeof ( $this -> tie_align ) == 0 ) {
return false ;
}
return in_array (( $cult . '|' . $civ ), $this -> tie_align );
}
2012-08-20 13:52:35 +00:00
}
?>