2012-06-25 13:04:51 +00:00
< ? php
2012-08-20 13:52:35 +00:00
class AdmMenuNode extends AchMenuNode implements ADM {
2012-06-25 13:04:51 +00:00
private $ach_count ;
function AdmMenuNode ( $data , $parent ) {
parent :: __construct ( $data , $parent );
global $DBc ;
$res = $DBc -> sqlQuery ( " SELECT count(*) as anz FROM ach_achievement WHERE aa_category=' " . $this -> id . " ' " );
$this -> ach_count = $res [ 0 ][ 'anz' ];
}
protected function makeChild ( $d ) { // override child generator to use admin classes
return new AdmMenuNode ( $d , $this );
}
function hasAchievements () {
if ( $this -> ach_count != 0 ) {
return true ;
}
else {
2012-08-07 15:41:50 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$elem = $iter -> getNext ();
2012-06-25 13:04:51 +00:00
$res = $elem -> hasAchievements ();
if ( $res == true ) {
return true ;
}
}
return false ;
}
}
function getNode ( $id ) { // try to find the child node that has the given ID. Return null on failure.
2012-07-08 16:11:25 +00:00
$res = $this -> getChildDataByID ( $id );
2012-07-02 16:56:13 +00:00
if ( $res != null ) {
return $res ;
2012-06-25 13:04:51 +00:00
}
2012-07-02 16:56:13 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) { // check children
$curr = $iter -> getNext ();
$tmp = $curr -> getNode ( $id );
if ( $tmp != null ) {
return $tmp ;
2012-06-25 13:04:51 +00:00
}
}
2012-07-02 16:56:13 +00:00
return null ;
2012-06-25 13:04:51 +00:00
}
function delete_me () { // remove this node
global $DBc ;
// remove from database
$DBc -> sqlQuery ( " DELETE FROM ach_category WHERE ac_id=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_category WHERE ac_parent=' " . $this -> getID () . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_category_lang WHERE NOT EXISTS (SELECT * FROM ach_category WHERE ac_id=acl_category) " );
// call delete function for all children
foreach ( $this -> nodes as $elem ) {
$elem -> delete_me ();
2012-07-02 16:56:13 +00:00
$this -> removeChild ( $elem -> getID ());
2012-06-25 13:04:51 +00:00
}
}
function insertChild ( & $n ) { // insert a new child
// insert command to create database entry
$n -> insert ();
// set the new child's parent and add it to the node list
$n -> setParent ( $this );
2012-07-02 16:56:13 +00:00
$this -> addChild ( $n );
2012-06-25 13:04:51 +00:00
}
function update () {
global $DBc , $_USER ;
$DBc -> sqlQuery ( " UPDATE ach_category SET ac_parent= " . mkn ( $this -> getParentID ()) . " ,ac_order=' " . $this -> getOrder () . " ',ac_image= " . mkn ( $this -> getImage ()) . " ,ac_dev=' " . $this -> getDev () . " ' WHERE ac_id=' " . $this -> getID () . " ' " );
2012-08-20 13:52:35 +00:00
#echo "<br>".$this->getImage()." =>UPDATE ach_category SET ac_parent=".mkn($this->getParentID()).",ac_order='".$this->getOrder()."',ac_image=".mkn($this->getImage()).",ac_dev='".$this->getDev()."' WHERE ac_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 IGNORE INTO ach_category_lang (acl_category,acl_lang,acl_name) VALUES (' " . $this -> getID () . " ',' " . $_USER -> getLang () . " ',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ') ON DUPLICATE KEY UPDATE acl_name=' " . $DBc -> sqlEscape ( $this -> getName ()) . " ' " );
2012-06-25 13:04:51 +00:00
}
function insert () { // write $this to the database as a new entry
global $DBc , $_USER ;
$this -> setOrder ( $this -> parent -> getNextOrder ());
$DBc -> sqlQuery ( " INSERT INTO ach_category (ac_parent,ac_order,ac_image,ac_dev) VALUES ( " . mkn ( $this -> getParentID ()) . " ,' " . $this -> getOrder () . " ', " . mkn ( $this -> getImage ()) . " ,'1') " );
2012-08-07 15:41:50 +00:00
$id = $DBc -> insertID ();
2012-06-25 13:04:51 +00:00
$this -> setID ( $id );
#MISSING: insert lang entry
2012-08-07 15:41:50 +00:00
$DBc -> sqlQuery ( " INSERT INTO ach_category_lang (acl_category,acl_lang,acl_name) VALUES (' " . $this -> getID () . " ',' " . $_USER -> getLang () . " ',' " . $DBc -> sqlEscape ( $this -> getName ()) . " ') " );
2012-06-25 13:04:51 +00:00
}
private function setOrder ( $o ) {
$this -> order = $o ;
$this -> update ();
}
function swapChild ( $a , $b ) {
$ids = array ();
foreach ( $this -> nodes as $key => $elem ) {
if ( $a == $elem -> getID () || $b == $elem -> getID ()) {
$ids [] = $key ;
}
if ( sizeof ( $ids ) == 2 ) {
break ;
}
}
$tmp = $this -> nodes [ $ids [ 0 ]];
$this -> nodes [ $ids [ 0 ]] = $this -> nodes [ $tmp [ 1 ]];
$this -> nodes [ $ids [ 1 ]] = $tmp ;
}
function setName ( $n ) {
$this -> name = $n ;
}
function setImage ( $i ) {
if ( $i == null || strtolower ( $i ) == " null " ) {
$this -> image = null ;
}
else {
$this -> image = $i ;
}
}
function setParentID ( $p ) {
if ( $p == null || strtolower ( $p ) == " null " ) {
$this -> parent_id = null ;
}
else {
$this -> parent_id = $p ;
}
}
function getNextOrder () {
if ( $this -> isEmpty ()) {
return 0 ;
}
$val = array ();
2012-08-07 15:41:50 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$elem = $iter -> getNext ();
2012-06-25 13:04:51 +00:00
$val [] = $elem -> getOrder ();
}
return ( max ( $val ) + 1 );
}
}
?>