#1470 tasks may now inherit objectives from their parent tasks

--HG--
branch : gsoc2012-achievements
This commit is contained in:
SirCotare 2012-08-22 15:29:29 +02:00
parent 00a6c623e8
commit d39db0a4fd
7 changed files with 88 additions and 19 deletions

View file

@ -75,6 +75,12 @@
$this->addOpen($tmp); $this->addOpen($tmp);
} }
} }
$iter = $this->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
$curr->loadHeritage();
}
} }
function parentDone() { // check if the parent is complete function parentDone() { // check if the parent is complete

View file

@ -35,11 +35,15 @@
protected $done; protected $done;
protected $template; protected $template;
protected $parent_id; protected $parent_id;
protected $inherit_obj;
private $heritage_list;
function AchTask($data,$parent) { function AchTask($data,$parent) {
global $DBc,$_USER; global $DBc,$_USER;
parent::__construct(); parent::__construct();
$this->heritage_list = array();
$this->setParent($parent); $this->setParent($parent);
$this->setID($data['at_id']); $this->setID($data['at_id']);
@ -50,11 +54,32 @@
$this->dev = $data['at_dev']; $this->dev = $data['at_dev'];
$this->template = $data['atl_template']; $this->template = $data['atl_template'];
$this->parent_id = $data['at_parent']; $this->parent_id = $data['at_parent'];
$this->inherit_obj = $data['at_inherit'];
$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,ach_achievement_lang) ON (aa_id=ao_metalink AND aa_id=aal_achievement AND aal_lang='".$_USER->getLang()."') WHERE ao_task='".$this->id."' ORDER by aol_name ASC,aal_name ASC"); #if($this->inherit_obj == 0) {
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) { $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,ach_achievement_lang) ON (aa_id=ao_metalink AND aa_id=aal_achievement AND aal_lang='".$_USER->getLang()."') WHERE ao_task='".$this->id."' ORDER by aol_name ASC,aal_name ASC");
$this->addChild($this->makeChild($res[$i]));
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$this->addChild($this->makeChild($res[$i]));
}
#}
}
function loadHeritage() {
if($this->inherit_obj == 0) {
return false;
}
$child = $this->parent->getChildDataByID($this->parent_id);
if($child == null) {
return false;
}
$iter = $child->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
$this->addChild($curr);
$this->heritage_list[] = $curr->getID();
} }
} }
@ -63,6 +88,14 @@
return new AchObjective($a,$this); return new AchObjective($a,$this);
} }
function getHeritage() {
return $this->inherit_obj;
}
function isInherited($id) {
return in_array($id,$this->heritage_list);
}
function getAchievement() { function getAchievement() {
return $this->achievement; return $this->achievement;
} }

View file

