PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 315 lines | 236 code | 54 blank | 25 comment | 34 complexity | 7a00e41a6aa17523285d82b92bd57902 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 implements Tieable {
  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."' AND (NOT EXISTS (SELECT * FROM ach_task_tie_align WHERE atta_task=at_id) OR EXISTS (SELECT * FROM ach_task_tie_align WHERE atta_task=at_id AND atta_alignment LIKE '".$parent->getCurrentCult().'|'.$parent->getCurrentCiv()."')) 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 hasTieRace_open() {
  96. #return $this->tie_race;
  97. $iter = $this->child_open->getIterator();
  98. while($iter->hasNext()) {
  99. $curr = $iter->getNext();
  100. if($curr->hasTieRace_open() && !$curr->inDev()) {
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. function hasTieAlign_open() {
  107. #return $this->tie_civ;
  108. $iter = $this->child_open->getIterator();
  109. while($iter->hasNext()) {
  110. $curr = $iter->getNext();
  111. if($curr->hasTieAlign_open() && !$curr->inDev()) {
  112. return true;
  113. }
  114. }
  115. return false;
  116. }
  117. function hasTieRace_done() {
  118. #return $this->tie_race;
  119. $iter = $this->child_done->getIterator();
  120. while($iter->hasNext()) {
  121. $curr = $iter->getNext();
  122. if($curr->hasTieRace_done() && !$curr->inDev()) {
  123. return true;
  124. }
  125. }
  126. return false;
  127. }
  128. function hasTieAlign_done() {
  129. #return $this->tie_civ;
  130. $iter = $this->child_done->getIterator();
  131. while($iter->hasNext()) {
  132. $curr = $iter->getNext();
  133. if($curr->hasTieAlign_done() && !$curr->inDev()) {
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. function hasTieRaceDev() {
  140. #return $this->tie_race;
  141. $iter = $this->nodes->getIterator();
  142. while($iter->hasNext()) {
  143. $curr = $iter->getNext();
  144. if($curr->hasTieRaceDev()) {
  145. return true;
  146. }
  147. }
  148. return false;
  149. }
  150. function hasTieAlignDev() {
  151. #return $this->tie_civ;
  152. $iter = $this->nodes->getIterator();
  153. while($iter->hasNext()) {
  154. $curr = $iter->getNext();
  155. if($curr->hasTieAlignDev()) {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. function isTiedRace_open($r) {
  162. #return $this->tie_race;
  163. $iter = $this->child_open->getIterator();
  164. while($iter->hasNext()) {
  165. $curr = $iter->getNext();
  166. if($curr->isTiedRace_open($r)) {
  167. return true;
  168. }
  169. }
  170. return false;
  171. }
  172. function isTiedAlign_open($cult,$civ) {
  173. #return $this->tie_civ;
  174. $iter = $this->child_open->getIterator();
  175. while($iter->hasNext()) {
  176. $curr = $iter->getNext();
  177. if($curr->isTiedAlign_open($cult,$civ)) {
  178. return true;
  179. }
  180. }
  181. return false;
  182. }
  183. function isTiedRace_done($r) {
  184. #return $this->tie_race;
  185. $iter = $this->child_done->getIterator();
  186. while($iter->hasNext()) {
  187. $curr = $iter->getNext();
  188. if($curr->isTiedRace_done($r)) {
  189. return true;
  190. }
  191. }
  192. return false;
  193. }
  194. function isTiedAlign_done($cult,$civ) {
  195. #return $this->tie_civ;
  196. $iter = $this->child_done->getIterator();
  197. while($iter->hasNext()) {
  198. $curr = $iter->getNext();
  199. if($curr->isTiedAlign_done($cult,$civ)) {
  200. return true;
  201. }
  202. }
  203. return false;
  204. }
  205. function getImage() {
  206. return $this->image;
  207. }
  208. function getName() {
  209. return $this->name;
  210. }
  211. function getValueDone() { // calculate the yubopoints that are already done
  212. $val = 0;
  213. $iter = $this->getDone();
  214. while($iter->hasNext()) {
  215. $curr = $iter->getNext();
  216. $val += $curr->getValue();
  217. }
  218. return $val;
  219. }
  220. function getValueOpen() { // get the yubopoints of the next open task
  221. $iter = $this->getOpen();
  222. if($iter->hasNext()) {
  223. $curr = $iter->getNext();
  224. return $curr->getValue();
  225. }
  226. return 0;
  227. }
  228. function fillTemplate($insert = array()) { // fill the naming template with given value
  229. if($this->template == null) {
  230. return implode(";",$insert);
  231. }
  232. else {
  233. $tmp = $this->template;
  234. $match = array();
  235. preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
  236. foreach($match[0] as $key=>$elem) {
  237. $tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
  238. }
  239. return $tmp;
  240. }
  241. }
  242. function getTemplate() {
  243. return $this->template;
  244. }
  245. function getCategory() {
  246. return $this->category;
  247. }
  248. function getSticky() {
  249. return $this->sticky;
  250. }
  251. function isSticky() {
  252. return ($this->sticky == 1);
  253. }
  254. function isHeroic() { // check parent category if it is heroic
  255. return $this->parent->isHeroic();
  256. }
  257. function isContest() {
  258. return $this->parent->isContest();
  259. }
  260. }
  261. ?>