PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/SirCotare/ryzom
PHP | 260 lines | 196 code | 43 blank | 21 comment | 26 complexity | b70fff2cf6d93e86e7c4ce258bd657a5 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * The Achievement class that holds one achievement. It is able to load one an the same task an treat is as both,
  4. * open and done.
  5. */
  6. class AchAchievement extends AchList {
  7. #########################
  8. # PHP 5.3 compatible
  9. # InDev_trait replaces this in PHP 5.4
  10. protected $dev;
  11. function inDev() {
  12. return ($this->dev == 1);
  13. }
  14. function getDev() {
  15. return $this->dev;
  16. }
  17. function setInDev($tf) {
  18. if($tf == true) {
  19. $this->setDev(1);
  20. }
  21. else {
  22. $this->setDev(0);
  23. }
  24. $this->update();
  25. }
  26. function setDev($d) {
  27. $this->dev = $d;
  28. }
  29. #########################
  30. protected $parent_id;
  31. protected $category;
  32. #protected $tie_race;
  33. #protected $tie_civ;
  34. #protected $tie_cult;
  35. protected $image;
  36. protected $name;
  37. protected $template;
  38. protected $sticky;
  39. function AchAchievement($data,$parent) {
  40. global $DBc,$_USER,$_CONF;
  41. parent::__construct();
  42. $this->setParent($parent); // real parent node
  43. $this->setID($data['aa_id']);
  44. $this->parent_id = $data['aa_parent']; // id of parent
  45. $this->category = $data['aa_category'];
  46. #$this->tie_race = $data['aa_tie_race'];
  47. #$this->tie_civ = $data['aa_tie_civ'];
  48. #$this->tie_cult = $data['aa_tie_cult'];
  49. $this->image = $data['aa_image'];
  50. $this->name = $data['aal_name'];
  51. $this->template = $data['aal_template'];
  52. $this->dev = $data['aa_dev'];
  53. $this->sticky = $data['aa_sticky'];
  54. if($this->name == null) {
  55. $res = $DBc->sqlQuery("SELECT * FROM ach_achievement_lang WHERE aal_lang='".$_CONF['default_lang']."' AND aal_achievement='".$this->id."'");
  56. $this->name = $res[0]['aal_name'];
  57. $this->template = $res[0]['aal_template'];
  58. }
  59. $res = $DBc->sqlQuery("SELECT * FROM ach_task LEFT JOIN (ach_task_lang) ON (atl_lang='".$_USER->getLang()."' AND atl_task=at_id) LEFT JOIN (ach_player_task) ON (apt_task=at_id AND apt_player='".$_USER->getID()."') WHERE at_achievement='".$this->id."' ORDER by at_torder ASC");
  60. $sz = sizeof($res);
  61. for($i=0;$i<$sz;$i++) {
  62. $tmp = $this->makeChild($res[$i]);
  63. if($tmp->isDone()) {
  64. $this->addDone($tmp);
  65. }
  66. else {
  67. $this->addOpen($tmp);
  68. }
  69. }
  70. $iter = $this->getIterator();
  71. while($iter->hasNext()) {
  72. $curr = $iter->getNext();
  73. $curr->loadHeritage();
  74. }
  75. }
  76. function parentDone() { // check if the parent is complete
  77. if($this->parent_id == null) {
  78. return true;
  79. }
  80. else {
  81. $p = $this->parent->getChildDataByID($this->parent_id);
  82. if($p == null) {
  83. return true;
  84. }
  85. return ($p->hasOpen() == false);
  86. }
  87. }
  88. #@override Parentum::makeChild()
  89. protected function makeChild($a) {
  90. return new AchTask($a,$this);
  91. }
  92. function getParentID() {
  93. return $this->parent_id;
  94. }
  95. function getTieRace() {
  96. #return $this->tie_race;
  97. $iter = $this->nodes->getIterator();
  98. while($iter->hasNext()) {
  99. $curr = $iter->getNext();
  100. if($curr->hasTieRace()) {
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. function getTieCiv() {
  107. #return $this->tie_civ;
  108. $iter = $this->nodes->getIterator();
  109. while($iter->hasNext()) {
  110. $curr = $iter->getNext();
  111. if($curr->hasTieCiv()) {
  112. return true;
  113. }
  114. }
  115. return false;
  116. }
  117. function getTieCult() {
  118. #return $this->tie_cult;
  119. $iter = $this->nodes->getIterator();
  120. while($iter->hasNext()) {
  121. $curr = $iter->getNext();
  122. if($curr->hasTieCult()) {
  123. return true;
  124. }
  125. }
  126. return false;
  127. }
  128. function isTiedRace($r) {
  129. #return $this->tie_race;
  130. $iter = $this->nodes->getIterator();
  131. while($iter->hasNext()) {
  132. $curr = $iter->getNext();
  133. if($curr->isTiedRace($r)) {
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. function isTiedCiv($c) {
  140. #return $this->tie_civ;
  141. $iter = $this->nodes->getIterator();
  142. while($iter->hasNext()) {
  143. $curr = $iter->getNext();
  144. if($curr->isTiedCiv($c)) {
  145. return true;
  146. }
  147. }
  148. return false;
  149. }
  150. function isTiedCult($c) {
  151. #return $this->tie_cult;
  152. $iter = $this->nodes->getIterator();
  153. while($iter->hasNext()) {
  154. $curr = $iter->getNext();
  155. if($curr->isTiedCult($c)) {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. function getImage() {
  162. return $this->image;
  163. }
  164. function getName() {
  165. return $this->name;
  166. }
  167. function getValueDone() { // calculate the yubopoints that are already done
  168. $val = 0;
  169. $iter = $this->getDone();
  170. while($iter->hasNext()) {
  171. $curr = $iter->getNext();
  172. $val += $curr->getValue();
  173. }
  174. return $val;
  175. }
  176. function getValueOpen() { // get the yubopoints of the next open task
  177. $iter = $this->getOpen();
  178. if($iter->hasNext()) {
  179. $curr = $iter->getNext();
  180. return $curr->getValue();
  181. }
  182. return 0;
  183. }
  184. function fillTemplate($insert = array()) { // fill the naming template with given value
  185. if($this->template == null) {
  186. return implode(";",$insert);
  187. }
  188. else {
  189. $tmp = $this->template;
  190. $match = array();
  191. preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
  192. foreach($match[0] as $key=>$elem) {
  193. $tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
  194. }
  195. return $tmp;
  196. }
  197. }
  198. function getTemplate() {
  199. return $this->template;
  200. }
  201. function getCategory() {
  202. return $this->category;
  203. }
  204. function getSticky() {
  205. return $this->sticky;
  206. }
  207. function isSticky() {
  208. return ($this->sticky == 1);
  209. }
  210. function isHeroic() { // check parent category if it is heroic
  211. return $this->parent->isHeroic();
  212. }
  213. function isContest() {
  214. return $this->parent->isContest();
  215. }
  216. }
  217. ?>