PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms 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
  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
  7	class AchAchievement extends AchList {
  8		#########################
  9		# PHP 5.3 compatible
 10		# InDev_trait replaces this in PHP 5.4
 11		protected $dev;
 12
 13		function inDev() {
 14			return ($this->dev == 1);
 15		}
 16
 17		function getDev() {
 18			return $this->dev;
 19		}
 20
 21		function setInDev($tf) {
 22			if($tf == true) {
 23				$this->setDev(1);
 24			}
 25			else {
 26				$this->setDev(0);
 27			}
 28
 29			$this->update();
 30		}
 31
 32		function setDev($d) {
 33			$this->dev = $d;
 34		}
 35		#########################
 36
 37		protected $parent_id;
 38		protected $category;
 39		#protected $tie_race;
 40		#protected $tie_civ;
 41		#protected $tie_cult;
 42		protected $image;
 43		protected $name;
 44		protected $template;
 45		protected $sticky;
 46
 47		function AchAchievement($data,$parent) {
 48			global $DBc,$_USER,$_CONF;
 49
 50			parent::__construct();
 51			
 52			$this->setParent($parent); // real parent node
 53			$this->setID($data['aa_id']);
 54			$this->parent_id = $data['aa_parent']; // id of parent
 55			$this->category = $data['aa_category'];
 56			#$this->tie_race = $data['aa_tie_race'];
 57			#$this->tie_civ = $data['aa_tie_civ'];
 58			#$this->tie_cult = $data['aa_tie_cult'];
 59			$this->image = $data['aa_image'];
 60			$this->name = $data['aal_name'];
 61			$this->template = $data['aal_template'];
 62			$this->dev = $data['aa_dev'];
 63			$this->sticky = $data['aa_sticky'];
 64
 65			if($this->name == null) {
 66				$res = $DBc->sqlQuery("SELECT * FROM ach_achievement_lang WHERE aal_lang='".$_CONF['default_lang']."' AND aal_achievement='".$this->id."'");
 67				$this->name = $res[0]['aal_name'];
 68				$this->template = $res[0]['aal_template'];
 69			}
 70
 71			$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");
 72			
 73			$sz = sizeof($res);
 74			for($i=0;$i<$sz;$i++) {
 75				$tmp = $this->makeChild($res[$i]);
 76
 77				if($tmp->isDone()) {
 78					$this->addDone($tmp);
 79				}
 80				else {
 81					$this->addOpen($tmp);
 82				}
 83			}
 84
 85			$iter = $this->getIterator();
 86			while($iter->hasNext()) {
 87				$curr = $iter->getNext();
 88				$curr->loadHeritage();
 89			}
 90		}
 91
 92		function parentDone() { // check if the parent is complete
 93			if($this->parent_id == null) {
 94				return true;
 95			}
 96			else {
 97				$p = $this->parent->getChildDataByID($this->parent_id);
 98				if($p == null) {
 99					return true;
100				}
101
102				return ($p->hasOpen() == false);
103			}
104		}
105
106		#@override Parentum::makeChild()
107		protected function makeChild($a) {
108			return new AchTask($a,$this);
109		}
110
111		function getParentID() {
112			return $this->parent_id;
113		}
114
115		function getTieRace() {
116			#return $this->tie_race;
117			$iter = $this->nodes->getIterator();
118			while($iter->hasNext()) {
119				$curr = $iter->getNext();
120				if($curr->hasTieRace()) {
121					return true;
122				}
123			}
124
125			return false;
126		}
127
128		function getTieCiv() {
129			#return $this->tie_civ;
130			$iter = $this->nodes->getIterator();
131			while($iter->hasNext()) {
132				$curr = $iter->getNext();
133				if($curr->hasTieCiv()) {
134					return true;
135				}
136			}
137
138			return false;
139		}
140
141		function getTieCult() {
142			#return $this->tie_cult;
143			$iter = $this->nodes->getIterator();
144			while($iter->hasNext()) {
145				$curr = $iter->getNext();
146				if($curr->hasTieCult()) {
147					return true;
148				}
149			}
150
151			return false;
152		}
153
154		function isTiedRace($r) {
155			#return $this->tie_race;
156			$iter = $this->nodes->getIterator();
157			while($iter->hasNext()) {
158				$curr = $iter->getNext();
159				if($curr->isTiedRace($r)) {
160					return true;
161				}
162			}
163
164			return false;
165		}
166
167		function isTiedCiv($c) {
168			#return $this->tie_civ;
169			$iter = $this->nodes->getIterator();
170			while($iter->hasNext()) {
171				$curr = $iter->getNext();
172				if($curr->isTiedCiv($c)) {
173					return true;
174				}
175			}
176
177			return false;
178		}
179
180		function isTiedCult($c) {
181			#return $this->tie_cult;
182			$iter = $this->nodes->getIterator();
183			while($iter->hasNext()) {
184				$curr = $iter->getNext();
185				if($curr->isTiedCult($c)) {
186					return true;
187				}
188			}
189
190			return false;
191		}
192
193		function getImage() {
194			return $this->image;
195		}
196
197		function getName() {
198			return $this->name;
199		}
200
201		function getValueDone() { // calculate the yubopoints that are already done
202			$val = 0;
203			$iter = $this->getDone();
204			while($iter->hasNext()) {
205				$curr = $iter->getNext();
206				$val += $curr->getValue();
207			}
208			return $val;
209		}
210
211		function getValueOpen() { // get the yubopoints of the next open task
212			$iter = $this->getOpen();
213			if($iter->hasNext()) {
214				$curr = $iter->getNext();
215				return $curr->getValue();
216			}
217			return 0;
218		}
219
220		function fillTemplate($insert = array()) { // fill the naming template with given value
221			if($this->template == null) {
222				return implode(";",$insert);
223			}
224			else {
225				$tmp = $this->template;
226				$match = array();
227				preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
228				foreach($match[0] as $key=>$elem) {
229					$tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
230				}
231				return $tmp;
232			}
233		}
234		
235		function getTemplate() {
236			return $this->template;
237		}
238
239		function getCategory() {
240			return $this->category;
241		}
242
243		function getSticky() {
244			return $this->sticky;
245		}
246
247		function isSticky() {
248			return ($this->sticky == 1);
249		}
250
251		function isHeroic() { // check parent category if it is heroic
252			return $this->parent->isHeroic();
253		}
254
255		function isContest() {
256			return $this->parent->isContest();
257		}
258		
259	}
260?>