#1470 major update; these changes were necessary for the admin tool; currently untested - need new testserver with php 5.4
--HG-- branch : gsoc2012-achievementshg/feature/gsoc2013-dfighter
parent
a874eb6f04
commit
a3d40de283
@ -1,22 +1,39 @@
|
||||
<?php
|
||||
abstract class AchList extends RenderNodeIterator {
|
||||
abstract class AchList extends Parentum {
|
||||
protected $child_done = array();
|
||||
protected $child_open = array();
|
||||
|
||||
function getDone() {
|
||||
return $this->child_done;
|
||||
final function getDone() {
|
||||
return new NodeIterator($this->child_done);
|
||||
}
|
||||
|
||||
function getOpen() {
|
||||
return $this->child_open;
|
||||
final function getOpen() {
|
||||
return new NodeIterator($this->child_open);
|
||||
}
|
||||
|
||||
function hasOpen() {
|
||||
final function hasOpen() {
|
||||
return (sizeof($this->child_open) != 0);
|
||||
}
|
||||
|
||||
function hasDone() {
|
||||
final function hasDone() {
|
||||
return (sizeof($this->child_done) != 0);
|
||||
}
|
||||
|
||||
final function addOpen($n) {
|
||||
$this->child_open[] = $this->addChild($n);
|
||||
}
|
||||
|
||||
final function addDone($n) {
|
||||
$this->child_done[] = $this->addChild($n);
|
||||
}
|
||||
|
||||
function removeChild() {
|
||||
$idx = $this->getIdx($id);
|
||||
if($idx != null) {
|
||||
unset($this->child_open[$idx]);
|
||||
unset($this->child_done[$idx]);
|
||||
parent::removeIdx($idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
class NodeIterator {
|
||||
private $nodes;
|
||||
private $curr;
|
||||
|
||||
function NodeIterator(&$nodes) {
|
||||
$this->nodes = $nodes;
|
||||
$this->curr = 0;
|
||||
}
|
||||
|
||||
function hasNext() {
|
||||
$tmp = array_keys($this->nodes);
|
||||
return isset($this->nodes[$tmp[$this->curr]]);
|
||||
}
|
||||
|
||||
function getNext() {
|
||||
$tmp = array_keys($this->nodes);
|
||||
return $this->nodes[$tmp[$this->curr++]];
|
||||
}
|
||||
|
||||
function first() {
|
||||
$this->curr = 0;
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
trait Node {
|
||||
protected $id;
|
||||
protected $parent;
|
||||
|
||||
final function getID() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
final function getParent() {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
final protected function setID($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
final protected function setParent($p) {
|
||||
$this->parent = $p;
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,5 +1,68 @@
|
||||
<?php
|
||||
abstract class Parentum {
|
||||
abstract protected function makeChild(&$args);
|
||||
/*---------------------------
|
||||
This class allows external access to the child-node list.
|
||||
Use the NodeIterator to iterate through the list since
|
||||
the numeric array keys might have gaps due to node removals!
|
||||
---------------------------*/
|
||||
protected $nodes = array();
|
||||
|
||||
abstract protected function makeChild($args); // overwriteable child generator; allows to define child type (eg.: admin classes that inherit base class)
|
||||
|
||||
final function getSize() {
|
||||
return sizeof($this->nodes);
|
||||
}
|
||||
|
||||
final function isEmpty() {
|
||||
return (sizeof($this->nodes) == 0);
|
||||
}
|
||||
|
||||
final function getIterator() {
|
||||
return new NodeIterator($this->nodes);
|
||||
}
|
||||
|
||||
final function addChild($n) {
|
||||
$tmp = sizeof($this->nodes);
|
||||
$this->nodes[] = $n;
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
function removeChild($id) {
|
||||
$this->removeIdx($this->getIdx($id));
|
||||
}
|
||||
|
||||
function removeNode($n) {
|
||||
$this->removeIdx($this->findNode($n));
|
||||
}
|
||||
|
||||
final protected function removeIdx($idx) {
|
||||
if($idx != null) {
|
||||
unset($this->nodes[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
final protected function findNode($n) {
|
||||
foreach($this->nodes as $key=>$elem) {
|
||||
if($this->nodes[$key] === $n) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
final protected function findNodeIdx($idx) {
|
||||
return $this->nodes[$idx];
|
||||
}
|
||||
|
||||
final protected function getIdx($id) {
|
||||
foreach($this->nodes as $key=>$elem) {
|
||||
if($elem->getID() == $id) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
abstract class RenderNodeIterator extends Parentum {
|
||||
protected $nodes = array();
|
||||
|
||||
function getSize() {
|
||||
return sizeof($this->nodes);
|
||||
}
|
||||
|
||||
function getChild($i) {
|
||||
return $this->nodes[$i];
|
||||
}
|
||||
|
||||
function isEmpty() {
|
||||
return (sizeof($this->nodes) == 0);
|
||||
}
|
||||
|
||||
function getChildren() {
|
||||
return $this->nodes;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue