2012-06-24 10:44:24 +00:00
< ? php
2012-06-25 13:03:14 +00:00
class AchMenuNode extends Parentum {
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
2012-06-24 10:44:24 +00:00
protected $parent_id ;
protected $name ;
protected $open ;
protected $image ;
protected $order ;
2012-06-25 13:03:14 +00:00
function AchMenuNode ( $data , $parent ) {
2012-12-10 14:07:13 +00:00
global $DBc , $_USER , $_CONF ;
2012-06-24 10:44:24 +00:00
2012-07-08 16:11:25 +00:00
parent :: __construct ();
2012-06-25 13:03:14 +00:00
$this -> setParent ( $parent );
$this -> setID ( $data [ 'ac_id' ]);
2012-06-24 10:44:24 +00:00
$this -> parent_id = $data [ 'ac_parent' ];
$this -> name = $data [ 'acl_name' ];
$this -> image = $data [ 'ac_image' ];
$this -> order = $data [ 'ac_order' ];
$this -> open = ( $this -> id == $data [ 'open' ]);
$this -> dev = $data [ 'ac_dev' ];
2012-12-10 14:07:13 +00:00
if ( $this -> name == null ) {
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_category_lang WHERE acl_lang=' " . $_CONF [ 'default_lang' ] . " ' AND acl_category=' " . $this -> id . " ' " );
$this -> name = $res [ 0 ][ 'acl_name' ];
}
2012-06-24 10:44:24 +00:00
$res = $DBc -> sqlQuery ( " SELECT * FROM ach_category LEFT JOIN (ach_category_lang) ON (acl_lang=' " . $_USER -> getLang () . " ' AND acl_category=ac_id) WHERE ac_parent=' " . $this -> id . " ' ORDER by ac_order ASC, acl_name ASC " );
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
$res [ $i ][ 'open' ] = $data [ 'open' ];
2012-07-08 16:11:25 +00:00
$this -> addChild ( $this -> makeChild ( $res [ $i ]));
2012-06-24 10:44:24 +00:00
}
}
2012-07-08 16:11:25 +00:00
#@override Parentum::makeChild()
2012-06-25 13:03:14 +00:00
protected function makeChild ( $a ) {
return new AchMenuNode ( $a , $this );
2012-06-24 10:44:24 +00:00
}
function getName () {
return $this -> name ;
}
function getParentID () {
return $this -> parent_id ;
}
function hasOpenCat () { // finds the currently open MenuNode and returns it's ID. If not found the result will be 0 instead.
if ( $this -> open ) {
return $this -> id ;
}
2012-07-08 16:11:25 +00:00
$iter = $this -> getIterator ();
while ( $iter -> hasNext ()) {
$curr = $iter -> getNext ();
$res = $curr -> hasOpenCat ();
2012-06-24 10:44:24 +00:00
if ( $res != 0 ) {
return $res ;
}
}
return 0 ;
}
function isOpen () {
return $this -> open ;
}
function getImage () {
return $this -> image ;
}
function getOrder () {
return $this -> order ;
}
}
?>