PageRenderTime 174ms CodeModel.GetById 121ms app.highlight 11ms RepoModel.GetById 39ms app.codeStats 0ms

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