From 899e5a90d37a225e27d726a5a22f55cf5cbcb15f Mon Sep 17 00:00:00 2001 From: SirCotare Date: Sun, 24 Jun 2012 12:44:24 +0200 Subject: [PATCH] #1470 some minor rendering fixes; Parentum is now abstract class; various adaptations to allow admin functions to inherit from these base classes --- .../class/AchAchievement_class.php | 2 +- .../class/AchCategory_class.php | 2 +- .../class/AchMenuNode_class.php | 81 ++++++++++++++++ .../app_achievements/class/AchMenu_class.php | 92 +++---------------- .../class/AchObjective_class.php | 8 +- .../app_achievements/class/AchPerk_class.php | 2 +- .../class/AchSummary_class.php | 2 +- .../class/Parentum_abstract.php | 5 + .../app_achievements/class/Parentum_inter.php | 5 - .../class/RenderNodeIteraor_abstract.php | 2 +- .../include/ach_render_ig.php | 7 +- code/web/app/app_achievements/index.php | 3 +- 12 files changed, 116 insertions(+), 95 deletions(-) create mode 100644 code/web/app/app_achievements/class/AchMenuNode_class.php create mode 100644 code/web/app/app_achievements/class/Parentum_abstract.php delete mode 100644 code/web/app/app_achievements/class/Parentum_inter.php diff --git a/code/web/app/app_achievements/class/AchAchievement_class.php b/code/web/app/app_achievements/class/AchAchievement_class.php index a28caf1ae..5d48d7b11 100644 --- a/code/web/app/app_achievements/class/AchAchievement_class.php +++ b/code/web/app/app_achievements/class/AchAchievement_class.php @@ -53,7 +53,7 @@ #echo "X-".$this->hasOpen(); } - function makeChild(&$a) { + protected function makeChild(&$a) { return new AchPerk($a); } diff --git a/code/web/app/app_achievements/class/AchCategory_class.php b/code/web/app/app_achievements/class/AchCategory_class.php index 86b6715dc..55ef42c0f 100644 --- a/code/web/app/app_achievements/class/AchCategory_class.php +++ b/code/web/app/app_achievements/class/AchCategory_class.php @@ -54,7 +54,7 @@ $this->ties_civ_dev = $res[0]['anz']; } - function makeChild(&$a) { + protected function makeChild(&$a) { return new AchAchievement($a); } diff --git a/code/web/app/app_achievements/class/AchMenuNode_class.php b/code/web/app/app_achievements/class/AchMenuNode_class.php new file mode 100644 index 000000000..8d90632ae --- /dev/null +++ b/code/web/app/app_achievements/class/AchMenuNode_class.php @@ -0,0 +1,81 @@ +id = $data['ac_id']; + $this->parent_id = $data['ac_parent']; + $this->name = $data['acl_name']; + $this->image = $data['ac_image']; + $this->order = $data['ac_order']; + $this->open = ($this->id == $data['open']); + $this->dev = $data['ac_dev']; + + $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"); + + $sz = sizeof($res); + for($i=0;$i<$sz;$i++) { + $res[$i]['open'] = $data['open']; + $this->nodes[] = $this->makeChild($res[$i]); + } + } + + protected function makeChild(&$a) { + return new AchMenuNode($a); + } + + function getID() { + return $this->id; + } + + function getName() { + return $this->name; + } + + function getParentID() { + return $this->parent_id; + } + + function hasOpenCat() { // finds the currently open MenuNode and returns it's ID. If not found the result will be 0 instead. + if($this->open) { + return $this->id; + } + + foreach($this->nodes as $elem) { + $res = $elem->hasOpenCat(); + if($res != 0) { + return $res; + } + } + return 0; + } + + function isOpen() { + return $this->open; + } + + function getImage() { + return $this->image; + } + + 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 1b5c384d1..a28e807cc 100644 --- a/code/web/app/app_achievements/class/AchMenu_class.php +++ b/code/web/app/app_achievements/class/AchMenu_class.php @@ -1,19 +1,26 @@ open = $open; + // the summary page is autogenerated and has no database entry. We add it manually here. $tmp = array(); $tmp['ac_id'] = 0; $tmp['ac_parent'] = null; $tmp['acl_name'] = get_translation('ach_summary',$_USER->getLang()); $tmp['ac_image'] = "test.png"; $tmp['ac_order'] = -1; - $this->nodes[] = new AchMenuNode($tmp,$open); + $tmp['open'] = $open; + $this->nodes[] = new AchMenuNode($tmp); $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"); @@ -24,11 +31,11 @@ } } - function getOpen() { + function getOpen() { // just returns the previously set ID of the currently open MenuNode return $this->open; } - function getOpenCat() { + 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(); if($res != 0) { @@ -38,83 +45,8 @@ return 0; } - function makeChild(&$a) { + protected function makeChild(&$a) { return new AchMenuNode($a); } } - - class AchMenuNode extends RenderNodeIterator { - private $id; - private $parent; - private $name; - private $open; - private $image; - private $order; - - function AchMenuNode(&$data) { - global $DBc,$_USER; - - $this->id = $data['ac_id']; - $this->parent = $data['ac_parent']; - $this->name = $data['acl_name']; - $this->image = $data['ac_image']; - $this->order = $data['ac_order']; - $this->open = ($this->id == $data['open']); - $this->dev = $data['ac_dev']; - - $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"); - - $sz = sizeof($res); - for($i=0;$i<$sz;$i++) { - $res[$i]['open'] = $open; - $this->nodes[] = $this->makeChild($res[$i]); - } - } - - function makeChild(&$a) { - return new AchMenuNode($a); - } - - function getID() { - return $this->id; - } - - function getName() { - return $this->name; - } - - function getParent() { - return $this->parent; - } - - function hasOpenCat() { - if($this->open) { - return $this->id; - } - - foreach($this->nodes as $elem) { - $res = $elem->hasOpenCat(); - if($res != 0) { - return $res; - } - } - return 0; - } - - function isOpen() { - return $this->open; - } - - function getImage() { - return $this->image; - } - - function getOrder() { - return $this->order; - } - - function inDev() { - return ($this->dev == 1); - } - } ?> \ No newline at end of file diff --git a/code/web/app/app_achievements/class/AchObjective_class.php b/code/web/app/app_achievements/class/AchObjective_class.php index f58849742..47c946381 100644 --- a/code/web/app/app_achievements/class/AchObjective_class.php +++ b/code/web/app/app_achievements/class/AchObjective_class.php @@ -1,5 +1,5 @@ progress = $this->value; if(!$this->isDone()) { - $res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_player_atom,ach_atom WHERE apa_atom=atom_id AND atom_objective='".$this->id."' AND apa_player='".$_USER->getId()."'"); + $res = $DBc->sqlQuery("SELECT count(*) as anz FROM ach_player_atom,ach_atom WHERE apa_atom=atom_id AND atom_objective='".$this->id."' AND apa_player='".$_USER->getID()."'"); $this->progress = $res[0]['anz']; } } + protected function makeChild(&$a) { + return null; + } + function getMetaImage() { return $this->meta_image; } diff --git a/code/web/app/app_achievements/class/AchPerk_class.php b/code/web/app/app_achievements/class/AchPerk_class.php index 20ca91b0c..15c9547ec 100644 --- a/code/web/app/app_achievements/class/AchPerk_class.php +++ b/code/web/app/app_achievements/class/AchPerk_class.php @@ -26,7 +26,7 @@ } } - function makeChild(&$a) { + protected function makeChild(&$a) { return new AchObjective($a); } diff --git a/code/web/app/app_achievements/class/AchSummary_class.php b/code/web/app/app_achievements/class/AchSummary_class.php index 2aee31dfc..db1d51978 100644 --- a/code/web/app/app_achievements/class/AchSummary_class.php +++ b/code/web/app/app_achievements/class/AchSummary_class.php @@ -22,7 +22,7 @@ } } - function makeChild(&$a) { + protected function makeChild(&$a) { return new AchAchievement($a); } diff --git a/code/web/app/app_achievements/class/Parentum_abstract.php b/code/web/app/app_achievements/class/Parentum_abstract.php new file mode 100644 index 000000000..25b476535 --- /dev/null +++ b/code/web/app/app_achievements/class/Parentum_abstract.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/code/web/app/app_achievements/class/Parentum_inter.php b/code/web/app/app_achievements/class/Parentum_inter.php deleted file mode 100644 index 2a206996d..000000000 --- a/code/web/app/app_achievements/class/Parentum_inter.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/code/web/app/app_achievements/class/RenderNodeIteraor_abstract.php b/code/web/app/app_achievements/class/RenderNodeIteraor_abstract.php index 4b8fd55b1..5fad955b8 100644 --- a/code/web/app/app_achievements/class/RenderNodeIteraor_abstract.php +++ b/code/web/app/app_achievements/class/RenderNodeIteraor_abstract.php @@ -1,5 +1,5 @@ inDev()) { continue; } - $html .= " - "; + if($sub == 0) { + $html .= ""; + } + + $html .= ""; if($sub == 0) { $html .= "getImage()."' />"; } diff --git a/code/web/app/app_achievements/index.php b/code/web/app/app_achievements/index.php index c47ffab38..a315f70d9 100644 --- a/code/web/app/app_achievements/index.php +++ b/code/web/app/app_achievements/index.php @@ -33,13 +33,14 @@ else { } require_once("include/ach_render_common.php"); -require_once("class/Parentum_inter.php"); +require_once("class/Parentum_abstract.php"); require_once("class/RenderNodeIteraor_abstract.php"); require_once("class/AchList_abstract.php"); require_once("class/Tieable_inter.php"); require_once("class/AchMenu_class.php"); +require_once("class/AchMenuNode_class.php"); require_once("class/AchSummary_class.php"); require_once("class/AchCategory_class.php"); require_once("class/AchAchievement_class.php");