#1470 some minor rendering fixes; Parentum is now abstract class; various adaptations to allow admin functions to inherit from these base classes

This commit is contained in:
SirCotare 2012-06-24 12:44:24 +02:00
parent 6b3d10307b
commit f277821577
12 changed files with 116 additions and 95 deletions

View file

@ -53,7 +53,7 @@
#echo "X-".$this->hasOpen(); #echo "X-".$this->hasOpen();
} }
function makeChild(&$a) { protected function makeChild(&$a) {
return new AchPerk($a); return new AchPerk($a);
} }

View file

@ -54,7 +54,7 @@
$this->ties_civ_dev = $res[0]['anz']; $this->ties_civ_dev = $res[0]['anz'];
} }
function makeChild(&$a) { protected function makeChild(&$a) {
return new AchAchievement($a); return new AchAchievement($a);
} }

View file

@ -0,0 +1,81 @@
<?php
class AchMenuNode extends RenderNodeIterator {
protected $id;
protected $parent_id;
protected $name;
protected $open;
protected $image;
protected $order;
protected $dev;
function AchMenuNode(&$data) {
global $DBc,$_USER;
$this->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;
}
}
?>

View file

@ -1,19 +1,26 @@
<?php <?php
class AchMenu extends RenderNodeIterator { class AchMenu extends RenderNodeIterator {
var $open; /*---------------------------
This class is the dispatcher for actual MenuNodes.
Since every MenuNode will only keep a list of it's children,
we have to handle the main nodes which have no parent this way.
---------------------------*/
protected $open;
function AchMenu($open = false) { function AchMenu($open = false) {
global $DBc,$_USER; global $DBc,$_USER;
$this->open = $open; $this->open = $open;
// the summary page is autogenerated and has no database entry. We add it manually here.
$tmp = array(); $tmp = array();
$tmp['ac_id'] = 0; $tmp['ac_id'] = 0;
$tmp['ac_parent'] = null; $tmp['ac_parent'] = null;
$tmp['acl_name'] = get_translation('ach_summary',$_USER->getLang()); $tmp['acl_name'] = get_translation('ach_summary',$_USER->getLang());
$tmp['ac_image'] = "test.png"; $tmp['ac_image'] = "test.png";
$tmp['ac_order'] = -1; $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"); $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; 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) { foreach($this->nodes as $elem) {
$res = $elem->hasOpenCat(); $res = $elem->hasOpenCat();
if($res != 0) { if($res != 0) {
@ -38,83 +45,8 @@
return 0; return 0;
} }
function makeChild(&$a) { protected function makeChild(&$a) {
return new AchMenuNode($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);
}
}
?> ?>

View file

@ -1,5 +1,5 @@
<?php <?php
class AchObjective { class AchObjective extends Parentum {
private $id; private $id;
private $perk; private $perk;
private $condition; private $condition;
@ -25,11 +25,15 @@
$this->progress = $this->value; $this->progress = $this->value;
if(!$this->isDone()) { 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']; $this->progress = $res[0]['anz'];
} }
} }
protected function makeChild(&$a) {
return null;
}
function getMetaImage() { function getMetaImage() {
return $this->meta_image; return $this->meta_image;
} }

View file

@ -26,7 +26,7 @@
} }
} }
function makeChild(&$a) { protected function makeChild(&$a) {
return new AchObjective($a); return new AchObjective($a);
} }

View file

@ -22,7 +22,7 @@
} }
} }
function makeChild(&$a) { protected function makeChild(&$a) {
return new AchAchievement($a); return new AchAchievement($a);
} }

View file

@ -0,0 +1,5 @@
<?php
abstract class Parentum {
abstract protected function makeChild(&$args);
}
?>

View file

@ -1,5 +0,0 @@
<?php
interface Parentum {
function makeChild(&$a);
}
?>

View file

@ -1,5 +1,5 @@
<?php <?php
abstract class RenderNodeIterator implements Parentum { abstract class RenderNodeIterator extends Parentum {
protected $nodes = array(); protected $nodes = array();
function getSize() { function getSize() {

View file

@ -138,8 +138,11 @@
if($curr->inDev()) { if($curr->inDev()) {
continue; continue;
} }
$html .= "<tr><td></td><td bgcolor='#000000'></td></tr> if($sub == 0) {
<tr><td>"; $html .= "<tr><td></td><td bgcolor='#000000'></td></tr>";
}
$html .= "<tr><td>";
if($sub == 0) { if($sub == 0) {
$html .= "<img src='".$_CONF['image_url']."pic/menu/ig_".$curr->getImage()."' />"; $html .= "<img src='".$_CONF['image_url']."pic/menu/ig_".$curr->getImage()."' />";
} }

View file

@ -33,13 +33,14 @@ else {
} }
require_once("include/ach_render_common.php"); 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/RenderNodeIteraor_abstract.php");
require_once("class/AchList_abstract.php"); require_once("class/AchList_abstract.php");
require_once("class/Tieable_inter.php"); require_once("class/Tieable_inter.php");
require_once("class/AchMenu_class.php"); require_once("class/AchMenu_class.php");
require_once("class/AchMenuNode_class.php");
require_once("class/AchSummary_class.php"); require_once("class/AchSummary_class.php");
require_once("class/AchCategory_class.php"); require_once("class/AchCategory_class.php");
require_once("class/AchAchievement_class.php"); require_once("class/AchAchievement_class.php");