2012-05-25 09:48:56 +00:00
< ? php
class AchMenu extends RenderNodeIterator {
2012-05-27 19:08:28 +00:00
var $open ;
2012-05-31 13:15:36 +00:00
function AchMenu ( $open = false ) {
global $DBc , $_USER ;
2012-05-25 09:48:56 +00:00
2012-05-27 19:08:28 +00:00
$this -> open = $open ;
2012-05-28 19:09:44 +00:00
$tmp = array ();
$tmp [ 'ac_id' ] = 0 ;
$tmp [ 'ac_parent' ] = null ;
2012-05-31 13:15:36 +00:00
$tmp [ 'acl_name' ] = get_translation ( 'ach_summary' , $_USER -> getLang ());
2012-05-28 19:09:44 +00:00
$tmp [ 'ac_image' ] = " " ;
$tmp [ 'ac_order' ] = - 1 ;
$this -> nodes [] = new AchMenuNode ( $tmp , $open , $lang );
2012-05-27 19:08:28 +00:00
2012-05-31 13:15:36 +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 IS NULL ORDER by ac_order ASC, acl_name ASC " );
2012-05-27 19:08:28 +00:00
2012-05-25 09:48:56 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-05-31 13:15:36 +00:00
$this -> nodes [] = new AchMenuNode ( $res [ $i ], $open );
2012-05-25 09:48:56 +00:00
}
}
2012-05-27 19:08:28 +00:00
2012-05-28 19:09:44 +00:00
function getOpen () {
2012-05-27 19:08:28 +00:00
return $this -> open ;
}
2012-05-28 19:09:44 +00:00
function getOpenCat () {
foreach ( $this -> nodes as $elem ) {
$res = $elem -> hasOpenCat ();
if ( $res != 0 ) {
return $res ;
}
}
return 0 ;
}
2012-05-25 09:48:56 +00:00
}
class AchMenuNode extends RenderNodeIterator {
2012-05-27 19:08:28 +00:00
private $id ;
private $parent ;
private $name ;
private $open ;
private $image ;
private $order ;
2012-05-25 09:48:56 +00:00
2012-05-31 13:15:36 +00:00
function AchMenuNode ( & $data , $open ) {
global $DBc , $_USER ;
2012-05-25 09:48:56 +00:00
$this -> id = $data [ 'ac_id' ];
$this -> parent = $data [ 'ac_parent' ];
$this -> name = $data [ 'acl_name' ];
2012-05-27 19:08:28 +00:00
$this -> image = $data [ 'ac_image' ];
$this -> order = $data [ 'ac_order' ];
2012-05-28 19:09:44 +00:00
$this -> open = ( $this -> id == $open );
2012-05-25 09:48:56 +00:00
2012-05-31 13:15:36 +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 " );
2012-05-27 19:08:28 +00:00
2012-05-25 09:48:56 +00:00
$sz = sizeof ( $res );
for ( $i = 0 ; $i < $sz ; $i ++ ) {
2012-05-31 13:15:36 +00:00
$this -> nodes [] = new AchMenuNode ( $res [ $i ], $open );
2012-05-25 09:48:56 +00:00
}
}
function getID () {
return $this -> id ;
}
function getName () {
return $this -> name ;
}
function getParent () {
return $this -> parent ;
}
2012-05-28 19:09:44 +00:00
function hasOpenCat () {
if ( $this -> open ) {
return $this -> id ;
}
foreach ( $this -> nodes as $elem ) {
$res = $elem -> hasOpenCat ();
if ( $res != 0 ) {
return $res ;
}
}
return 0 ;
}
2012-05-25 09:48:56 +00:00
function isOpen () {
return $this -> open ;
}
2012-05-27 19:08:28 +00:00
function getImage () {
return $this -> image ;
}
function getOrder () {
return $this -> order ;
}
2012-05-25 09:48:56 +00:00
}
?>