PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/code/web/app/app_achievements/class/AchTask_class.php

https://bitbucket.org/SirCotare/ryzom
PHP | 238 lines | 190 code | 41 blank | 7 comment | 38 complexity | d25be648deef42e649910b26e54d88a2 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. class AchTask extends Parentum {
  3. #########################
  4. # PHP 5.3 compatible
  5. # InDev_trait replaces this in PHP 5.4
  6. protected $dev;
  7. function inDev() {
  8. return ($this->dev == 1);
  9. }
  10. function getDev() {
  11. return $this->dev;
  12. }
  13. function setInDev($tf) {
  14. if($tf == true) {
  15. $this->setDev(1);
  16. }
  17. else {
  18. $this->setDev(0);
  19. }
  20. $this->update();
  21. }
  22. function setDev($d) {
  23. $this->dev = $d;
  24. }
  25. #########################
  26. protected $achievement;
  27. protected $value;
  28. protected $name;
  29. protected $done;
  30. protected $template;
  31. protected $parent_id;
  32. protected $inherit_obj;
  33. private $heritage_list;
  34. protected $tie_race;
  35. protected $tie_cult;
  36. protected $tie_civ;
  37. function AchTask($data,$parent) {
  38. global $DBc,$_USER,$_CONF;
  39. parent::__construct();
  40. #$this->heritage_list = array();
  41. $this->setParent($parent);
  42. $this->setID($data['at_id']);
  43. $this->achievement = $data['at_achievement'];
  44. $this->value = $data['at_value'];
  45. $this->name = $data['atl_name'];
  46. $this->done = $data['apt_date'];
  47. $this->dev = $data['at_dev'];
  48. $this->template = $data['atl_template'];
  49. $this->parent_id = $data['at_parent'];
  50. $this->inherit_obj = $data['at_inherit'];
  51. if($this->inherit_obj == 1) {
  52. $this->heritage_list = new AVLTree();
  53. }
  54. else {
  55. $this->heritage_list = null;
  56. }
  57. if($this->name == null) {
  58. $res = $DBc->sqlQuery("SELECT * FROM ach_task_lang WHERE atl_lang='".$_CONF['default_lang']."' AND atl_task='".$this->id."'");
  59. $this->name = $res[0]['atl_name'];
  60. $this->template = $res[0]['atl_template'];
  61. }
  62. $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");
  63. $sz = sizeof($res);
  64. for($i=0;$i<$sz;$i++) {
  65. $this->addChild($this->makeChild($res[$i]));
  66. }
  67. //load ties
  68. $res = $DBc->sqlQuery("SELECT attr_race FROM ach_task_tie_race WHERE attr_task='".$this->id."'");
  69. $sz = sizeof($res);
  70. $this->tie_race = array();
  71. for($i=0;$i<$sz;$i++) {
  72. $this->tie_race[] = $res[$i]['attr_race'];
  73. }
  74. $res = $DBc->sqlQuery("SELECT attcult_cult FROM ach_task_tie_cult WHERE attcult_task='".$this->id."'");
  75. $sz = sizeof($res);
  76. $this->tie_cult = array();
  77. for($i=0;$i<$sz;$i++) {
  78. $this->tie_cult[] = $res[$i]['attcult_cult'];
  79. }
  80. $res = $DBc->sqlQuery("SELECT attciv_civ FROM ach_task_tie_civ WHERE attciv_task='".$this->id."'");
  81. $sz = sizeof($res);
  82. $this->tie_civ = array();
  83. for($i=0;$i<$sz;$i++) {
  84. $this->tie_civ[] = $res[$i]['attciv_civ'];
  85. }
  86. }
  87. function loadHeritage() {
  88. if($this->inherit_obj == 0) {
  89. return false;
  90. }
  91. $child = $this->parent->getChildDataByID($this->parent_id);
  92. if($child == null) {
  93. return false;
  94. }
  95. $iter = $child->getIterator();
  96. while($iter->hasNext()) {
  97. $curr = $iter->getNext();
  98. $this->addChild($curr);
  99. $this->heritage_list->insert($curr);
  100. }
  101. }
  102. #@override Parentum::makeChild()
  103. protected function makeChild($a) {
  104. return new AchObjective($a,$this);
  105. }
  106. function getHeritage() {
  107. return $this->inherit_obj;
  108. }
  109. function isInherited($id) {
  110. if($this->getHeritage() == 0) {
  111. return false;
  112. }
  113. if($this->heritage_list == null) {
  114. return false;
  115. }
  116. return ($this->heritage_list->find($id) != null);
  117. }
  118. function hasTieRace() {
  119. return (sizeof($this->tie_race) != 0);
  120. }
  121. function hasTieCult() {
  122. return (sizeof($this->tie_cult) != 0);
  123. }
  124. function hasTieCiv() {
  125. return (sizeof($this->tie_civ) != 0);
  126. }
  127. function isTiedRace($r) {
  128. if(sizeof($this->tie_race) == 0) {
  129. return true;
  130. }
  131. return in_array($r,$this->race);
  132. }
  133. function isTiedCult($c) {
  134. if(sizeof($this->tie_cult) == 0) {
  135. return true;
  136. }
  137. return in_array($c,$this->tie_cult);
  138. }
  139. function isTiedCiv($c) {
  140. if(sizeof($this->tie_civ) == 0) {
  141. return true;
  142. }
  143. return in_array($c,$this->tie_civ);
  144. }
  145. function getAchievement() {
  146. return $this->achievement;
  147. }
  148. function getValue() {
  149. return $this->value;
  150. }
  151. function getDisplayName() {
  152. if(substr($this->name,0,1) == "!") {
  153. return substr($this->name,1);
  154. }
  155. return $this->parent->fillTemplate(explode(";",$this->name));
  156. }
  157. function getName() {
  158. return $this->name;
  159. }
  160. function objDrawable() {
  161. $iter = $this->getIterator();
  162. while($iter->hasNext()) {
  163. $curr = $iter->getNext();
  164. if($curr->getDisplay() != "hidden") {
  165. return true;
  166. }
  167. }
  168. return false;
  169. }
  170. function isDone() {
  171. return ($this->done > 0);
  172. }
  173. function getDone() {
  174. return $this->done;
  175. }
  176. function fillTemplate($insert = array()) {
  177. if($this->template == null) {
  178. return implode(";",$insert);
  179. }
  180. else {
  181. $tmp = $this->template;
  182. $match = array();
  183. preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
  184. foreach($match[0] as $key=>$elem) {
  185. $tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
  186. }
  187. return $tmp;
  188. }
  189. }
  190. function getTemplate() {
  191. return $this->template;
  192. }
  193. function getParentID() {
  194. return $this->parent_id;
  195. }
  196. }
  197. ?>