7,7 → 7,6 |
private $limite = 50; |
|
private $champ_tri = 'date_observation'; |
private $protocole_tri = 0; |
private $ordre = 'desc'; |
private $tri_demande = false; |
|
112,7 → 111,6 |
$this->ordre = isset($_GET['ordre']) ? $_GET['ordre'] : $this->ordre; |
|
$this->tri_demande = isset($_GET['tri']) ? true : false; |
$this->protocole_tri = isset($_GET['id_protocole']) ? $_GET['id_protocole'] : $this->protocole_tri; |
|
if(isset($_GET['format'])) { |
$this->format = strtolower($_GET['format']); |
194,24 → 192,8 |
|
private function comparerObservations($image_a, $image_b) { |
|
$valeur_tri = null; |
$champ_tri = $this->champ_tri; |
|
switch($this->champ_tri) { |
case 'date_observation': |
$valeur_tri = $this->comparerDate($image_a, $image_b); |
break; |
case 'nb_votes': |
$valeur_tri = $this->comparerNbVote($image_a, $image_b); |
break; |
} |
|
return $valeur_tri; |
} |
|
private function comparerDate($image_a, $image_b) { |
|
$champ_tri = 'date_observation'; |
|
$champ_a_comparer_a = isset($image_a->observation->$champ_tri) ? $image_a->observation->$champ_tri : 0; |
$champ_a_comparer_b = isset($image_b->observation->$champ_tri) ? $image_b->observation->$champ_tri : 0; |
|
222,34 → 204,6 |
} |
} |
|
private function comparerNbVote($image_a, $image_b) { |
$id_protocole = $this->protocole_tri; |
$votes_a = 0; |
$votes_b = 0; |
|
if(isset($image_a->votes)) { |
foreach($image_a->votes as $vote_a) { |
$votes_a += $vote_a->id_protocole == $id_protocole ? 1 : 0; |
} |
} |
|
if(isset($image_b->votes)) { |
foreach($image_b->votes as $vote_b) { |
$votes_b += $vote_b->id_protocole == $id_protocole ? 1 : 0; |
} |
} |
|
if ($votes_a == $votes_b) { |
return 0; |
} |
|
if($this->ordre == 'asc') { |
return ($votes_a < $votes_b) ? -1 : 1; |
} else { |
return ($votes_a > $votes_b) ? -1 : 1; |
} |
} |
|
private function obtenirImagesAvecObservations() { |
return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json')); |
} |