2012-06-25 13:04:51 +00:00
|
|
|
<?php
|
2012-06-25 20:00:02 +00:00
|
|
|
class AdmMenu extends AchMenu {
|
2012-07-02 16:56:13 +00:00
|
|
|
use AdmDispatcher;
|
2012-06-25 13:04:51 +00:00
|
|
|
|
|
|
|
function AdmMenu($open) {
|
|
|
|
parent::__construct($open);
|
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
#$this->drawTree();
|
|
|
|
|
|
|
|
#$this->removeChild(0); // unset the auto-generated "summary" node
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function makeChild($d) { // override child generator to use admin classes
|
|
|
|
return new AdmMenuNode($d,$this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeNode($id) { // find the node that has the ID we want to delete. If found, call it's delete function.
|
|
|
|
$res = $this->getNode($id);
|
|
|
|
if($res != null) {
|
|
|
|
$res->delete_me();
|
2012-07-02 16:56:13 +00:00
|
|
|
$this->removeChild($id);
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertNode(&$n) {
|
|
|
|
if($n->getParentID() != null) {
|
|
|
|
$res = $this->getNode($n->getParentID());
|
|
|
|
if($res != null) {
|
|
|
|
$n->setParent($res);
|
|
|
|
$res->insertChild($n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$n->setParent($this);
|
|
|
|
$n->insert();
|
2012-07-02 16:56:13 +00:00
|
|
|
$this->addChild($n);
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateNode($id,$data) { #MISSING: data handling...
|
|
|
|
$res = $this->getNode($id);
|
|
|
|
if($res != null) {
|
|
|
|
$res->setName($data['acl_name']);
|
|
|
|
$res->setImage($data['ac_image']);
|
|
|
|
$res->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function swapOrder($a,$b) {
|
|
|
|
$tmp_a = $this->getNode($a);
|
|
|
|
if($tmp_a != null) {
|
|
|
|
$tmp_b = $this->getNode($a);
|
|
|
|
if($tmp_b != null) {
|
|
|
|
$tmp = $tmp_b->getOrder();
|
|
|
|
$tmp_b->setOrder($tmp_a->getOrder());
|
|
|
|
$tmp_a->setOrder($tmp);
|
|
|
|
|
|
|
|
if($tmp_a->getParentID() == $tmp_b->getParentID()) {
|
|
|
|
$tmp_a->getParent()->swapChild($a,$b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNode($id) { // try to find the MenuNode that has the given ID. Return null on failure.
|
2012-07-02 16:56:13 +00:00
|
|
|
#echo "<br>getNode(".$id.")";
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$iter = $this->getIterator();
|
|
|
|
while($iter->hasNext()) {
|
|
|
|
$curr = $iter->getNext();
|
|
|
|
#echo $curr->getID();
|
|
|
|
$tmp = $curr->getNode($id);
|
2012-06-25 13:04:51 +00:00
|
|
|
if($tmp != null) {
|
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNextOrder() {
|
|
|
|
if($this->isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$val = array();
|
2012-07-02 16:56:13 +00:00
|
|
|
$iter = $this->getIterator();
|
|
|
|
while($iter->hasNext()) {
|
|
|
|
$curr = $iter->getNext();
|
|
|
|
$val[] = $curr->getOrder();
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (max($val)+1);
|
|
|
|
}
|
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
/*function unsetChild($id) { // remove child with given ID from nodes list; unset should destruct it.
|
2012-06-25 13:04:51 +00:00
|
|
|
foreach($this->nodes as $key=>$elem) {
|
|
|
|
if($elem->getID() == $id) {
|
|
|
|
unset($this->nodes[$key]);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-07-02 16:56:13 +00:00
|
|
|
}*/
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
?>
|