@ -108,7 +108,7 @@
function update() { function update() {
global $DBc; global $DBc;
$DBc->sqlQuery("UPDATE ach_task SET at_parent=".mkn($this->getParentID()).",at_value='".$DBc->sqlEscape($this->getValue())."',at_condition='".$DBc->sqlEscape($this->getCondition())."',at_condition_value=".mkn($this->getConditionValue()).",at_dev='".$this->getDev()."',at_torder='".$this->torder."' WHERE at_id='".$this->getID()."'"); $DBc->sqlQuery("UPDATE ach_task SET at_parent=".mkn($this->getParentID()).",at_value='".$DBc->sqlEscape($this->getValue())."',at_condition='".$DBc->sqlEscape($this->getCondition())."',at_condition_value=".mkn($this->getConditionValue()).",at_dev='".$this->getDev()."',at_torder='".$this->torder."', at_inherit='".$this->inherit_obj."' WHERE at_id='".$this->getID()."'");
$DBc->sqlQuery("INSERT INTO ach_task_lang (atl_task,atl_lang,atl_name,atl_template) VALUES ('".$this->getID()."','en','".$DBc->sqlEscape($this->getName())."',".mkn($this->getTemplate()).") ON DUPLICATE KEY UPDATE atl_name='".$DBc->sqlEscape($this->getName())."',atl_template=".mkn($this->getTemplate()).""); $DBc->sqlQuery("INSERT INTO ach_task_lang (atl_task,atl_lang,atl_name,atl_template) VALUES ('".$this->getID()."','en','".$DBc->sqlEscape($this->getName())."',".mkn($this->getTemplate()).") ON DUPLICATE KEY UPDATE atl_name='".$DBc->sqlEscape($this->getName())."',atl_template=".mkn($this->getTemplate())."");
} }
@ -118,7 +118,7 @@
$this->dev = 1; $this->dev = 1;
$DBc->sqlQuery("INSERT INTO ach_task (at_achievement,at_parent,at_value,at_condition,at_condition_value,at_dev,at_torder) VALUES ('".$this->getAchievement()."',".mkn($this->getParentID()).",'".$DBc->sqlEscape($this->getValue())."','".$DBc->sqlEscape($this->getCondition())."',".mkn($this->getConditionValue()).",'1','".$this->torder."')"); $DBc->sqlQuery("INSERT INTO ach_task (at_achievement,at_parent,at_value,at_condition,at_condition_value,at_dev,at_torder,at_inherit) VALUES ('".$this->getAchievement()."',".mkn($this->getParentID()).",'".$DBc->sqlEscape($this->getValue())."','".$DBc->sqlEscape($this->getCondition())."',".mkn($this->getConditionValue()).",'1','".$this->torder."','".$this->inherit_obj."')");
$id = $DBc->insertID(); $id = $DBc->insertID();
$this->setID($id); $this->setID($id);
@ -165,6 +165,10 @@
$this->torder = $t; $this->torder = $t;
} }
function setHeritage($i) {
$this->inherit_obj = $i;
}
function setParentID($p,$order = true) { #reordering must happen A) after insert B) when updating function setParentID($p,$order = true) { #reordering must happen A) after insert B) when updating
if($p == null || $p == "null") { if($p == null || $p == "null") {

View file

@ -200,7 +200,7 @@
<td><input type='text' name='at_condition_value' /></td> <td><input type='text' name='at_condition_value' /></td>
</tr> </tr>
<tr> <tr>
<td colspan='2'><input type='submit' value='create' /></td> <td colspan='2'><input type='hidden' value='0' name='at_inherit' /><input type='submit' value='create' /></td>
</tr> </tr>
</table> </table>
</fieldset> </fieldset>
@ -382,6 +382,10 @@
$html .= "</select> $html .= "</select>
</td> </td>
</tr> </tr>
<tr>
<td class='bw'>inherit objectives:</td>
<td><input type='hidden' value='0' name='at_inherit' /><input type='checkbox' name='at_inherit' value='1' /></td>
</tr>
<tr> <tr>
<td class='bw'>condition:</td> <td class='bw'>condition:</td>
<td> <td>
@ -520,6 +524,14 @@
$html .= "</select> $html .= "</select>
</td> </td>
</tr> </tr>
<tr>
<td class='bw'>inherit objectives:</td>
<td><input type='hidden' value='0' name='at_inherit' /><input type='checkbox' name='at_inherit' value='1'";
if($task->getHeritage() == 1) {
$html .= " checked='checked'";
}
$html .= "/></td>
</tr>
<tr> <tr>
<td class='bw'>condition:</td> <td class='bw'>condition:</td>
<td> <td>
@ -624,13 +636,13 @@
</form> </form>
</div>"; </div>";
$html .= ach_render_obj_list($task->getIterator()); $html .= ach_render_obj_list($task->getIterator(),$task);
} }
return $html; return $html;
} }
function ach_render_obj_list($obj) { function ach_render_obj_list($obj,$task) {
#return null; #return null;
global $metalist; global $metalist;
$html = "<center><table width='90%'>"; $html = "<center><table width='90%'>";
@ -640,24 +652,30 @@
while($obj->hasNext()) { while($obj->hasNext()) {
#foreach($obj as $elem) { #foreach($obj as $elem) {
$inh = "";
$elem = $obj->getNext(); $elem = $obj->getNext();
if($task->isInherited($elem->getID())) {
$inh = "<i>inherited</i>:&nbsp;";
}
#if(($i%2) == 0) { #if(($i%2) == 0) {
$html .= "<tr><td><table><tr>"; $html .= "<tr><td><table><tr>";
#} #}
switch($elem->getDisplay()) { switch($elem->getDisplay()) {
case "meta": case "meta":
$html .= "<td>".ach_render_obj_meta($elem)."<td>"; $html .= "<td>".$inh.ach_render_obj_meta($elem)."<td>";
break; break;
case "value": case "value":
#if(($i%2) == 1) { #if(($i%2) == 1) {
# $html .= "</tr><tr>"; # $html .= "</tr><tr>";
#} #}
$html .= "<td>".ach_render_obj_value($elem)."</td>"; $html .= "<td>".$inh.ach_render_obj_value($elem)."</td>";
#$i++; #$i++;
break; break;
case "simple": case "simple":
$html .= "<td>".ach_render_obj_simple($elem)."</td>"; $html .= "<td>".$inh.ach_render_obj_simple($elem)."</td>";
break; break;
case "hidden": case "hidden":
default: default:
@ -666,7 +684,7 @@
#if(($i%2) == 1) { #if(($i%2) == 1) {
# $html .= "</tr><tr>"; # $html .= "</tr><tr>";
#} #}
$html .= "<td>".ach_render_obj_hidden($elem)."</td>"; $html .= "<td>".$inh.ach_render_obj_hidden($elem)."</td>";
#$i++; #$i++;
break; break;
} }

View file

@ -168,20 +168,23 @@ function catchTab(item,e){
$html .= "<div style='display: block; margin-bottom: 5px;'> $html .= "<div style='display: block; margin-bottom: 5px;'>
<div style='display:block;font-size:16px;' class='bar'><a href='javascript:hs(\"task_".$task->getID()."\",\"block\");'>[+]</a> ".$task->getDisplayName()." <span style='font-size:12px;'>(condition= ".$task->getCondition().": ".$task->getConditionValue().")</span></div> <div style='display:block;font-size:16px;' class='bar'><a href='javascript:hs(\"task_".$task->getID()."\",\"block\");'>[+]</a> ".$task->getDisplayName()." <span style='font-size:12px;'>(condition= ".$task->getCondition().": ".$task->getConditionValue().")</span></div>
<div style='margin-left:25px;display:".$o.";' id='task_".$task->getID()."'>".ach_render_obj_list($task->getIterator())."</div> <div style='margin-left:25px;display:".$o.";' id='task_".$task->getID()."'>".ach_render_obj_list($task->getIterator(),$task)."</div>
</div>"; </div>";
} }
return $html; return $html;
} }
function ach_render_obj_list($obj) { function ach_render_obj_list($obj,$task) {
$html = ""; $html = "";
while($obj->hasNext()) { while($obj->hasNext()) {
$elem = $obj->getNext(); $elem = $obj->getNext();
if($task->isInherited($elem->getID())) {
continue;
}
$o = "block"; $o = "block";

View file

@ -170,14 +170,14 @@
</div> </div>
</div> </div>
<div style='margin-left:25px;display:".$o.";' id='task_".$task->getID()."'>".ach_render_obj_list($task->getIterator())."</div> <div style='margin-left:25px;display:".$o.";' id='task_".$task->getID()."'>".ach_render_obj_list($task->getIterator(),$task)."</div>
</div>"; </div>";
} }
return $html; return $html;
} }
function ach_render_obj_list($obj) { function ach_render_obj_list($obj,$task) {
global $_CONF; global $_CONF;
$html = ""; $html = "";
@ -186,7 +186,9 @@
while($obj->hasNext()) { while($obj->hasNext()) {
$elem = $obj->getNext(); $elem = $obj->getNext();
if($task->isInherited($elem->getID())) {
continue;
}

View file

@ -420,6 +420,7 @@ $c .= "</div></td>
$task->setValue($_REQUEST['at_value']); $task->setValue($_REQUEST['at_value']);
$task->setCondition($_REQUEST['at_condition']); $task->setCondition($_REQUEST['at_condition']);
$task->setConditionValue($_REQUEST['at_condition_value']); $task->setConditionValue($_REQUEST['at_condition_value']);
$task->setHeritage(0);
$ach->insertNode($task); $ach->insertNode($task);
} }
@ -450,6 +451,7 @@ $c .= "</div></td>
$task->setValue($_REQUEST['at_value']); $task->setValue($_REQUEST['at_value']);
$task->setCondition($_REQUEST['at_condition']); $task->setCondition($_REQUEST['at_condition']);
$task->setConditionValue($_REQUEST['at_condition_value']); $task->setConditionValue($_REQUEST['at_condition_value']);
$task->setHeritage($_REQUEST['at_inherit']);
$ach->insertNode($task); $ach->insertNode($task);
$task->setParentID($_REQUEST['at_parent']); $task->setParentID($_REQUEST['at_parent']);
@ -467,6 +469,7 @@ $c .= "</div></td>
$task->setValue($_REQUEST['at_value']); $task->setValue($_REQUEST['at_value']);
$task->setCondition($_REQUEST['at_condition']); $task->setCondition($_REQUEST['at_condition']);
$task->setConditionValue($_REQUEST['at_condition_value']); $task->setConditionValue($_REQUEST['at_condition_value']);
$task->setHeritage($_REQUEST['at_inherit']);
$task->setParentID($_REQUEST['at_parent']); $task->setParentID($_REQUEST['at_parent']);