Subversion Repositories eFlore/Applications.del

Rev

Rev 505 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 505 Rev 509
Line 5... Line 5...
5
	
5
	
6
	private $debut = 0;
6
	private $debut = 0;
Line 7... Line 7...
7
	private $limite = 50;
7
	private $limite = 50;
-
 
8
	
8
	
9
	private $champ_tri = 'date_observation';
9
	private $champ_tri = 'date_observation';
10
	private $protocole_tri = 0;
Line 10... Line 11...
10
	private $ordre = 'desc';
11
	private $ordre = 'desc';
11
	private $tri_demande = false;
12
	private $tri_demande = false;
Line 109... Line 110...
109
		
110
		
110
		$this->champ_tri = isset($_GET['tri']) ? $_GET['tri'] : $this->champ_tri;
111
		$this->champ_tri = isset($_GET['tri']) ? $_GET['tri'] : $this->champ_tri;
Line 111... Line 112...
111
		$this->ordre = isset($_GET['ordre']) ? $_GET['ordre'] : $this->ordre;
112
		$this->ordre = isset($_GET['ordre']) ? $_GET['ordre'] : $this->ordre;
-
 
113
		
Line 112... Line 114...
112
		
114
		$this->tri_demande = isset($_GET['tri']) ? true : false;
113
		$this->tri_demande = isset($_GET['tri']) ? true : false;
115
		$this->protocole_tri = isset($_GET['id_protocole']) ? $_GET['id_protocole'] : $this->protocole_tri;
114
		
116
		
Line 190... Line 192...
190
		return $correspond;
192
		return $correspond;
191
	}
193
	}
Line 192... Line 194...
192
	
194
	
Line -... Line 195...
-
 
195
	private function comparerObservations($image_a, $image_b) {
-
 
196
		
193
	private function comparerObservations($image_a, $image_b) {
197
		$valeur_tri = null;
-
 
198
		
-
 
199
		switch($this->champ_tri) {
-
 
200
			case 'date_observation':
-
 
201
				$valeur_tri = $this->comparerDate($image_a, $image_b);
-
 
202
			break;
-
 
203
			case 'nb_votes':
-
 
204
				$valeur_tri = $this->comparerNbVote($image_a, $image_b);
-
 
205
			break;
-
 
206
		}
-
 
207
		
-
 
208
		return $valeur_tri;
-
 
209
	}
-
 
210
	
-
 
211
	private function comparerDate($image_a, $image_b) {
Line 194... Line 212...
194
		
212
		
195
		$champ_tri = $this->champ_tri;
213
		$champ_tri = 'date_observation';
Line 196... Line 214...
196
		
214
		
Line 202... Line 220...
202
		} else {
220
		} else {
203
			return $champ_a_comparer_a < $champ_a_comparer_b;
221
			return $champ_a_comparer_a < $champ_a_comparer_b;
204
		}
222
		}
205
	}
223
	}
Line -... Line 224...
-
 
224
	
-
 
225
	private function comparerNbVote($image_a, $image_b) {
-
 
226
		$id_protocole = $this->protocole_tri;
-
 
227
		$votes_a = 0;
-
 
228
		$votes_b = 0;
-
 
229
		
-
 
230
		if(isset($image_a->votes)) {
-
 
231
			foreach($image_a->votes as $vote_a) {
-
 
232
				$votes_a += $vote_a->id_protocole == $id_protocole ? 1 : 0;
-
 
233
			}
-
 
234
		}
-
 
235
		
-
 
236
		if(isset($image_b->votes)) {
-
 
237
			foreach($image_b->votes as $vote_b) {
-
 
238
				$votes_b += $vote_b->id_protocole == $id_protocole ? 1 : 0;
-
 
239
			}
-
 
240
		}
-
 
241
		
-
 
242
		if ($votes_a == $votes_b) {
-
 
243
			return 0;
-
 
244
		}
-
 
245
		
-
 
246
		if($this->ordre == 'asc') {
-
 
247
			return ($votes_a < $votes_b) ? -1 : 1;
-
 
248
		} else {
-
 
249
			return ($votes_a > $votes_b) ? -1 : 1;
-
 
250
		}
-
 
251
	}
206
	
252
	
207
	private function obtenirImagesAvecObservations() {
253
	private function obtenirImagesAvecObservations() {
208
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json'));
254
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json'));
209
	}
255
	}
210
}
256
}
211
?>
257
?>