#1740 replaced child node lists with doubly linked lists; various minor changes

This commit is contained in:
SirCotare 2012-07-08 18:11:25 +02:00
parent edd9dd80a7
commit f41e2b6cdd
33 changed files with 404 additions and 278 deletions

View file

@ -193,7 +193,7 @@
return $r;
}
$p = $r->getLeft();
$p = $r;
while($p->getLeft() != null) {
$p = $p->getLeft();
}

View file

@ -1,6 +1,6 @@
<?php
class AchAchievement extends AchList {
use Node,InDev;
use InDev;
protected $parent_id;
protected $category;
@ -14,6 +14,8 @@
function AchAchievement($data,$parent) {
global $DBc,$_USER;
parent::__construct();
$this->setParent($parent);
$this->setID($data['aa_id']);
$this->parent_id = $data['aa_parent'];
@ -27,7 +29,7 @@
$this->dev = $data['aa_dev'];
$res = $DBc->sqlQuery("SELECT * FROM ach_perk LEFT JOIN (ach_perk_lang) ON (apl_lang='".$_USER->getLang()."' AND apl_perk=ap_id) LEFT JOIN (ach_player_perk) ON (app_perk=ap_id AND app_player='".$_USER->getID()."') WHERE ap_achievement='".$this->id."' AND ap_parent IS NULL");
#MISSING: or parent is done
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$tmp = $this->makeChild($res[$i]);
@ -45,6 +47,15 @@
return new AchPerk($a,$this);
}
function unlockedByParent() {
if($this->parent_id != null) {
$tmp = $this->parent->getChildByID($this->parent_id);
return ($tmp->hasOpen() == false);
}
return true;
}
function getParentID() {
return $this->parent_id;
}
@ -73,7 +84,7 @@
$val = 0;
$iter = $this->getDone();
while($iter->hasNext()) {
$curr = $this->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
$val += $curr->getValue();
}
return $val;
@ -82,7 +93,7 @@
function getValueOpen() {
$iter = $this->getOpen();
if($iter->hasNext()) {
$curr = $this->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
return $curr->getValue();
}
return 0;

View file

@ -1,18 +1,27 @@
<?php
class AchCategory extends AchList implements Tieable {
protected $id;
#protected $id;
protected $ties_cult;
protected $ties_civ;
protected $ties_race;
protected $ties_race_dev;
protected $ties_cult_dev;
protected $ties_civ_dev;
protected $cult;
protected $civ;
function AchCategory($id,$cult = null,$civ = null) {
function AchCategory($id,$race = null,$cult = null,$civ = null) {
global $DBc,$_USER;
parent::__construct();
$civ = mysql_real_escape_string($civ);
$cult = mysql_real_escape_string($cult);
$race = mysql_real_escape_string($race);
if($race == null) {
$race = $_USER->getRace();
}
if($cult == null) {
$cult = $_USER->getCult();
@ -27,27 +36,33 @@
$this->id = mysql_real_escape_string($id);
$res = $DBc->sqlQuery("SELECT * FROM ach_achievement LEFT JOIN (ach_achievement_lang) ON (aal_lang='".$_USER->getLang()."' AND aal_achievement=aa_id) WHERE aa_category='".$this->id."' AND (aa_parent IS NULL OR NOT EXISTS (SELECT * FROM ach_perk WHERE ap_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_player_perk WHERE app_player='".$_USER->getID()."' AND app_perk=ap_id))) AND (aa_tie_race IS NULL OR aa_tie_race LIKE '".$_USER->getRace()."') AND (aa_tie_cult IS NULL OR aa_tie_cult LIKE '".$cult."') AND (aa_tie_civ IS NULL OR aa_tie_civ LIKE '".$civ."') ORDER by aal_name ASC");
#parent!!!!
$res = $DBc->sqlQuery("SELECT * FROM ach_achievement LEFT JOIN (ach_achievement_lang) ON (aal_lang='".$_USER->getLang()."' AND aal_achievement=aa_id) WHERE aa_category='".$this->id."' AND (aa_parent IS NULL OR NOT EXISTS (SELECT * FROM ach_perk WHERE ap_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_player_perk WHERE app_player='".$_USER->getID()."' AND app_perk=ap_id))) AND (aa_tie_race IS NULL OR aa_tie_race LIKE '".$race."') AND (aa_tie_cult IS NULL OR aa_tie_cult LIKE '".$cult."') AND (aa_tie_civ IS NULL OR aa_tie_civ LIKE '".$civ."') ORDER by aal_name ASC");
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$tmp = $this->makeChild($res[$i]);
if($tmp->hasOpen()) {
$this->addOpen($tmp);
$this->addOpen($tmp); #AchList::addOpen()
}
if($tmp->hasDone()) {
$this->addDone($tmp);
$this->addDone($tmp); #AchList::addDone()
}
}
//load counts for tie determination
$res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_cult IS NOT NULL AND aa_category='".$this->id."' AND aa_dev='0'");
$this->ties_cult = $res[0]['anz'];
$res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_civ IS NOT NULL AND aa_category='".$this->id."' AND aa_dev='0'");
$this->ties_civ = $res[0]['anz'];
$res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_race IS NOT NULL AND aa_category='".$this->id."' AND aa_dev='0'");
$this->ties_race = $res[0]['anz'];
$res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_race IS NOT NULL AND aa_category='".$this->id."'");
$this->ties_race_dev = $res[0]['anz'];
$res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_cult IS NOT NULL AND aa_category='".$this->id."'");
$this->ties_cult_dev = $res[0]['anz'];
@ -55,13 +70,14 @@
$this->ties_civ_dev = $res[0]['anz'];
}
#@override Parentum::makeChild()
protected function makeChild($a) {
return new AchAchievement($a,$this);
}
function getID() {
return $this->id;
}
#function getID() {
# return $this->id;
#}
function isTiedCult() {
return ($this->ties_cult > 0);

View file

@ -6,95 +6,78 @@
child_open and child_done refer to the index set in Parentum::nodes[]
---------------------------*/
protected $child_done = array();
protected $child_open = array();
protected $child_done;
protected $child_open;
function AchList() {
parent::__construct();
$this->child_done = new DLL();
$this->child_open = new DLL();
}
final function getDone() {
return new NodeIterator($this->child_done);
return $this->child_done->getIterator();
}
final function getOpen() {
return new NodeIterator($this->child_open);
return $this->child_open->getIterator();
}
final function hasOpen() {
return (sizeof($this->child_open) != 0);
#echo "hasOpen: ".$this->child_open->getSize()."<br>";
return ($this->child_open->getSize() != 0);
}
final function hasDone() {
return (sizeof($this->child_done) != 0);
#echo "hasDone: ".$this->child_done->getSize()."<br>";
return ($this->child_done->getSize() != 0);
}
final function addOpen($n) {
$this->child_open[] = $this->addChild($n);
final function addOpen($data) {
$this->child_open->addNode($data);
$this->addChild($data); #Parentum::addChild()
}
final function addDone($n) {
$this->child_done[] = $this->addChild($n);
final function addDone($data) {
$this->child_done->addNode($data);
$this->addChild($data); #Parentum::addChild()
}
final function setChildDone($idx) {
$this->addChildDone($idx);
$this->removeChildOpen($idx);
final function setChildDone($id) {
$this->addChildDone($id);
$this->removeChildOpen($id);
}
final function addChildDone($idx) {
echo "try adding done child: ".$idx;
if(!in_array($idx,$this->child_done)) {
$this->child_done[] = $idx;
echo " ... done<br>";
}
echo var_export($this->child_done,true);
final function setChildOpen($id) {
$this->addChildOpen($id);
$this->removeChildDone($id);
}
final function removeChildDone($idx) {
echo "try removing done child: ".$idx;
foreach($this->child_done as $key=>$elem) {
if($elem == $idx) {
unset($this->child_done[$key]);
echo " ... done<br>";
break;
}
}
echo var_export($this->child_done,true);
final function addChildDone($id) {
$data = $this->getChildDataByID($id);
$this->child_done->addNode($data);
}
final function setChildOpen($idx) {
$this->addChildOpen($idx);
$this->removeChildDone($idx);
final function addChildOpen($id) {
$data = $this->getChildDataByID($id);
$this->child_open->addNode($data);
}
final function addChildOpen($idx) {
echo "try adding open child: ".$idx;
if(!in_array($idx,$this->child_open)) {
$this->child_open[] = $idx;
echo " ... done<br>";
}
echo var_export($this->child_open,true);
final function removeChildDone($id) {
$this->child_done->removeNode($id);
}
final function removeChildOpen($idx) {
echo "try removing open child: ".$idx;
foreach($this->child_open as $key=>$elem) {
if($elem == $idx) {
unset($this->child_open[$key]);
echo " ... done<br>";
break;
}
}
echo var_export($this->child_open,true);
final function removeChildOpen($id) {
$this->child_open->removeNode($id);
}
#@OVERRIDE Parentum::removeChild()
function removeChild($id) {
$n = parent::removeChild($id);
if($n != false && $n != null) {
unset($this->child_open[$n->getIdx()]);
unset($this->child_done[$n->getIdx()]);
}
return $n;
parent::removeChild($id);
$this->child_open->removeNode($id);
$this->child_done->removeNode($id);
}
}
?>

View file

@ -1,17 +1,18 @@
<?php
class AchMenuNode extends Parentum {
use Node;
use InDev;
protected $parent_id;
protected $name;
protected $open;
protected $image;
protected $order;
protected $dev;
function AchMenuNode($data,$parent) {
global $DBc,$_USER;
parent::__construct();
$this->setParent($parent);
$this->setID($data['ac_id']);
$this->parent_id = $data['ac_parent'];
@ -26,10 +27,11 @@
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$res[$i]['open'] = $data['open'];
$this->nodes[] = $this->makeChild($res[$i]);
$this->addChild($this->makeChild($res[$i]));
}
}
#@override Parentum::makeChild()
protected function makeChild($a) {
return new AchMenuNode($a,$this);
}
@ -47,8 +49,10 @@
return $this->id;
}
foreach($this->nodes as $elem) {
$res = $elem->hasOpenCat();
$iter = $this->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
$res = $curr->hasOpenCat();
if($res != 0) {
return $res;
}
@ -67,13 +71,5 @@
function getOrder() {
return $this->order;
}
function inDev() { // check if dev flag is set
return ($this->dev == 1);
}
function getDev() {
return $this->dev;
}
}
?>

View file

@ -10,6 +10,8 @@
function AchMenu($open = false) {
global $DBc,$_USER;
parent::__construct();
$this->open = $open;
// the summary page is autogenerated and has no database entry. We add it manually here.
@ -29,6 +31,8 @@
$res[$i]['open'] = $open;
$this->addChild($this->makeChild($res[$i]));
}
#echo var_export($this->nodes->findNode(1),true);
}
function getOpen() { // just returns the previously set ID of the currently open MenuNode
@ -36,8 +40,10 @@
}
function getOpenCat() { // finds the currently open MenuNode and returns it's ID. If not found the result will be 0 instead.
foreach($this->nodes as $elem) {
$res = $elem->hasOpenCat();
$iter = $this->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
$res = $curr->hasOpenCat();
if($res != 0) {
return $res;
}
@ -45,6 +51,7 @@
return 0;
}
#@override Parentum::makeChild()
protected function makeChild($a) {
return new AchMenuNode($a,$this);
}

View file

@ -1,7 +1,5 @@
<?php
class AchObjective extends Parentum {
use Node;
protected $perk;
protected $condition;
protected $value;
@ -14,6 +12,8 @@
function AchObjective($data,$parent) {
global $DBc,$_USER;
parent::__construct();
$this->setParent($parent);
$this->setID($data['ao_id']);
$this->perk = $data['ao_perk'];
@ -32,6 +32,7 @@
}
}
#@override: Parentum::makeChild()
protected function makeChild($a) {
return null;
}

View file

@ -1,6 +1,6 @@
<?php
class AchPerk extends Parentum {
use Node,InDev;
use InDev;
protected $achievement;
protected $value;
@ -12,6 +12,8 @@
function AchPerk($data,$parent) {
global $DBc,$_USER;
parent::__construct();
$this->setParent($parent);
$this->setID($data['ap_id']);
$this->achievement = $data['ap_achievement'];
@ -29,6 +31,7 @@
}
}
#@override Parentum::makeChild()
protected function makeChild($a) {
return new AchObjective($a,$this);
}

View file

@ -6,6 +6,8 @@
function AchSummary(&$menu,$size = 10) {
global $DBc,$_USER;
parent::__construct();
$this->menu = $menu;
//read all recent perks of user
@ -21,6 +23,7 @@
#echo var_export($this->child_done,true);
}
#@override: Parentum::makeChild()
protected function makeChild($a) {
return new AchAchievement($a,$this);
}

View file

@ -0,0 +1,174 @@
<?php
class DLL {
private $first;
private $last;
private $size;
private $avl;
function DLL() {
$this->avl = new AVLTree();
$this->first = null;
$this->last = null;
$this->size = 0;
}
function getIterator() {
return new NodeIterator($this->first);
}
final function getSize() {
return $this->size;
}
final function isEmpty() {
return ($this->size == 0);
}
function getFirst() {
return $this->first;
}
function getLast() {
return $this->last;
}
function addNode($data,$before = null) {
if($this->findNode($data->getID()) != null) {
return false;
}
$n = new DLLnode($data);
if($before == null) {
//insert as last
if($this->last != null) {
$this->last->setChild($n);
}
$n->setParent($this->last);
$this->last = $n;
}
else {
//insert before
$b = $this->findNode($before);
if($b != null) {
if($b == $this->first) {
$this->first = $n;
}
$tmp = $b->getParent();
$b->setParent($n);
$n->setChild($b);
if($tmp != null) {
$tmp->setChild($n);
}
}
}
if($this->first == null) {
$this->first = $n;
}
$this->avl->insert($n);
$this->size++;
#$this->avl->inorder();
#echo "<br>";
}
function removeNode($id) {
echo "rid: ".$id."<br>";
$this->avl->inorder();
echo "<br>";
$n = $this->findNode($id);
if($n != null) {
echo "removed; ";
$p = $n->getParent();
$c = $n->getChild();
if($c != null) {
$c->setParent($p);
if($p != null) {
$p->setChild($c);
}
}
else {
if($p != null) {
$p->setChild(null);
}
$this->last = $p;
}
if($p == null) {
if($c != null) {
$c->setParent(null);
$this->first = $c;
}
else {
$this->first = null;
}
}
$this->avl->remove($id);
$this->size--;
}
$this->avl->inorder();
echo "<br>";
}
function findNode($id) {
return $this->avl->find($id);
}
/*function storeOrder() {
$iter = $this->getIterator();
$i = 0;
while($iter->hasNext()) {
$curr = $iter->getNext();
$curr->StoreOrder($i);
$i++;
}
}*/
}
class DLLnode {
private $parent;
private $child;
public $data;
function DLLNode($d) {
$this->parent = null;
$this->child = null;
$this->data = $d;
}
final function getParent() {
return $this->parent;
}
final function setParent($p) {
$this->parent = $p;
}
final function getChild() {
return $this->child;
}
final function setChild($c) {
$this->child = $c;
}
final function getIterator() {
return new NodeIterator($this);
}
#function ListStoreOrder($i) {
# $this->data->setListOrder($i);
# $this->data->update();
#}
function getID() {
return $this->data->getID();
}
}
?>

View file

@ -11,26 +11,37 @@
// ...
}
---------------------------*/
private $nodes;
private $curr;
private $node;
#private $curr;
function NodeIterator(&$nodes) {
$this->nodes = $nodes;
$this->curr = 0;
function NodeIterator($node) {
$this->node = $node;
#$this->curr = 0;
}
function hasNext() {
$tmp = array_keys($this->nodes);
return isset($this->nodes[$tmp[$this->curr]]);
#$tmp = array_keys($this->nodes);
#return isset($this->nodes[$tmp[$this->curr]]);
if($this->node == null) {
#echo "empty";
return false;
}
#if($this->node->getChild() == null) {
# return false;
#}
#echo "true";
return true;
}
function getNext() {
$tmp = array_keys($this->nodes);
return $this->nodes[$tmp[$this->curr++]];
}
function first() {
$this->curr = 0;
#$tmp = array_keys($this->nodes);
#return $this->nodes[$tmp[$this->curr++]];
$n = $this->node;
$this->node = $this->node->getChild();
return $n->data;
}
}
?>

View file

@ -1,31 +1,26 @@
<?php
trait Node {
abstract class Node {
/*---------------------------
This trait provides basic functionality common to nodes.
This class provides basic functionality common to nodes.
Every node has an id, and InDeX and a parent.
Every node has an id and a parent.
---------------------------*/
protected $idx;
protected $id;
protected $parent;
function Node() {
}
final function getID() {
return $this->id;
}
final function getIdx() {
return $this->idx;
}
final function getParent() {
return $this->parent;
}
final function setIdx($i) {
$this->idx = $i;
}
final function setID($id) {
$this->id = $id;
}

View file

@ -1,5 +1,5 @@
<?php
abstract class Parentum {
abstract class Parentum extends Node {
/*---------------------------
This class allows external access to the child-node list.
Use the NodeIterator to iterate through the list since
@ -9,80 +9,41 @@
functions removeChild() and findChild(). init() must be called
before adding any nodes!
---------------------------*/
protected $nodes = array();
protected $avl = null;
protected $nodes;
protected function init() {
#echo "init()";
$this->nodes = array();
$this->avl = new AVLTree();
function Parentum() {
parent::__construct();
$this->nodes = new DLL(); // Doubly Linked List
}
abstract protected function makeChild($args); // overwriteable child generator; allows to define child type (eg.: admin classes that inherit from base class)
final function getSize() {
return sizeof($this->nodes);
function isEmpty() {
return $this->nodes->isEmpty();
}
final function isEmpty() {
return (sizeof($this->nodes) == 0);
}
final function getIterator() {
return new NodeIterator($this->nodes);
}
final function addChild($n) {
$tmp = sizeof($this->nodes);
$n->setIdx($tmp);
$this->nodes[] = $n;
if($this->avl != null) {
$this->avl->insert($n);
}
return $tmp;
function addChild($data) {
$this->nodes->addNode($data);
}
function removeChild($id) {
if($this->isEmpty()) {
$this->nodes->removeNode($id);
}
function getChildByID($id) {
return $this->nodes->findNode($id);
}
function getChildDataByID($id) {
$tmp = $this->getChildByID($id);
if($tmp != null) {
return $tmp->data;
}
return null;
}
if($this->avl == null) {
return false;
}
$n = $this->avl->remove($id);
#echo var_export($n,true);
if($n != null) {
if($n->getIdx() != null) {
unset($this->nodes[$n->getIdx()]);
}
return $n;
}
return null;
}
final function getChildByID($id) {
if($this->isEmpty()) {
return null;
}
if($this->avl == null) {
return false;
}
#$this->avl->inorder();
return $this->avl->find($id);
}
final function getChildByIdx($idx) {
if($this->isEmpty()) {
return null;
}
return $this->nodes[$idx];
function getIterator() {
return $this->nodes->getIterator();
}
}
?>

View file

@ -24,7 +24,7 @@
$open = $menu->getOpenCat();
if($open != 0) {
$cat = new AchCategory($open,$_REQUEST['cult'],$_REQUEST['civ']);
$cat = new AchCategory($open,'matis',$_REQUEST['cult'],$_REQUEST['civ']);
}
else {
$cat = new AchSummary($menu,8);
@ -160,6 +160,7 @@
$iter = $menu->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
#$curr = $curr->data;
#$sz = $menu->getSize();
#for($i=0;$i<$sz;$i++) {
# $curr = $menu->getChild($i);
@ -195,7 +196,7 @@
$iter = $cat->getDone();
while($iter->hasNext()) {
$curr = $cat->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "A";
@ -207,7 +208,7 @@
$iter = $cat->getOpen();
while($iter->hasNext()) {
$curr = $cat->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "B";
@ -295,7 +296,7 @@
$html = "";
$perk_list = $ach->getOpen();
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
#$perk = $ach->getChild($perk_list[0]);
@ -319,7 +320,7 @@
$perk_list = $ach->getDone();
while($perk_list->hasNext()) {
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
#foreach($perk_list as $elem) {
#$perk = $ach->getChild($elem);
if($perk->inDev()) {

View file

@ -34,12 +34,15 @@ else {
}
require_once("include/ach_render_common.php");
require_once("class/DLL_class.php");
require_once("class/InDev_trait.php");
require_once("class/Node_abstract.php");
require_once("class/AVLTree_class.php");
require_once("class/Parentum_abstract.php");
require_once("class/AchList_abstract.php");
require_once("class/Tieable_inter.php");
require_once("class/NodeIterator_class.php");
require_once("class/Node_trait.php");
require_once("class/AchMenu_class.php");
require_once("class/AchMenuNode_class.php");

View file

@ -3,7 +3,6 @@
use AdmDispatcher;
function AdmAchievement($data,$parent) {
$this->init();
parent::__construct($data,$parent);
}

View file

@ -1,7 +1,5 @@
<?php
class AdmAtom implements ADM {
use Node;
class AdmAtom extends Node implements ADM {
protected $objective;
protected $mandatory;
protected $ruleset;

View file

@ -2,9 +2,8 @@
class AdmCategory extends AchCategory {
use AdmDispatcher;
function AdmCategory($id,$cult = null,$civ = null) {
$this->init();
parent::__construct($id,$cult,$civ);
function AdmCategory($id,$race,$cult = null,$civ = null) {
parent::__construct($id,$race,$cult,$civ);
}
protected function makeChild($d) {

View file

@ -23,7 +23,7 @@
}
function removeNode($id) {
$res = $this->getChildByID($id);
$res = $this->getChildDataByID($id);
if($res != null) {
$res->delete_me();
$this->removeChild($id);
@ -31,7 +31,7 @@
}
function updateNode($id) { // PROBABLY USELESS!
$res = $this->getChildByID($id);
$res = $this->getChildDataByID($id);
if($res != null) {
$res->update();
}
@ -53,7 +53,7 @@
$tmp = explode(";",$pid);
if($tmp[0] == $this->getID()) {
if(sizeof($tmp) > 1) {
$c = $this->getChildByID($tmp[1]);
$c = $this->getChildDataByID($tmp[1]);
if($c != null) {
unset($tmp[0]);
return $c->getElementByPath(implode(";",$tmp));

View file

@ -3,7 +3,6 @@
private $ach_count;
function AdmMenuNode($data,$parent) {
$this->init();
parent::__construct($data,$parent);
global $DBc;
@ -33,7 +32,7 @@
}
function getNode($id) { // try to find the child node that has the given ID. Return null on failure.
$res = $this->getChildByID($id);
$res = $this->getChildDataByID($id);
if($res != null) {
return $res;
}
@ -65,15 +64,6 @@
}
}
/*function unsetChild($id) { // remove child with given ID from nodes list; unset should destruct.
foreach($this->nodes as $key=>$elem) {
if($elem->getID() == $id) {
unset($this->nodes[$key]);
return null;
}
}
}*/
function insertChild(&$n) { // insert a new child
// insert command to create database entry
$n->insert();
@ -105,21 +95,6 @@
}
function setInDev($tf) {
if($tf == true) {
$this->setDev(1);
}
else {
$this->setDev(0);
}
$this->update();
}
private function setDev($d) {
$this->dev = $d;
}
private function setOrder($o) {
$this->order = $o;
$this->update();

View file

@ -3,7 +3,6 @@
use AdmDispatcher;
function AdmMenu($open) {
$this->init();
parent::__construct($open);
#$this->drawTree();
@ -65,7 +64,7 @@
function getNode($id) { // try to find the MenuNode that has the given ID. Return null on failure.
#echo "<br>getNode(".$id.")";
$res = $this->getChildByID($id);
$res = $this->getChildDataByID($id);
if($res != null) {
return $res;
}

View file

@ -3,7 +3,6 @@
use AdmDispatcher;
function AdmObjective($data,$parent) {
$this->init();
parent::__construct($data,$parent);
global $DBc;
@ -11,7 +10,7 @@
$res = $DBc->sqlQuery("SELECT atom_id FROM ach_atom WHERE atom_objective='".$this->getID()."'");
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$this->nodes[] = $this->makeChild($res[$i]);
$this->addChild($this->makeChild($res[$i]));
}
}

View file

@ -6,7 +6,6 @@
protected $condition_value;
function AdmPerk($data,$parent) {
$this->init();
parent::__construct($data,$parent);
$this->condition = $data["ap_condition"];

View file

@ -3,7 +3,6 @@
use CSRDispatcher;
function CSRAchievement($data,$parent) {
$this->init();
parent::__construct($data,$parent);
}
@ -16,10 +15,10 @@
while($iter->hasNext()) {
$curr = $iter->getNext();
$curr->grant($pid);
$this->setChildDone($curr->getIdx());
$this->setChildDone($curr->getID());
}
$this->parent->setChildDone($this->idx);
$this->parent->setChildDone($this->id);
}
function deny($pid) {
@ -27,34 +26,34 @@
while($iter->hasNext()) {
$curr = $iter->getNext();
$curr->deny($pid);
$this->setChildOpen($curr->getIdx());
$this->setChildOpen($curr->getID());
}
$this->parent->setChildOpen($this->idx);
$this->parent->setChildOpen($this->id);
}
function setPerkDone($idx) {
function setPerkDone($id) {
echo "perk<br>";
$this->setChildDone($idx);
$this->setChildDone($id);
echo "ach<br>";
$this->parent->addChildDone($this->idx);
$this->parent->addChildDone($this->id);
if(!$this->hasOpen()) {
$this->parent->removeChildOpen($this->idx);
$this->parent->removeChildOpen($this->id);
}
}
function setPerkOpen($idx) {
function setPerkOpen($id) {
echo "perk<br>";
$this->setChildOpen($idx);
$this->setChildOpen($id);
echo "ach<br>";
$this->parent->addChildOpen($this->idx);
$this->parent->addChildOpen($this->id);
if(!$this->hasDone()) {
$this->parent->removeChildDone($this->idx);
$this->parent->removeChildDone($this->id);
}
}
}

View file

@ -1,6 +1,5 @@
<?php
class CSRAtom implements CSR {
use Node;
class CSRAtom extends Node implements CSR {
function CSRAtom($data,$parent) {
$this->id = $data['atom_id'];

View file

@ -2,9 +2,8 @@
class CSRCategory extends AchCategory implements CSR {
use CSRDispatcher;
function CSRCategory($id,$cult = null,$civ = null) {
$this->init();
parent::__construct($id,$cult,$civ);
function CSRCategory($id,$race,$cult = null,$civ = null) {
parent::__construct($id,$race,$cult,$civ);
}
protected function makeChild($d) {
@ -16,7 +15,7 @@
}
function deny($id) {
return false; // category can't grant!
return false; // category can't deny!
}
/*function setAchOpen($idx,$state) {

View file

@ -13,7 +13,7 @@
//get child with the next level id and dispatch
$tmp = explode(";",$path);
$c = $this->getChildByID($tmp[1]);
$c = $this->getChildDataByID($tmp[1]);
#echo "...".$tmp[1];
if($c != null) { // check if it's really own child
unset($tmp[0]);
@ -37,7 +37,7 @@
if($tmp[0] == $this->getID()) { // it's my id!
$c = $this->getChildByID($tmp[1]);
$c = $this->getChildDataByID($tmp[1]);
if($c != null) { // check if it's really own child
unset($tmp[0]);
$c->denyNode(implode(";",$tmp),$player);

View file

@ -5,7 +5,6 @@
#private $nodes;
function CSRObjective($data,$parent) {
$this->init();
parent::__construct($data,$parent);
global $DBc;

View file

@ -3,7 +3,6 @@
use CSRDispatcher;
function CSRPerk($data,$parent) {
$this->init();
parent::__construct($data,$parent);
}
@ -17,7 +16,7 @@
$DBc->sqlQuery("INSERT INTO ach_player_perk (app_perk,app_player,app_date) VALUES ('".$this->getID()."','".$pid."','".time()."')");
$this->done = time();
#echo $this->idx."<br>";
$this->parent->setPerkDone($this->idx);
$this->parent->setPerkDone($this->id);
$iter = $this->getIterator();
while($iter->hasNext()) {
@ -31,7 +30,7 @@
$DBc->sqlQuery("DELETE FROM ach_player_perk WHERE app_perk='".$this->getID()."' AND app_player='".$pid."'");
$this->done = 0;
$this->parent->setPerkOpen($this->idx);
$this->parent->setPerkOpen($this->id);
$iter = $this->getIterator();
while($iter->hasNext()) {

View file

@ -174,7 +174,7 @@
$iter = $cat->getOpen();
while($iter->hasNext()) {
$curr = $cat->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "B";
@ -333,7 +333,7 @@
<option value='null' selected='selected'>[set as main perk]</option>";
$iter = $ach->getOpen();
while($iter->hasNext()) {
$curr = $ach->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
$html .= "<option value='".$curr->getID()."'>".$curr->getName()."</option>";
}
@ -416,7 +416,7 @@
$perk_list = $ach->getOpen();
while($perk_list->hasNext()) {
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
#$perk = $ach->getChild($perk_list[0]);
@ -466,7 +466,7 @@
$par = $perk->getParent();
$iter = $par->getOpen();
while($iter->hasNext()) {
$curr = $par->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
$html .= "<option value='".$curr->getID()."'>".$curr->getName()."</option>";
}
@ -555,7 +555,7 @@
$perk_list = $ach->getDone();
while($perk_list->hasNext()) {
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
#foreach($perk_list as $elem) {
#$perk = $ach->getChild($elem);
if($perk->inDev()) {
@ -588,7 +588,7 @@
#if(($i%2) == 1) {
# $html .= "</tr><tr>";
#}
$html .= "<td><center>".ach_render_obj_value($elem)."</center></td>";
$html .= "<td>".ach_render_obj_value($elem)."</td>";
#$i++;
break;
case "simple":
@ -601,7 +601,7 @@
#if(($i%2) == 1) {
# $html .= "</tr><tr>";
#}
$html .= "<td><center>".ach_render_obj_hidden($elem)."</center></td>";
$html .= "<td>".ach_render_obj_hidden($elem)."</td>";
#$i++;
break;
}

View file

@ -15,7 +15,7 @@
$res = $DBc->sqlQuery("SELECT sum(ap_value) as anz FROM ach_perk,ach_player_perk WHERE ap_id=app_perk AND app_player='".$_USER->getID()."'");
$html = "<div style='display:block;border-bottom:1px solid #000000;'><span style='font-size:32px;'>".$_USER->getName()."&nbsp;<img src='".$_CONF['image_url']."pic/yubo_done.png'>&nbsp;".$res[0]['anz']."</span></div>";
$html = "<div style='display:block;border-bottom:1px solid #000000;'><span style='font-size:32px;'>".$_USER->getName()."&nbsp;<img src='".$_CONF['image_url']."pic/yubo_done.png'>&nbsp;".max(0,$res[0]['anz'])."</span></div>";
return $html;
}
@ -132,9 +132,9 @@
}
$iter = $cat->getDone();
echo "<br>done: ".var_export($iter,true)."<br>";
while($iter->hasNext()) {
$curr = $cat->getChildByIdx($iter->getNext());
$curr = $iter->getNext();
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
@ -146,11 +146,10 @@
}
$iter = $cat->getOpen();
echo "<br>open: ".var_export($iter,true)."<br>";
while($iter->hasNext()) {
$tmp = $iter->getNext();
$curr = $cat->getChildByIdx($tmp);
echo "<b>".$tmp."-".$curr->getIdx()."</b><br>";
$curr = $iter->getNext();
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "B";
@ -238,10 +237,8 @@
$html = "";
$perk_list = $ach->getOpen();
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
echo "<b>".$ach->getIdx()."</b>";
echo "<br>".var_export($perk_list,true)."<br>";
#$perk = $ach->getChild($perk_list[0]);
@ -274,7 +271,7 @@
$perk_list = $ach->getDone();
while($perk_list->hasNext()) {
$perk = $ach->getChildByIdx($perk_list->getNext());
$perk = $perk_list->getNext();
#foreach($perk_list as $elem) {
#$perk = $ach->getChild($elem);
if($perk->inDev()) {

View file

@ -44,7 +44,7 @@
</div>";
if($_REQUEST['ac_id'] > 0 && $_REQUEST['confirm'] == "delete") {
$curr = $menu->getNode($_REQUEST['ac_id']);
$curr = $menu->getChildDataByID($_REQUEST['ac_id']);
$html .= "<div style='display:block;'>
<fieldset>
<legend>Are you sure you want to delete this category?</legend>";

View file

@ -36,12 +36,13 @@ require_once("class/mySQL_class.php");
#require_once("include/ach_render_csr.php");
require_once($_CONF['app_achievements_path']."include/ach_render_common.php");
require_once($_CONF['app_achievements_path']."class/DLL_class.php");
require_once($_CONF['app_achievements_path']."class/Node_abstract.php");
require_once($_CONF['app_achievements_path']."class/AVLTree_class.php");
require_once($_CONF['app_achievements_path']."class/Parentum_abstract.php");
require_once($_CONF['app_achievements_path']."class/AchList_abstract.php");
require_once($_CONF['app_achievements_path']."class/Tieable_inter.php");
require_once($_CONF['app_achievements_path']."class/NodeIterator_class.php");
require_once($_CONF['app_achievements_path']."class/Node_trait.php");
require_once($_CONF['app_achievements_path']."class/InDev_trait.php");
require_once($_CONF['app_achievements_path']."class/AchMenu_class.php");
@ -208,10 +209,10 @@ $c .= "</div></td>
$open = $menu->getOpenCat();
if($open != 0) {
$cat = new AdmCategory($open,$_REQUEST['cult'],$_REQUEST['civ']);
$cat = new AdmCategory($open,'',$_REQUEST['cult'],$_REQUEST['civ']);
if($_REQUEST['act'] == "ach_move") {
$ach = $cat->getChildByID($_REQUEST['id']);
$ach = $cat->getChildDataByID($_REQUEST['id']);
if($ach != null) {
$ach->setCategory($_REQUEST['new_cat']);
$ach->update();
@ -240,7 +241,7 @@ $c .= "</div></td>
}
if($_REQUEST['act'] == "ach_update") {
$ach = $cat->getChildByID($_REQUEST['id']);
$ach = $cat->getChildDataByID($_REQUEST['id']);
if($ach != null) {
$ach->setName($_REQUEST['aal_name']);
@ -254,7 +255,7 @@ $c .= "</div></td>
}
if($_REQUEST['act'] == "perk_insert") {
$ach = $cat->getChildByID($_REQUEST['id']);
$ach = $cat->getChildDataByID($_REQUEST['id']);
if($ach != null) {
$perk = new AdmPerk(array(),$ach);
$perk->setAchievement($ach->getID());