2012-06-25 13:04:51 +00:00
< ? php
2012-07-02 16:56:13 +00:00
class AdmObjective extends AchObjective implements ADM {
2012-08-20 13:52:35 +00:00
#########################
# PHP 5.3 compatible
# AdmDispatcher_trait replaces this in PHP 5.4
2012-08-07 15:41:50 +00:00
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 ;
}
2012-08-20 13:52:35 +00:00
#########################
2012-06-25 13:04:51 +00:00
function AdmObjective ( $data , $parent ) {
parent :: __construct ( $data , $parent );
global $DBc ;
2012-08-07 15:41:50 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_atom WHERE atom_objective=' " . $this -> getID () . " ' " );
2012-06-25 13:04:51 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-07-08 16:11:25 +00:00
$this -> addChild ( $this -> makeChild ( $res [ $i ]));
2012-06-25 13:04:51 +00:00
}
}
2012-07-02 16:56:13 +00:00
protected function makeChild ( $d ) {
2012-06-25 13:04:51 +00:00
return new AdmAtom ( $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_objective_lang WHERE aol_objective=' " . $this -> getID () . " ' AND aol_lang=' " . $lang . " ' " );
return $res [ 0 ][ 'aol_name' ];
}
2012-08-20 15:41:46 +00:00
function setLang ( $lang , $txt ) { // 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_objective_lang (aol_objective,aol_lang,aol_name) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $lang ) . " ',' " . $DBc -> sqlEscape ( $txt ) . " ') ON DUPLICATE KEY UPDATE aol_name=' " . $DBc -> sqlEscape ( $txt ) . " ' " );
2012-08-20 13:52:35 +00:00
if ( $_USER -> getLang () == $lang ) {
$this -> name = $txt ;
}
}
2012-06-25 13:04:51 +00:00
function delete_me () {
global $DBc ;
$DBc -> sqlQuery ( " DELETE FROM ach_objective WHERE ao_id=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_player_objective WHERE apo_objective=' " . $this -> getID () . " ' " );
2012-07-02 16:56:13 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
$curr -> delete_me ();
$this -> removeChild ( $curr -> getID ());
2012-06-25 13:04:51 +00:00
}
}
function update () {
2012-07-02 16:56:13 +00:00
global $DBc ;
2012-06-25 13:04:51 +00:00
2012-08-20 13:52:35 +00:00
$DBc -> sqlQuery ( " UPDATE ach_objective SET ao_condition=' " . $DBc -> sqlEscape ( $this -> getCondition ()) . " ',ao_value= " . mkn ( $this -> getValue ()) . " ,ao_display=' " . $DBc -> sqlEscape ( $this -> getDisplay ()) . " ',ao_metalink= " . mkn ( $this -> getMetalink ()) . " WHERE ao_id=' " . $this -> getID () . " ' " );
2012-07-02 16:56:13 +00:00
2012-08-07 15:41:50 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_objective_lang (aol_objective,aol_lang,aol_name) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ') ON DUPLICATE KEY UPDATE aol_name=' " . $DBc -> sqlEscape ( $this -> getName ()) . " ' " );
2012-06-25 13:04:51 +00:00
}
function insert () {
2012-07-02 16:56:13 +00:00
global $DBc ;
2012-06-25 13:04:51 +00:00
2012-08-20 13:52:35 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_objective (ao_task,ao_condition,ao_value,ao_display,ao_metalink) VALUES (' " . $this -> getTask () . " ',' " . $DBc -> sqlEscape ( $this -> getCondition ()) . " ', " . mkn ( $this -> getValue ()) . " ,' " . $DBc -> sqlEscape ( $this -> getDisplay ()) . " ', " . mkn ( $this -> getMetalink ()) . " ) " );
2012-08-07 15:41:50 +00:00
$id = $DBc -> insertID ();
2012-07-02 16:56:13 +00:00
$this -> setID ( $id );
2012-06-25 13:04:51 +00:00
2012-08-07 15:41:50 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_objective_lang (aol_objective,aol_lang,aol_name) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ') " );
2012-07-02 16:56:13 +00:00
}
2012-06-25 13:04:51 +00:00
2012-07-02 16:56:13 +00:00
function setCondition ( $c ) {
$this -> condition = $c ;
2012-06-25 13:04:51 +00:00
}
2012-07-09 17:10:44 +00:00
function setDisplay ( $d ) {
$this -> display = $d ;
}
function setName ( $n ) {
$this -> name = $n ;
}
function setValue ( $v ) {
$this -> value = $v ;
}
function setMetalink ( $m ) {
2012-08-20 13:52:35 +00:00
$this -> metalink = $m ;
if ( $this -> getDisplay () == " meta " ) {
$this -> name = " <i>name and image will load on refresh only!</i> " ;
}
2012-07-09 17:10:44 +00:00
}
2012-08-20 13:52:35 +00:00
function setTask ( $t ) {
$this -> task = $t ;
2012-07-09 17:10:44 +00:00
}
2012-06-25 13:04:51 +00:00
}
?>