From d0c17c0c6518ed77efb294be3a96127795fe66f3 Mon Sep 17 00:00:00 2001 From: SirCotare Date: Sun, 8 Jul 2012 18:11:25 +0200 Subject: [PATCH] #1740 replaced child node lists with doubly linked lists; various minor changes --- .../app_achievements/class/AVLTree_class.php | 2 +- .../class/AchAchievement_class.php | 19 +- .../class/AchCategory_class.php | 38 ++-- .../class/AchList_abstract.php | 99 +++++----- .../class/AchMenuNode_class.php | 24 +-- .../app_achievements/class/AchMenu_class.php | 11 +- .../class/AchObjective_class.php | 7 +- .../app_achievements/class/AchPerk_class.php | 7 +- .../class/AchSummary_class.php | 5 +- .../app/app_achievements/class/DLL_class.php | 174 ++++++++++++++++++ .../class/NodeIterator_class.php | 37 ++-- .../{Node_trait.php => Node_abstract.php} | 19 +- .../class/Parentum_abstract.php | 83 +++------ .../include/ach_render_web.php | 11 +- code/web/app/app_achievements/index.php | 5 +- .../class/AdmAchievement_class.php | 1 - .../class/AdmAtom_class.php | 4 +- .../class/AdmCategory_class.php | 5 +- .../class/AdmDispatcher_trait.php | 6 +- .../class/AdmMenuNode_class.php | 27 +-- .../class/AdmMenu_class.php | 3 +- .../class/AdmObjective_class.php | 3 +- .../class/AdmPerk_class.php | 1 - .../class/CSRAchievement_class.php | 25 ++- .../class/CSRAtom_class.php | 3 +- .../class/CSRCategory_class.php | 7 +- .../class/CSRDispatcher_trait.php | 4 +- .../class/CSRObjective_class.php | 1 - .../class/CSRPerk_class.php | 5 +- .../include/adm_render_ach.php | 14 +- .../include/adm_render_csr.php | 19 +- .../include/adm_render_menu.php | 2 +- code/web/app/app_achievements_admin/index.php | 11 +- 33 files changed, 404 insertions(+), 278 deletions(-) create mode 100644 code/web/app/app_achievements/class/DLL_class.php rename code/web/app/app_achievements/class/{Node_trait.php => Node_abstract.php} (55%) diff --git a/code/web/app/app_achievements/class/AVLTree_class.php b/code/web/app/app_achievements/class/AVLTree_class.php index cf2270c3c..61944bde5 100644 --- a/code/web/app/app_achievements/class/AVLTree_class.php +++ b/code/web/app/app_achievements/class/AVLTree_class.php @@ -193,7 +193,7 @@ return $r; } - $p = $r->getLeft(); + $p = $r; while($p->getLeft() != null) { $p = $p->getLeft(); } diff --git a/code/web/app/app_achievements/class/AchAchievement_class.php b/code/web/app/app_achievements/class/AchAchievement_class.php index 7a1164e9e..e64a11c35 100644 --- a/code/web/app/app_achievements/class/AchAchievement_class.php +++ b/code/web/app/app_achievements/class/AchAchievement_class.php @@ -1,6 +1,6 @@ setParent($parent); $this->setID($data['aa_id']); @@ -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; diff --git a/code/web/app/app_achievements/class/AchCategory_class.php b/code/web/app/app_achievements/class/AchCategory_class.php index 7df1c8898..dd05b55d4 100644 --- a/code/web/app/app_achievements/class/AchCategory_class.php +++ b/code/web/app/app_achievements/class/AchCategory_class.php @@ -1,18 +1,27 @@ getRace(); + } if($cult == null) { $cult = $_USER->getCult(); @@ -27,41 +36,48 @@ $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']; $res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_achievement WHERE aa_tie_civ IS NOT NULL AND aa_category='".$this->id."'"); $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); diff --git a/code/web/app/app_achievements/class/AchList_abstract.php b/code/web/app/app_achievements/class/AchList_abstract.php index 4338173cb..eae3c3329 100644 --- a/code/web/app/app_achievements/class/AchList_abstract.php +++ b/code/web/app/app_achievements/class/AchList_abstract.php @@ -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()."
"; + return ($this->child_open->getSize() != 0); } final function hasDone() { - return (sizeof($this->child_done) != 0); + #echo "hasDone: ".$this->child_done->getSize()."
"; + 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
"; - } - 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
"; - 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
"; - } - 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
"; - 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); } } ?> \ No newline at end of file diff --git a/code/web/app/app_achievements/class/AchMenuNode_class.php b/code/web/app/app_achievements/class/AchMenuNode_class.php index a9112b855..2a47afbef 100644 --- a/code/web/app/app_achievements/class/AchMenuNode_class.php +++ b/code/web/app/app_achievements/class/AchMenuNode_class.php @@ -1,17 +1,18 @@ 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; - } } ?> \ No newline at end of file diff --git a/code/web/app/app_achievements/class/AchMenu_class.php b/code/web/app/app_achievements/class/AchMenu_class.php index dba0d18a8..60f21f17b 100644 --- a/code/web/app/app_achievements/class/AchMenu_class.php +++ b/code/web/app/app_achievements/class/AchMenu_class.php @@ -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); } diff --git a/code/web/app/app_achievements/class/AchObjective_class.php b/code/web/app/app_achievements/class/AchObjective_class.php index 90eebb865..2f5a38543 100644 --- a/code/web/app/app_achievements/class/AchObjective_class.php +++ b/code/web/app/app_achievements/class/AchObjective_class.php @@ -1,7 +1,5 @@ setParent($parent); $this->setID($data['ao_id']); @@ -31,7 +31,8 @@ $this->progress = $res[0]['anz']; } } - + + #@override: Parentum::makeChild() protected function makeChild($a) { return null; } diff --git a/code/web/app/app_achievements/class/AchPerk_class.php b/code/web/app/app_achievements/class/AchPerk_class.php index ccd16b51a..91d45e5b2 100644 --- a/code/web/app/app_achievements/class/AchPerk_class.php +++ b/code/web/app/app_achievements/class/AchPerk_class.php @@ -1,6 +1,6 @@ setParent($parent); $this->setID($data['ap_id']); @@ -28,7 +30,8 @@ $this->addChild($this->makeChild($res[$i])); } } - + + #@override Parentum::makeChild() protected function makeChild($a) { return new AchObjective($a,$this); } diff --git a/code/web/app/app_achievements/class/AchSummary_class.php b/code/web/app/app_achievements/class/AchSummary_class.php index cc6ac89f6..85ca43b37 100644 --- a/code/web/app/app_achievements/class/AchSummary_class.php +++ b/code/web/app/app_achievements/class/AchSummary_class.php @@ -6,6 +6,8 @@ function AchSummary(&$menu,$size = 10) { global $DBc,$_USER; + parent::__construct(); + $this->menu = $menu; //read all recent perks of user @@ -20,7 +22,8 @@ #echo var_export($this->child_done,true); } - + + #@override: Parentum::makeChild() protected function makeChild($a) { return new AchAchievement($a,$this); } diff --git a/code/web/app/app_achievements/class/DLL_class.php b/code/web/app/app_achievements/class/DLL_class.php new file mode 100644 index 000000000..c52ccd4d9 --- /dev/null +++ b/code/web/app/app_achievements/class/DLL_class.php @@ -0,0 +1,174 @@ +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 "
"; + } + + function removeNode($id) { + echo "rid: ".$id."
"; + $this->avl->inorder(); + echo "
"; + + $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 "
"; + } + + 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(); + } + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/class/NodeIterator_class.php b/code/web/app/app_achievements/class/NodeIterator_class.php index 1d939e5c4..fe71b44b0 100644 --- a/code/web/app/app_achievements/class/NodeIterator_class.php +++ b/code/web/app/app_achievements/class/NodeIterator_class.php @@ -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; } } ?> \ No newline at end of file diff --git a/code/web/app/app_achievements/class/Node_trait.php b/code/web/app/app_achievements/class/Node_abstract.php similarity index 55% rename from code/web/app/app_achievements/class/Node_trait.php rename to code/web/app/app_achievements/class/Node_abstract.php index d9bf1a42a..091e5b10d 100644 --- a/code/web/app/app_achievements/class/Node_trait.php +++ b/code/web/app/app_achievements/class/Node_abstract.php @@ -1,31 +1,26 @@ 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; } diff --git a/code/web/app/app_achievements/class/Parentum_abstract.php b/code/web/app/app_achievements/class/Parentum_abstract.php index 88c147cb4..09cb7b380 100644 --- a/code/web/app/app_achievements/class/Parentum_abstract.php +++ b/code/web/app/app_achievements/class/Parentum_abstract.php @@ -1,5 +1,5 @@ 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()) { - return null; + $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; } - - 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(); } } ?> \ No newline at end of file diff --git a/code/web/app/app_achievements/include/ach_render_web.php b/code/web/app/app_achievements/include/ach_render_web.php index 7101b2d64..0bac0107f 100644 --- a/code/web/app/app_achievements/include/ach_render_web.php +++ b/code/web/app/app_achievements/include/ach_render_web.php @@ -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()) { diff --git a/code/web/app/app_achievements/index.php b/code/web/app/app_achievements/index.php index af1e03b9c..726b8d047 100644 --- a/code/web/app/app_achievements/index.php +++ b/code/web/app/app_achievements/index.php @@ -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"); diff --git a/code/web/app/app_achievements_admin/class/AdmAchievement_class.php b/code/web/app/app_achievements_admin/class/AdmAchievement_class.php index 61898ae5a..3092a58b4 100644 --- a/code/web/app/app_achievements_admin/class/AdmAchievement_class.php +++ b/code/web/app/app_achievements_admin/class/AdmAchievement_class.php @@ -3,7 +3,6 @@ use AdmDispatcher; function AdmAchievement($data,$parent) { - $this->init(); parent::__construct($data,$parent); } diff --git a/code/web/app/app_achievements_admin/class/AdmAtom_class.php b/code/web/app/app_achievements_admin/class/AdmAtom_class.php index 86ddf3ec2..b75dbd6aa 100644 --- a/code/web/app/app_achievements_admin/class/AdmAtom_class.php +++ b/code/web/app/app_achievements_admin/class/AdmAtom_class.php @@ -1,7 +1,5 @@ init(); - parent::__construct($id,$cult,$civ); + function AdmCategory($id,$race,$cult = null,$civ = null) { + parent::__construct($id,$race,$cult,$civ); } protected function makeChild($d) { diff --git a/code/web/app/app_achievements_admin/class/AdmDispatcher_trait.php b/code/web/app/app_achievements_admin/class/AdmDispatcher_trait.php index 12f9bdc4d..65fd13663 100644 --- a/code/web/app/app_achievements_admin/class/AdmDispatcher_trait.php +++ b/code/web/app/app_achievements_admin/class/AdmDispatcher_trait.php @@ -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)); diff --git a/code/web/app/app_achievements_admin/class/AdmMenuNode_class.php b/code/web/app/app_achievements_admin/class/AdmMenuNode_class.php index dad7c8a38..05064d28c 100644 --- a/code/web/app/app_achievements_admin/class/AdmMenuNode_class.php +++ b/code/web/app/app_achievements_admin/class/AdmMenuNode_class.php @@ -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(); diff --git a/code/web/app/app_achievements_admin/class/AdmMenu_class.php b/code/web/app/app_achievements_admin/class/AdmMenu_class.php index d6debda0b..f646d0d3f 100644 --- a/code/web/app/app_achievements_admin/class/AdmMenu_class.php +++ b/code/web/app/app_achievements_admin/class/AdmMenu_class.php @@ -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 "
getNode(".$id.")"; - $res = $this->getChildByID($id); + $res = $this->getChildDataByID($id); if($res != null) { return $res; } diff --git a/code/web/app/app_achievements_admin/class/AdmObjective_class.php b/code/web/app/app_achievements_admin/class/AdmObjective_class.php index 4a40b9685..e75147fa9 100644 --- a/code/web/app/app_achievements_admin/class/AdmObjective_class.php +++ b/code/web/app/app_achievements_admin/class/AdmObjective_class.php @@ -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])); } } diff --git a/code/web/app/app_achievements_admin/class/AdmPerk_class.php b/code/web/app/app_achievements_admin/class/AdmPerk_class.php index 3a66585e0..21fbc0ca2 100644 --- a/code/web/app/app_achievements_admin/class/AdmPerk_class.php +++ b/code/web/app/app_achievements_admin/class/AdmPerk_class.php @@ -6,7 +6,6 @@ protected $condition_value; function AdmPerk($data,$parent) { - $this->init(); parent::__construct($data,$parent); $this->condition = $data["ap_condition"]; diff --git a/code/web/app/app_achievements_admin/class/CSRAchievement_class.php b/code/web/app/app_achievements_admin/class/CSRAchievement_class.php index e3f49b40c..2bcd2ad56 100644 --- a/code/web/app/app_achievements_admin/class/CSRAchievement_class.php +++ b/code/web/app/app_achievements_admin/class/CSRAchievement_class.php @@ -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
"; - $this->setChildDone($idx); + $this->setChildDone($id); echo "ach
"; - $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
"; - $this->setChildOpen($idx); + $this->setChildOpen($id); echo "ach
"; - $this->parent->addChildOpen($this->idx); + $this->parent->addChildOpen($this->id); if(!$this->hasDone()) { - $this->parent->removeChildDone($this->idx); + $this->parent->removeChildDone($this->id); } } } diff --git a/code/web/app/app_achievements_admin/class/CSRAtom_class.php b/code/web/app/app_achievements_admin/class/CSRAtom_class.php index 51a651c4b..398b7f283 100644 --- a/code/web/app/app_achievements_admin/class/CSRAtom_class.php +++ b/code/web/app/app_achievements_admin/class/CSRAtom_class.php @@ -1,6 +1,5 @@ id = $data['atom_id']; diff --git a/code/web/app/app_achievements_admin/class/CSRCategory_class.php b/code/web/app/app_achievements_admin/class/CSRCategory_class.php index 26a774803..6a118c6e3 100644 --- a/code/web/app/app_achievements_admin/class/CSRCategory_class.php +++ b/code/web/app/app_achievements_admin/class/CSRCategory_class.php @@ -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) { diff --git a/code/web/app/app_achievements_admin/class/CSRDispatcher_trait.php b/code/web/app/app_achievements_admin/class/CSRDispatcher_trait.php index b7618ae3e..6b373f177 100644 --- a/code/web/app/app_achievements_admin/class/CSRDispatcher_trait.php +++ b/code/web/app/app_achievements_admin/class/CSRDispatcher_trait.php @@ -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); diff --git a/code/web/app/app_achievements_admin/class/CSRObjective_class.php b/code/web/app/app_achievements_admin/class/CSRObjective_class.php index 0a9421d34..d336a2ade 100644 --- a/code/web/app/app_achievements_admin/class/CSRObjective_class.php +++ b/code/web/app/app_achievements_admin/class/CSRObjective_class.php @@ -5,7 +5,6 @@ #private $nodes; function CSRObjective($data,$parent) { - $this->init(); parent::__construct($data,$parent); global $DBc; diff --git a/code/web/app/app_achievements_admin/class/CSRPerk_class.php b/code/web/app/app_achievements_admin/class/CSRPerk_class.php index 3b68bd5ce..fcd8bd668 100644 --- a/code/web/app/app_achievements_admin/class/CSRPerk_class.php +++ b/code/web/app/app_achievements_admin/class/CSRPerk_class.php @@ -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."
"; - $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()) { diff --git a/code/web/app/app_achievements_admin/include/adm_render_ach.php b/code/web/app/app_achievements_admin/include/adm_render_ach.php index 50fc3b1b0..7b9f52d2a 100644 --- a/code/web/app/app_achievements_admin/include/adm_render_ach.php +++ b/code/web/app/app_achievements_admin/include/adm_render_ach.php @@ -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 @@ "; $iter = $ach->getOpen(); while($iter->hasNext()) { - $curr = $ach->getChildByIdx($iter->getNext()); + $curr = $iter->getNext(); $html .= ""; } @@ -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 .= ""; } @@ -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 .= ""; #} - $html .= "
".ach_render_obj_value($elem)."
"; + $html .= "".ach_render_obj_value($elem).""; #$i++; break; case "simple": @@ -601,7 +601,7 @@ #if(($i%2) == 1) { # $html .= ""; #} - $html .= "
".ach_render_obj_hidden($elem)."
"; + $html .= "".ach_render_obj_hidden($elem).""; #$i++; break; } diff --git a/code/web/app/app_achievements_admin/include/adm_render_csr.php b/code/web/app/app_achievements_admin/include/adm_render_csr.php index cb973d573..f6505a2f3 100644 --- a/code/web/app/app_achievements_admin/include/adm_render_csr.php +++ b/code/web/app/app_achievements_admin/include/adm_render_csr.php @@ -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 = "
".$_USER->getName()."  ".$res[0]['anz']."
"; + $html = "
".$_USER->getName()."  ".max(0,$res[0]['anz'])."
"; return $html; } @@ -132,9 +132,9 @@ } $iter = $cat->getDone(); - echo "
done: ".var_export($iter,true)."
"; + 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 "
open: ".var_export($iter,true)."
"; + while($iter->hasNext()) { - $tmp = $iter->getNext(); - $curr = $cat->getChildByIdx($tmp); - echo "".$tmp."-".$curr->getIdx()."
"; + $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 "".$ach->getIdx().""; - echo "
".var_export($perk_list,true)."
"; #$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()) { diff --git a/code/web/app/app_achievements_admin/include/adm_render_menu.php b/code/web/app/app_achievements_admin/include/adm_render_menu.php index 2e231bfff..d7fc5669d 100644 --- a/code/web/app/app_achievements_admin/include/adm_render_menu.php +++ b/code/web/app/app_achievements_admin/include/adm_render_menu.php @@ -44,7 +44,7 @@ "; if($_REQUEST['ac_id'] > 0 && $_REQUEST['confirm'] == "delete") { - $curr = $menu->getNode($_REQUEST['ac_id']); + $curr = $menu->getChildDataByID($_REQUEST['ac_id']); $html .= "
Are you sure you want to delete this category?"; diff --git a/code/web/app/app_achievements_admin/index.php b/code/web/app/app_achievements_admin/index.php index f95aff209..f4ee5685a 100644 --- a/code/web/app/app_achievements_admin/index.php +++ b/code/web/app/app_achievements_admin/index.php @@ -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 .= "
$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 .= " } 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 .= " } 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());