2012-06-25 13:04:51 +00:00
|
|
|
<?php
|
|
|
|
class CSRObjective extends AchObjective implements CSR {
|
2012-08-20 13:52:35 +00:00
|
|
|
#########################
|
|
|
|
# PHP 5.3 compatible
|
|
|
|
# CSRDispatcher_trait replaces this in PHP 5.4
|
|
|
|
|
2012-08-07 15:41:50 +00:00
|
|
|
function grantNode($path,$player) {
|
|
|
|
#echo "start: ".$path." id: ".$this->getID()."<br>";
|
|
|
|
if(is_numeric($path)) {
|
|
|
|
//it's me (id == numeric)
|
|
|
|
if($this->getID() == $path) {
|
|
|
|
$this->grant($player);
|
|
|
|
#echo "grant()<br>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//get child with the next level id and dispatch
|
|
|
|
$tmp = explode(";",$path);
|
|
|
|
|
|
|
|
$c = $this->getChildDataByID($tmp[1]);
|
|
|
|
#echo "...".$tmp[1];
|
|
|
|
if($c != null) { // check if it's really own child
|
|
|
|
unset($tmp[0]);
|
|
|
|
$c->grantNode(implode(";",$tmp),$player);
|
|
|
|
#echo "grantNode()<br>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#echo "end<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function denyNode($path,$player) {
|
|
|
|
if(is_numeric($path)) {
|
|
|
|
//it's me (id == numeric)
|
|
|
|
if($this->getID() == $path) {
|
|
|
|
$this->deny($player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//get child with the next level id and dispatch
|
|
|
|
$tmp = explode(";",$path);
|
|
|
|
|
|
|
|
if($tmp[0] == $this->getID()) { // it's my id!
|
|
|
|
|
|
|
|
$c = $this->getChildDataByID($tmp[1]);
|
|
|
|
if($c != null) { // check if it's really own child
|
|
|
|
unset($tmp[0]);
|
|
|
|
$c->denyNode(implode(";",$tmp),$player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPath($path = "") {
|
|
|
|
if($path != "") {
|
|
|
|
$path = ";".$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $this->getID().$path;
|
|
|
|
|
|
|
|
if($this->hasParent()) {
|
|
|
|
$path = $this->parent->getPath($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function hasParent() {
|
|
|
|
return ($this->parent != null);
|
|
|
|
}
|
2012-08-20 13:52:35 +00:00
|
|
|
#########################
|
2012-06-25 13:04:51 +00:00
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
function CSRObjective($data,$parent) {
|
|
|
|
parent::__construct($data,$parent);
|
2012-06-25 13:04:51 +00:00
|
|
|
|
|
|
|
global $DBc;
|
|
|
|
|
|
|
|
$res = $DBc->sqlQuery("SELECT atom_id FROM ach_atom WHERE atom_objective='".$this->getID()."'");
|
|
|
|
$sz = sizeof($res);
|
|
|
|
for($i=0;$i<$sz;$i++) {
|
2012-07-02 16:56:13 +00:00
|
|
|
$this->addChild($this->makeChild($res[$i]));
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
protected function makeChild($d) {
|
|
|
|
return new CSRAtom($d,$this);
|
|
|
|
}
|
|
|
|
|
2012-06-25 13:04:51 +00:00
|
|
|
function grant($pid) {
|
|
|
|
global $DBc;
|
|
|
|
|
|
|
|
$DBc->sqlQuery("INSERT INTO ach_player_objective (apo_objective,apo_player,apo_date) VALUES ('".$this->getID()."','".$pid."','".time()."')");
|
2012-07-02 16:56:13 +00:00
|
|
|
$this->done = 1;
|
|
|
|
$this->progress = $this->value;
|
2012-06-25 13:04:51 +00:00
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
$iter = $this->getIterator();
|
|
|
|
while($iter->hasNext()) {
|
|
|
|
$curr = $iter->getNext();
|
|
|
|
$curr->grant($pid);
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function deny($pid) {
|
|
|
|
global $DBc;
|
|
|
|
|
|
|
|
$DBc->sqlQuery("DELETE FROM ach_player_objective WHERE apo_objective='".$this->getID()."' AND apo_player='".$pid."'");
|
2012-07-02 16:56:13 +00:00
|
|
|
$this->done = 0;
|
|
|
|
$this->progress = 0;
|
2012-06-25 13:04:51 +00:00
|
|
|
|
2012-07-02 16:56:13 +00:00
|
|
|
$iter = $this->getIterator();
|
|
|
|
while($iter->hasNext()) {
|
|
|
|
$curr = $iter->getNext();
|
|
|
|
$curr->deny($pid);
|
2012-06-25 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|