#1470 major update; these changes were necessary for the admin tool; currently untested - need new testserver with php 5.4

--HG--
branch : gsoc2012-achievements
This commit is contained in:
SirCotare 2012-06-25 15:03:14 +02:00
parent a874eb6f04
commit a3d40de283
15 changed files with 309 additions and 196 deletions

View file

@ -1,21 +1,23 @@
<?php
class AchAchievement extends AchList {
private $id;
private $parent;
private $category;
private $tie_race;
private $tie_civ;
private $tie_cult;
private $image;
private $name;
private $template;
private $dev;
use Node;
function AchAchievement(&$data) {
protected $parent_id;
protected $category;
protected $tie_race;
protected $tie_civ;
protected $tie_cult;
protected $image;
protected $name;
protected $template;
protected $dev;
function AchAchievement($data,$parent) {
global $DBc,$_USER;
$this->id = $data['aa_id'];
$this->parent = $data['aa_parent'];
$this->setParent($parent);
$this->setID($data['aa_id']);
$this->parent_id = $data['aa_parent'];
$this->category = $data['aa_category'];
$this->tie_race = $data['aa_tie_race'];
$this->tie_civ = $data['aa_tie_civ'];
@ -25,44 +27,27 @@
$this->template = $data['aal_template'];
$this->dev = $data['aa_dev'];
#echo $this->id;
$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++) {
#echo "Z";
$res[$i]['this'] = $this;
$tmp = $this->makeChild($res[$i]);
#echo var_export($tmp,true);
if($tmp->isDone()) {
$this->child_done[] = sizeof($this->nodes);
$this->addDone($tmp);
}
else {
$this->child_open[] = sizeof($this->nodes);
$this->addOpen($tmp);
}
}
$this->nodes[] = $tmp;
#MISSING: divide into groups -> open/done
}
#echo var_export($this->child_open,true);
#echo "X-".$this->hasOpen();
protected function makeChild($a) {
return new AchPerk($a,$this);
}
protected function makeChild(&$a) {
return new AchPerk($a);
}
function getID() {
return $this->id;
}
function getParent() {
return $this->parent;
function getParentID() {
return $this->parent_id;
}
function getTieRace() {
@ -87,14 +72,21 @@
function getValueDone() {
$val = 0;
foreach($this->child_done as $elem) {
$val += $this->nodes[$elem]->getValue();
$iter = $this->getDone();
while($iter->hasNext()) {
$curr = $this->findNodeIdx($iter->getNext());
$val += $curr->getValue();
}
return $val;
}
function getValueOpen() {
return $this->nodes[$this->child_open[0]]->getValue();
$iter = $this->getDone();
if($iter->hasNext()) {
$curr = $this->findNodeIdx($iter->getNext());
return $curr->getValue();
}
return 0;
}
function getTemplate($insert = array()) {

View file

@ -1,12 +1,12 @@
<?php
class AchCategory extends AchList implements Tieable {
private $id = false;
private $ties_cult;
private $ties_civ;
private $ties_cult_dev;
private $ties_civ_dev;
private $cult;
private $civ;
protected $id;
protected $ties_cult;
protected $ties_civ;
protected $ties_cult_dev;
protected $ties_civ_dev;
protected $cult;
protected $civ;
function AchCategory($id,$cult = null,$civ = null) {
global $DBc,$_USER;
@ -28,17 +28,14 @@
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
#echo "Y";
$tmp = $this->makeChild($res[$i]);
#echo var_export($tmp,true);
if($tmp->hasOpen()) {
$this->child_open[] = sizeof($this->nodes);
$this->addOpen($tmp);
}
if($tmp->hasDone()) {
$this->child_done[] = sizeof($this->nodes);
$this->addDone($tmp);
}
$this->nodes[] = $tmp;
}
$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'");
@ -54,8 +51,8 @@
$this->ties_civ_dev = $res[0]['anz'];
}
protected function makeChild(&$a) {
return new AchAchievement($a);
protected function makeChild($a) {
return new AchAchievement($a,$this);
}
function getID() {

View file

@ -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);
}
}
}
?>

View file

@ -1,6 +1,7 @@
<?php
class AchMenuNode extends RenderNodeIterator {
protected $id;
class AchMenuNode extends Parentum {
use Node;
protected $parent_id;
protected $name;
protected $open;
@ -8,10 +9,11 @@
protected $order;
protected $dev;
function AchMenuNode(&$data) {
function AchMenuNode($data,$parent) {
global $DBc,$_USER;
$this->id = $data['ac_id'];
$this->setParent($parent);
$this->setID($data['ac_id']);
$this->parent_id = $data['ac_parent'];
$this->name = $data['acl_name'];
$this->image = $data['ac_image'];
@ -28,12 +30,8 @@
}
}
protected function makeChild(&$a) {
return new AchMenuNode($a);
}
function getID() {
return $this->id;
protected function makeChild($a) {
return new AchMenuNode($a,$this);
}
function getName() {

View file

@ -1,5 +1,5 @@
<?php
class AchMenu extends RenderNodeIterator {
class AchMenu extends Parentum {
/*---------------------------
This class is the dispatcher for actual MenuNodes.
Since every MenuNode will only keep a list of it's children,
@ -20,7 +20,7 @@
$tmp['ac_image'] = "test.png";
$tmp['ac_order'] = -1;
$tmp['open'] = $open;
$this->nodes[] = new AchMenuNode($tmp);
$this->nodes[] = new AchMenuNode($tmp,$this);
$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");
@ -45,8 +45,8 @@
return 0;
}
protected function makeChild(&$a) {
return new AchMenuNode($a);
protected function makeChild($a) {
return new AchMenuNode($a,$this);
}
}
?>

View file

@ -1,19 +1,21 @@
<?php
class AchObjective extends Parentum {
private $id;
private $perk;
private $condition;
private $value;
private $name;
private $display;
private $done;
private $progress;
private $meta_image;
use Node;
function AchObjective(&$data) {
protected $perk;
protected $condition;
protected $value;
protected $name;
protected $display;
protected $done;
protected $progress;
protected $meta_image;
function AchObjective($data,$parent) {
global $DBc,$_USER;
$this->id = $data['ao_id'];
$this->setParent($parent);
$this->setID($data['ao_id']);
$this->perk = $data['ao_perk'];
$this->condition = $data['ao_condition'];
$this->value = $data['ao_value'];
@ -30,7 +32,7 @@
}
}
protected function makeChild(&$a) {
protected function makeChild($a) {
return null;
}
@ -38,10 +40,6 @@
return $this->meta_image;
}
function getID() {
return $this->id;
}
function getPerk() {
return $this->perk;
}

View file

@ -1,18 +1,18 @@
<?php
class AchPerk extends RenderNodeIterator {
private $id;
private $parent;
private $achievement;
private $value;
private $name;
private $done;
private $dev;
class AchPerk extends Parentum {
use Node;
function AchPerk(&$data) {
protected $achievement;
protected $value;
protected $name;
protected $done;
protected $dev;
function AchPerk($data,$parent) {
global $DBc,$_USER;
$this->id = $data['ap_id'];
$this->parent = $data['this'];
$this->setParent($parent);
$this->setID($data['ap_id']);
$this->achievement = $data['ap_achievement'];
$this->value = $data['ap_value'];
$this->name = $data['apl_name'];
@ -22,20 +22,12 @@
$res = $DBc->sqlQuery("SELECT * FROM ach_objective LEFT JOIN (ach_objective_lang) ON (aol_lang='".$_USER->getLang()."' AND aol_objective=ao_id) LEFT JOIN (ach_player_objective) ON (apo_objective=ao_id AND apo_player='".$_USER->getID()."') LEFT JOIN (ach_achievement) ON (aa_id=ao_metalink) WHERE ao_perk='".$this->id."'");
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$this->nodes[] = $this->makeChild($res[$i]);
$this->addChild($this->makeChild($res[$i]));
}
}
protected function makeChild(&$a) {
return new AchObjective($a);
}
function getID() {
return $this->id;
}
function getParent() {
return $this->parent;
protected function makeChild($a) {
return new AchObjective($a,$this);
}
function getAchievement() {
@ -51,11 +43,14 @@
}
function objDrawable() {
foreach($this->nodes as $elem) {
if($elem->getDisplay() != "hidden") {
$iter = $this->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
if($curr->getDisplay() != "hidden") {
return true;
}
}
return false;
}

View file

@ -15,15 +15,12 @@
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$tmp = $this->makeChild($res[$i]);
$this->child_done[] = sizeof($this->nodes);
$this->nodes[] = $tmp;
$this->addDone($this->makeChild($res[$i]));
}
}
protected function makeChild(&$a) {
return new AchAchievement($a);
protected function makeChild($a) {
return new AchAchievement($a,$this);
}
function getSummary() {
@ -32,13 +29,15 @@
//and also sum up how many have been completed
$this->stats = array(); // [][name,done,total]
$tmp = $this->menu->getChildren();
foreach($tmp as $elem) {
if($elem->getID() == 0 || $elem->inDev()) {
$iter = $this->menu->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
if($curr->getID() == 0 || $curr->inDev()) {
continue; // skip summary page
}
$res = $this->sumStats($elem);
$this->stats[] = array($elem->getName(),$res[0],$res[1]);
$res = $this->sumStats($curr);
$this->stats[] = array($curr->getName(),$res[0],$res[1]);
}
}
@ -59,8 +58,10 @@
$res = $DBc->sqlQuery("SELECT count(ap_id) as anz FROM ach_perk,ach_achievement WHERE aa_category='".$node->getID()."' AND ap_achievement=aa_id AND aa_dev='0' AND ap_dev='0'");
$total += $res[0]["anz"];
$tmp = $node->getChildren();
foreach($tmp as $elem) {
$iter = $node->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
$res = $this->sumStats($elem);
$done += $res[0];
$total += $res[1];

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -132,9 +132,13 @@
if($sub == 0) {
$html = "<table cellpadding='2px'>";
}
$sz = $menu->getSize();
for($i=0;$i<$sz;$i++) {
$curr = $menu->getChild($i);
$iter = $menu->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
#$sz = $menu->getSize();
#for($i=0;$i<$sz;$i++) {
#$curr = $menu->getChild($i);
if($curr->inDev()) {
continue;
}
@ -176,24 +180,28 @@
$html .= ach_render_tiebar($cat->getCurrentCult(),$cat->getCurrentCiv(),$cat);
}
$tmp = $cat->getDone();
$sz = sizeof($tmp);
for($i=0;$i<$sz;$i++) {
$iter = $cat->getDone();
while($iter->hasNext()) {
$curr = $cat->findNodeIdx($iter->getNext());
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "A";
if($cat->getChild($tmp[$i])->inDev()) {
if($curr->inDev()) {
continue;
}
$html .= ach_render_achievement_done($cat->getChild($tmp[$i]));
$html .= ach_render_achievement_done($curr);
}
$tmp = $cat->getOpen();
$sz = sizeof($tmp);
for($i=0;$i<$sz;$i++) {
$iter = $cat->getOpen();
while($iter->hasNext()) {
$curr = $cat->findNodeIdx($iter->getNext());
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "B";
if($cat->getChild($tmp[$i])->inDev()) {
if($curr->inDev()) {
continue;
}
$html .= ach_render_achievement_open($cat->getChild($tmp[$i]));
$html .= ach_render_achievement_open($curr));
}
return $html;
@ -251,8 +259,7 @@
$html = "";
$perk_list = $ach->getOpen();
$perk = $ach->getChild($perk_list[0]);
$perk = $ach->findNodeIdx($perk_list->getNext());
if($perk->inDev()) {
return $html;
@ -273,9 +280,11 @@
$html = "";
$perk_list = $ach->getDone();
while($perk_list->hasNext()) {
$perk = $this->findNodeIdx($perk_list->getNext());
foreach($perk_list as $elem) {
$perk = $ach->getChild($elem);
#foreach($perk_list as $elem) {
#$perk = $ach->getChild($elem);
if($perk->inDev()) {
continue;
}
@ -291,7 +300,9 @@
$i = 0;
$skip = false;
foreach($obj as $elem) {
while($obj->hasNext()) {
#foreach($obj as $elem) {
$elem = $obj->getNext();
if(($i%2) == 0) {
$html .= "<tr>";
}

View file

@ -134,8 +134,6 @@
}
function ach_render_menu(&$menu,$sub = 0) {
global $_CONF;
$html = "<style>
.ach_menu {
display:block;
@ -153,9 +151,18 @@
}
</style>";
$sz = $menu->getSize();
for($i=0;$i<$sz;$i++) {
$curr = $menu->getChild($i);
return $html.ach_render_mnode($menu,$sub);
}
function ach_render_mnode(&$menu,$sub) {
global $_CONF;
$iter = $menu->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
#$sz = $menu->getSize();
#for($i=0;$i<$sz;$i++) {
# $curr = $menu->getChild($i);
if($curr->inDev()) {
continue;
}
@ -172,7 +179,7 @@
</tr>
</table></a></span>";
if($curr->hasOpenCat() != 0) {
$html .= "<div style='display:block;margin-left:25px;'>".ach_render_menu($curr,($sub+4))."</div>";
$html .= "<div style='display:block;margin-left:25px;'>".ach_render_mnode($curr,($sub+4))."</div>";
}
}
@ -186,24 +193,28 @@
$html .= ach_render_tiebar($cat->getCurrentCult(),$cat->getCurrentCiv(),$cat);
}
$tmp = $cat->getDone();
$sz = sizeof($tmp);
for($i=0;$i<$sz;$i++) {
$iter = $cat->getDone();
while($iter->hasNext()) {
$curr = $cat->findNodeIdx($iter->getNext());
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "A";
if($cat->getChild($tmp[$i])->inDev()) {
if($curr->inDev()) {
continue;
}
$html .= ach_render_achievement_done($cat->getChild($tmp[$i]));
$html .= ach_render_achievement_done($curr);
}
$tmp = $cat->getOpen();
$sz = sizeof($tmp);
for($i=0;$i<$sz;$i++) {
$iter = $cat->getOpen();
while($iter->hasNext()) {
$curr = $cat->findNodeIdx($iter->getNext());
#$sz = sizeof($tmp);
#for($i=0;$i<$sz;$i++) {
#echo "B";
if($cat->getChild($tmp[$i])->inDev()) {
if($curr->inDev()) {
continue;
}
$html .= ach_render_achievement_open($cat->getChild($tmp[$i]));
$html .= ach_render_achievement_open($curr));
}
return $html;
@ -284,8 +295,9 @@
$html = "";
$perk_list = $ach->getOpen();
$perk = $ach->findNodeIdx($perk_list->getNext());
$perk = $ach->getChild($perk_list[0]);
#$perk = $ach->getChild($perk_list[0]);
if($perk->inDev()) {
return $html;
@ -295,7 +307,7 @@
$html .= "<span style='color:#999999;font-weight:bold;display:block;'>".$perk->getName()."</span>";
}
if($perk->objDrawable()) {
$html .= ach_render_obj_list($perk->getChildren());
$html .= ach_render_obj_list($perk->getIterator());
}
return $html;
@ -306,9 +318,10 @@
$html = "";
$perk_list = $ach->getDone();
foreach($perk_list as $elem) {
$perk = $ach->getChild($elem);
while($perk_list->hasNext()) {
$perk = $this->findNodeIdx($perk_list->getNext());
#foreach($perk_list as $elem) {
#$perk = $ach->getChild($elem);
if($perk->inDev()) {
continue;
}
@ -324,7 +337,9 @@
$i = 0;
$skip = false;
foreach($obj as $elem) {
while($obj->hasNext()) {
#foreach($obj as $elem) {
$elem = $obj->getNext();
if(($i%2) == 0) {
$html .= "<tr>";
}

View file

@ -34,10 +34,10 @@ else {
require_once("include/ach_render_common.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/NodeIterator_class.php");
require_once("class/Node_trait.php");
require_once("class/AchMenu_class.php");
require_once("class/AchMenuNode_class.php");