2012-06-25 13:04:51 +00:00
< ? php
2012-07-02 16:56:13 +00:00
class AdmAchievement extends AchAchievement 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 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 AdmAchievement ( $data , $parent ) {
parent :: __construct ( $data , $parent );
}
2012-07-02 16:56:13 +00:00
protected function makeChild ( $d ) {
2012-08-20 13:52:35 +00:00
return new AdmTask ( $d , $this );
}
function getLang ( $lang ) {
global $DBc ;
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_achievement_lang WHERE aal_achievement=' " . $this -> getID () . " ' AND aal_lang=' " . $lang . " ' " );
return array ( 0 => $res [ 0 ][ 'aal_name' ], 1 => $res [ 0 ][ 'aal_template' ]);
}
function setLang ( $lang , $txt , $tpl ) {
global $DBc , $_USER ;
$DBc -> sqlQuery ( " INSERT INTO ach_achievement_lang (aal_achievement,aal_lang,aal_name,aal_template) VALUES (' " . $this -> getID () . " ',' " . $DBc -> sqlEscape ( $lang ) . " ',' " . $DBc -> sqlEscape ( $txt ) . " ', " . mkn ( $tpl ) . " ) ON DUPLICATE KEY UPDATE aal_name=' " . $DBc -> sqlEscape ( $txt ) . " ',aal_template= " . mkn ( $tpl ) . " " );
if ( $_USER -> getLang () == $lang ) {
$this -> name = $txt ;
$this -> template = $tpl ;
}
2012-06-25 13:04:51 +00:00
}
2012-07-02 16:56:13 +00:00
#@overrides AdmDispatcher::insertNode()
function insertNode ( $n ) {
2012-06-25 13:04:51 +00:00
$n -> insert ();
2012-07-02 16:56:13 +00:00
$this -> addOpen ( $n );
2012-06-25 13:04:51 +00:00
}
function delete_me () {
global $DBc ;
$DBc -> sqlQuery ( " DELETE FROM ach_achievement WHERE aa_id=' " . $this -> getID () . " ' " );
2012-08-20 13:52:35 +00:00
$DBc -> sqlQuery ( " DELETE FROM ach_objective WHERE ao_metalink=' " . $this -> getID () . " ' " );
2012-06-25 13:04:51 +00:00
$DBc -> sqlQuery ( " DELETE FROM ach_achievement_lang WHERE NOT EXISTS (SELECT * FROM ach_achievement WHERE aa_id=aal_achievement) " );
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 () {
global $DBc ;
2012-12-10 14:07:13 +00:00
$DBc -> sqlQuery ( " UPDATE ach_achievement SET aa_category=' " . $this -> getCategory () . " ',aa_parent= " . mkn ( $this -> getParentID ()) . " ,aa_image=' " . $DBc -> sqlEscape ( $this -> getImage ()) . " ',aa_dev=' " . $this -> getDev () . " ',aa_sticky=' " . $DBc -> sqlEscape ( $this -> getSticky ()) . " ' WHERE aa_id=' " . $this -> getID () . " ' " );
2012-06-25 13:04:51 +00:00
#MISSING: update lang entry
2012-08-07 15:41:50 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_achievement_lang (aal_achievement,aal_lang,aal_name,aal_template) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ', " . mkn ( $this -> getTemplate ()) . " ) ON DUPLICATE KEY UPDATE aal_name=' " . $DBc -> sqlEscape ( $this -> getName ()) . " ',aal_template= " . mkn ( $this -> getTemplate ()) . " " );
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-07-02 16:56:13 +00:00
$this -> dev = 1 ;
2012-06-25 13:04:51 +00:00
2012-12-10 14:07:13 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_achievement (aa_category,aa_parent,aa_image,aa_dev,aa_sticky) VALUES (' " . $this -> getCategory () . " ', " . mkn ( $this -> getParentID ()) . " ,' " . $DBc -> sqlEscape ( $this -> getImage ()) . " ','1',' " . $DBc -> sqlEscape ( $this -> getSticky ()) . " ') " );
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_achievement_lang (aal_achievement,aal_lang,aal_name,aal_template) VALUES (' " . $this -> getID () . " ','en',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ', " . mkn ( $this -> getTemplate ()) . " ) " );
2012-06-25 13:04:51 +00:00
}
function setCategory ( $c ) {
$this -> category = $c ;
}
function setImage ( $i ) {
$this -> image = $i ;
}
function setName ( $n ) {
$this -> name = $n ;
}
2012-07-02 16:56:13 +00:00
function setTemplate ( $t ) {
2012-06-25 13:04:51 +00:00
$this -> template = $t ;
}
2012-07-09 17:10:44 +00:00
2012-08-20 13:52:35 +00:00
function orderTasks () {
2012-07-09 17:10:44 +00:00
$i = 0 ;
2012-08-20 13:52:35 +00:00
$start = $this -> findParentID ( null );
while ( $start != null ) {
$start -> setTorder ( $i );
$start -> update ();
$i ++ ;
#echo $i;
$start = $this -> findParentID ( $start -> getID ());
}
}
private function findParentID ( $id ) {
$iter = $this -> getIterator ();
2012-07-09 17:10:44 +00:00
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
2012-08-20 13:52:35 +00:00
if ( $curr -> getParentID () == $id ) {
return $curr ;
}
2012-07-09 17:10:44 +00:00
}
2012-08-20 13:52:35 +00:00
return null ;
}
function setParentID ( $p ) {
$this -> parent_id = $p ;
}
function setSticky ( $s ) {
$this -> sticky = $s ;
2012-07-09 17:10:44 +00:00
}
2012-06-25 13:04:51 +00:00
}
?>