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

Language PHP Lines 260
MD5 Hash b70fff2cf6d93e86e7c4ce258bd657a5 Estimated Cost $4,829 (why?)
Repository https://bitbucket.org/SirCotare/ryzom View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
	/*
	 * The Achievement class that holds one achievement. It is able to load one an the same task an treat is as both,
	 * open and done.
	 */

	class AchAchievement extends AchList {
		#########################
		# PHP 5.3 compatible
		# InDev_trait replaces this in PHP 5.4
		protected $dev;

		function inDev() {
			return ($this->dev == 1);
		}

		function getDev() {
			return $this->dev;
		}

		function setInDev($tf) {
			if($tf == true) {
				$this->setDev(1);
			}
			else {
				$this->setDev(0);
			}

			$this->update();
		}

		function setDev($d) {
			$this->dev = $d;
		}
		#########################

		protected $parent_id;
		protected $category;
		#protected $tie_race;
		#protected $tie_civ;
		#protected $tie_cult;
		protected $image;
		protected $name;
		protected $template;
		protected $sticky;

		function AchAchievement($data,$parent) {
			global $DBc,$_USER,$_CONF;

			parent::__construct();
			
			$this->setParent($parent); // real parent node
			$this->setID($data['aa_id']);
			$this->parent_id = $data['aa_parent']; // id of parent
			$this->category = $data['aa_category'];
			#$this->tie_race = $data['aa_tie_race'];
			#$this->tie_civ = $data['aa_tie_civ'];
			#$this->tie_cult = $data['aa_tie_cult'];
			$this->image = $data['aa_image'];
			$this->name = $data['aal_name'];
			$this->template = $data['aal_template'];
			$this->dev = $data['aa_dev'];
			$this->sticky = $data['aa_sticky'];

			if($this->name == null) {
				$res = $DBc->sqlQuery("SELECT * FROM ach_achievement_lang WHERE aal_lang='".$_CONF['default_lang']."' AND aal_achievement='".$this->id."'");
				$this->name = $res[0]['aal_name'];
				$this->template = $res[0]['aal_template'];
			}

			$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");
			
			$sz = sizeof($res);
			for($i=0;$i<$sz;$i++) {
				$tmp = $this->makeChild($res[$i]);

				if($tmp->isDone()) {
					$this->addDone($tmp);
				}
				else {
					$this->addOpen($tmp);
				}
			}

			$iter = $this->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				$curr->loadHeritage();
			}
		}

		function parentDone() { // check if the parent is complete
			if($this->parent_id == null) {
				return true;
			}
			else {
				$p = $this->parent->getChildDataByID($this->parent_id);
				if($p == null) {
					return true;
				}

				return ($p->hasOpen() == false);
			}
		}

		#@override Parentum::makeChild()
		protected function makeChild($a) {
			return new AchTask($a,$this);
		}

		function getParentID() {
			return $this->parent_id;
		}

		function getTieRace() {
			#return $this->tie_race;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->hasTieRace()) {
					return true;
				}
			}

			return false;
		}

		function getTieCiv() {
			#return $this->tie_civ;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->hasTieCiv()) {
					return true;
				}
			}

			return false;
		}

		function getTieCult() {
			#return $this->tie_cult;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->hasTieCult()) {
					return true;
				}
			}

			return false;
		}

		function isTiedRace($r) {
			#return $this->tie_race;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->isTiedRace($r)) {
					return true;
				}
			}

			return false;
		}

		function isTiedCiv($c) {
			#return $this->tie_civ;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->isTiedCiv($c)) {
					return true;
				}
			}

			return false;
		}

		function isTiedCult($c) {
			#return $this->tie_cult;
			$iter = $this->nodes->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->isTiedCult($c)) {
					return true;
				}
			}

			return false;
		}

		function getImage() {
			return $this->image;
		}

		function getName() {
			return $this->name;
		}

		function getValueDone() { // calculate the yubopoints that are already done
			$val = 0;
			$iter = $this->getDone();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				$val += $curr->getValue();
			}
			return $val;
		}

		function getValueOpen() { // get the yubopoints of the next open task
			$iter = $this->getOpen();
			if($iter->hasNext()) {
				$curr = $iter->getNext();
				return $curr->getValue();
			}
			return 0;
		}

		function fillTemplate($insert = array()) { // fill the naming template with given value
			if($this->template == null) {
				return implode(";",$insert);
			}
			else {
				$tmp = $this->template;
				$match = array();
				preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
				foreach($match[0] as $key=>$elem) {
					$tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
				}
				return $tmp;
			}
		}
		
		function getTemplate() {
			return $this->template;
		}

		function getCategory() {
			return $this->category;
		}

		function getSticky() {
			return $this->sticky;
		}

		function isSticky() {
			return ($this->sticky == 1);
		}

		function isHeroic() { // check parent category if it is heroic
			return $this->parent->isHeroic();
		}

		function isContest() {
			return $this->parent->isContest();
		}
		
	}
?>
Back to Top