Subversion Repositories eFlore/Applications.del

Rev

Rev 2213 | Rev 2223 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2213 Rev 2222
1
<?php
1
<?php
2
/**
2
/**
3
 * Le web service plantnet récupère toutes les infos de la vue del_plantnet.
3
 * Le web service plantnet récupère toutes les infos de la vue del_plantnet.
4
 * Ordonées par date de modification.
4
 * Ordonées par date de modification.
5
 * Les images sont regroupées en observations.
5
 * Les images sont regroupées en observations.
6
 * Les tags, les votes et les propositions de determinations sont intégrés à l'observation.
6
 * Les tags, les votes et les propositions de determinations sont intégrés à l'observation.
7
 *
7
 *
-
 
8
 * Paramètres: date.debut et date.fin (unixtime en secondes), navigation.limite (10 par défaut), navigation.depart, ordre (DESC par défaut)
-
 
9
 * Ne pas Oublier l'api key dans le header $_SERVER['HTTP_API_KEY']
-
 
10
 *
8
 * @category DEL
11
 * @category DEL
9
 * @package Services
12
 * @package Services
10
 * @subpackage Plantnet
13
 * @subpackage Plantnet
11
 * @version 0.1
14
 * @version 0.1
12
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @author Mathias CHOUET <mathias@tela-botanica.org>
13
 * @author Samuel DUFOUR-KOWALSKI <samuel.dufour@cirad.fr>
16
 * @author Samuel DUFOUR-KOWALSKI <samuel.dufour@cirad.fr>
14
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
17
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
18
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
16
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> 
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> 
17
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
21
 * @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
19
 */
22
 */
20
 
23
 
21
class Changements {
24
class Changements {
22
 
25
 
23
	private $conteneur;
26
	private $conteneur;
24
	private $navigation;
27
	private $navigation;
25
	private $bdd;
28
	private $bdd;
26
 
29
 
27
	private $parametres = array();
30
	private $parametres = array();
28
	private $ressources = array();
31
	private $ressources = array();
29
	private $ordre_defaut = 'asc';
32
	private $ordre_defaut = 'DESC';
30
	private $idsObsImg = array();
33
	private $idsObsImg = array();
31
	private $infosObsImg = array();
34
	private $infosObsImg = array();
32
 
35
 
33
 
36
 
34
	public function __construct(Conteneur $conteneur = null) {
37
	public function __construct(Conteneur $conteneur = null) {
35
		/* restore_exception_handler(); */
38
		/* restore_exception_handler(); */
36
		/* restore_error_handler(); */
39
		/* restore_error_handler(); */
37
		/* ini_set("display_errors", "1"); */
40
		/* ini_set("display_errors", "1"); */
38
 
41
 
39
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
42
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
40
		$this->navigation = $conteneur->getNavigation();
43
		$this->navigation = $conteneur->getNavigation();
41
		$this->bdd = $this->conteneur->getBdd();
44
		$this->bdd = $this->conteneur->getBdd();
42
	}
45
	}
43
 
46
 
44
	/**
47
	/**
45
	 * Méthode principale de la classe.
48
	 * Méthode principale de la classe.
46
	 * Lance la récupération des images dans la base et les place dans un objet ResultatService
49
	 * Lance la récupération des images dans la base et les place dans un objet ResultatService
47
	 * pour l'afficher.
50
	 * pour l'afficher.
48
	 * @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
51
	 * @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
49
	 * @param array $parametres les paramètres situés après le ? dans l'url
52
	 * @param array $parametres les paramètres situés après le ? dans l'url
50
	 * */
53
	 * */
51
	public function consulter($ressources, $parametres) {
54
	public function consulter($ressources, $parametres) {
52
		// initialiserRessourcesEtParametres()
55
		// initialiserRessourcesEtParametres()
53
		$this->ressources = $ressources;
56
		$this->ressources = $ressources;
54
		$this->parametres = $parametres;
57
		$this->parametres = $parametres;
55
 
58
 
56
		if (!isset($parametres['date.debut'])) {
59
		if (!isset($parametres['date.debut'])) {
57
			$this->parametres['date.debut'] = '1900-01-01';
60
			$this->parametres['date.debut'] = '0';
58
		}
61
		}
59
 
62
 
60
		if (!isset($parametres['date.fin'])) {
63
		if (!isset($parametres['date.fin'])) {
61
			$this->parametres['date.fin'] = date('Y-m-d');
64
			$this->parametres['date.fin'] = time();
62
		}
65
		}
63
 
66
 
64
		if (! isset($parametres['ordre'])) {
67
		if (! isset($parametres['ordre'])) {
65
			$this->parametres['ordre'] = $this->ordre_defaut;
68
			$this->parametres['ordre'] = $this->ordre_defaut;
66
		} else {
69
		} else {
67
 			$parametres['ordre'] = strtolower($parametres['ordre']);
70
 			$parametres['ordre'] = strtolower($parametres['ordre']);
68
 			if (! in_array($parametres['ordre'], array('asc', 'desc'))) {
71
 			if (! in_array($parametres['ordre'], array('asc', 'desc'))) {
69
 				$this->parametres['ordre'] = $this->ordre_defaut;
72
 				$this->parametres['ordre'] = $this->ordre_defaut;
70
			}
73
			}
71
		}
74
		}
72
 
75
 
73
		// Lancement du service
76
		// Lancement du service
74
		$this->idsObsImg = $this->getIdsObsImg();
77
		$this->idsObsImg = $this->getIdsObsImg();
75
		$infos = array();
78
		$infos = array();
76
		$total = 0;
79
		$total = 0;
77
		if ($this->idsObsImg) {
80
		if ($this->idsObsImg) {
78
			$total = $this->getTotal();
81
			$total = $this->getTotal();
79
 
82
 
80
			$this->infosObsImg = $this->recupererInfos();
83
			$this->infosObsImg = $this->recupererInfos();
81
			$infos = $this->formaterInfos();
84
			$infos = $this->formaterInfos();
82
			$infos = $this->chargerPropositionPlusProbable($infos);
85
			$infos = $this->chargerPropositionPlusProbable($infos);
83
			$infos = $this->orderArray($infos);
86
			$infos = $this->orderArray($infos);
84
		}
87
		}
85
		$this->navigation->setTotal($total);
88
		$this->navigation->setTotal($total);
86
 
89
 
87
		// Mettre en forme le résultat et l'envoyer pour affichage
90
		// Mettre en forme le résultat et l'envoyer pour affichage
88
		$resultat = new ResultatService();
91
		$resultat = new ResultatService();
89
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $infos);
92
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $infos);
90
		return $resultat;
93
		return $resultat;
91
	}
94
	}
92
 
95
 
93
	/*-------------------------------------------------------------------------------
96
	/*-------------------------------------------------------------------------------
94
								CHARGEMENT DES IMAGES
97
								CHARGEMENT DES IMAGES
95
	--------------------------------------------------------------------------------*/
98
	--------------------------------------------------------------------------------*/
96
 
99
 
97
	private function getIdsObsImg() {
100
	private function getIdsObsImg() {
98
		$date_debut = "'{$this->parametres['date.debut']}'";
101
        $date_debut = date('Y-m-d H:i:s', $this->parametres['date.debut']);
99
		$date_fin = "'{$this->parametres['date.fin']}'";
102
        $date_fin = date('Y-m-d H:i:s', $this->parametres['date.fin']);
100
		$limite = @min(intval($this->parametres['navigation.limite']), 1000);
103
		$limite = @min(intval($this->parametres['navigation.limite']), 1000);
101
		$limite = $limite ? $limite : 100; // 0 => 10
104
		$limite = $limite ?: 100; // 0 => 10
102
		$depart = intval(@$this->parametres['navigation.depart']);
105
		$depart = intval(@$this->parametres['navigation.depart']);
103
		$ordre = $this->parametres['ordre'];
106
		$ordre = $this->parametres['ordre'];
-
 
107
 
-
 
108
        $date_debut = "'{$date_debut}'";
-
 
109
        $date_fin = "'{$date_fin}'";
104
 
110
 
105
		$requete =
111
		$requete =
106
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, p.id_image, '.
112
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, p.id_image, '.
107
			'GROUP_CONCAT(iv.valeur) AS votes, '.
113
			'GROUP_CONCAT(iv.valeur) AS votes, '.
108
			'GROUP_CONCAT(DISTINCT tag) AS tags, '.
114
			'GROUP_CONCAT(DISTINCT it.tag) AS del_image_tags, '.
109
			'modif_date '.
115
			'modif_date '.
110
 
-
 
111
			'FROM del_plantnet AS p '.
116
			'FROM del_plantnet AS p '.
112
			'	JOIN del_observation_modif_date '.
117
			'	JOIN del_observation_modif_date '.
113
			'		ON (p.id_observation = del_observation_modif_date.id_observation '.
118
			'		ON (p.id_observation = del_observation_modif_date.id_observation '.
114
			'		AND modif_date >= '.date('U', strtotime($date_debut)).') '.
119
			'		AND modif_date >= '.$date_debut.' '.
115
			'		AND modif_date <= '.date('U', strtotime($date_fin)).') '.
120
			'		AND modif_date <= '.$date_fin.') '.
116
			'	LEFT JOIN del_image_vote AS iv '.
121
			'	LEFT JOIN del_image_vote AS iv '.
117
			'		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
122
			'		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
118
			'	LEFT JOIN del_image_tag AS it '.
123
			'	LEFT JOIN del_image_tag AS it '.
119
			'		ON (id_image = it.ce_image AND it.actif = 1) '.
124
			'		ON (id_image = it.ce_image AND it.actif = 1) '.
120
			'	LEFT JOIN del_commentaire AS c '.
125
			'	LEFT JOIN del_commentaire AS c '.
121
			'		ON (p.id_observation = c.ce_observation) '.
126
			'		ON (p.id_observation = c.ce_observation) '.
122
			'	LEFT JOIN del_commentaire_vote AS cv '.
127
			'	LEFT JOIN del_commentaire_vote AS cv '.
123
			'		ON (c.id_commentaire = cv.ce_proposition) '.
128
			'		ON (c.id_commentaire = cv.ce_proposition) '.
124
			'GROUP BY id_image, p.id_observation '.
129
			'GROUP BY id_image, p.id_observation '.
125
			'ORDER BY modif_date ' . $ordre . ' '.
130
			'ORDER BY modif_date ' . $ordre . ' '.
126
			'LIMIT '.$depart.', '.$limite.
131
			'LIMIT '.$depart.', '.$limite.
127
			' -- '.__FILE__.':'.__LINE__;
132
			' -- '.__FILE__.':'.__LINE__;
128
 
133
 
129
		return $this->bdd->recupererTous($requete);
134
		return $this->bdd->recupererTous($requete);
-
 
135
        // On récupère id_obs, id_image, votes, tags, modif_date
130
	}
136
	}
131
 
137
 
132
	private function getTotal() {
138
	private function getTotal() {
133
		$compte = $this->bdd->recuperer('SELECT FOUND_ROWS() AS nbre');
139
		$compte = $this->bdd->recuperer('SELECT FOUND_ROWS() AS nbre');
134
		$total = (int) $compte['nbre'];
140
		$total = (int) $compte['nbre'];
135
		return $total;
141
		return $total;
136
	}
142
	}
137
 
143
 
138
	// recupere les donnée associées (fait en 2 requetes pour optimiser)
144
	// recupere les donnée associées (fait en 2 requetes pour optimiser)
139
	private function recupererInfos() {
145
	private function recupererInfos() {
140
		// recuperer les ids
146
		// recuperer les ids
141
		$idsImg = array();
147
		$idsImg = array();
142
		foreach ($this->idsObsImg as $ids) {
148
		foreach ($this->idsObsImg as $ids) {
143
			$id = $ids['id_image'];
149
			$id = $ids['id_image'];
144
			$idsImg[] = $id;
150
			$idsImg[] = $id;
145
		}
151
		}
146
		$idsImgConcat = implode(',', $idsImg);
152
		$idsImgConcat = implode(',', $idsImg);
147
 
153
 
148
		$requete = 'SELECT '.
154
		$requete = 'SELECT '.
149
			'p.id_observation, p.id_image, '.
155
			'p.id_observation, p.plantnet_id, p.id_image, '.
150
			'cp.id_plantnet, ' .
156
			'cp.plant_net_occurrence_id, ' .
151
			'p.nom_sel, '.
157
			'p.nom_sel, p.nom_sel_nn, p.nom_ret, p.nom_ret_nn,'.
152
			'p.nom_referentiel, p.nom_ret, p.famille, '.
158
			'p.nom_referentiel, p.famille, '.
153
			'p.zone_geo, p.latitude, p.longitude, '.
159
			'p.zone_geo, p.altitude,'.
154
			'p.date_observation, p.date_creation, p.date_transmission, '.
160
			'p.date_observation, p.date_created, p.date_published, '.
155
			'p.mots_cles_texte, '.
161
			'p.is_wild, p.identiplante_score, p.is_identiplante_validated, p.cel_photo_tag, '.
156
			'p.ce_utilisateur, p.prenom_utilisateur, p.nom_utilisateur, p.courriel_utilisateur, '.
162
			'p.ce_utilisateur, p.courriel_utilisateur, '.
157
			'p.i_mots_cles_texte AS mots_cles_texte_image, p.nom_original AS nom_image '.
163
			'p.original_name AS nom_image, p.i_date_updated AS image_updated '.
158
			'FROM del_plantnet AS p '.
164
			'FROM del_plantnet AS p '.
159
			'LEFT JOIN tb_cel.cel_plantnet AS cp ON p.id_observation = cp.id_observation '.
165
			'LEFT JOIN tb_new_cel.pn_tb_pair AS cp ON p.id_observation = cp.occurrence_id '.
160
			"WHERE id_image IN ($idsImgConcat) ".
166
			"WHERE id_image IN ($idsImgConcat) ".
161
			' -- '.__FILE__.':'.__LINE__;
167
			' -- '.__FILE__.':'.__LINE__;
162
		// recuperer les donnees
168
		// recuperer les donnees
163
		$resultats = $this->bdd->recupererTous($requete);
169
		$resultats = $this->bdd->recupererTous($requete);
164
 
170
 
165
		// regroupe les données par id_image
171
		// regroupe les données par id_image
166
		$img_data = array();
172
		$img_data = array();
167
		foreach ($resultats as $infos) {
173
		foreach ($resultats as $infos) {
168
			$idImg = $infos['id_image'];
174
			$idImg = $infos['id_image'];
169
			$img_data[$idImg] = $infos;
175
			$img_data[$idImg] = $infos;
170
		}
176
		}
171
		return $img_data;
177
		return $img_data;
172
	}
178
	}
173
 
179
 
174
	/**
180
	/**
175
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
181
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
176
	* @param $liaisons les liaisons de la table del_obs_images
182
	* @param $liaisons les liaisons de la table del_obs_images
177
	*/
183
	*/
178
	private function formaterInfos() {
184
	private function formaterInfos() {
179
		// regroupe les observations
185
		// regroupe les observations
180
		$obs = array();
186
		$obs = array();
181
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
187
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
182
		foreach ($this->idsObsImg as $ids) {
188
		foreach ($this->idsObsImg as $ids) {
183
			$idobs = $ids['id_observation'];
189
			$idobs = $ids['id_observation'];
184
			$idimg = $ids['id_image'];
190
			$idimg = $ids['id_image'];
185
 
191
 
186
			$imgdata = $this->infosObsImg[$idimg];
192
			$imgdata = $this->infosObsImg[$idimg];
187
 
193
 
188
			if (!isset($obs[$idobs])) {
194
			if (!isset($obs[$idobs])) {
189
				$obs[$idobs] = array();
195
				$obs[$idobs] = array();
190
			}
196
			}
191
 
197
 
192
			$obs[$idobs]['id_observation'] = $idobs;
198
			$obs[$idobs]['id_observation'] = $idobs;
193
			$obs[$idobs]['id_plantnet'] = $imgdata['id_plantnet'];
199
			$obs[$idobs]['plantnet_id'] = $imgdata['plantnet_id'];
194
			$obs[$idobs]['auteur_id'] = $imgdata['ce_utilisateur'];
-
 
195
			$obs[$idobs]['auteur_prenom'] = $imgdata['prenom_utilisateur'];
-
 
196
			$obs[$idobs]['auteur_nom'] = $imgdata['nom_utilisateur'];
-
 
197
			$obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
200
			$obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
198
 
201
 
199
			$obs[$idobs]['mots_cles_obs_cel'] = $this->formaterMotsClesCel($imgdata['mots_cles_texte']);
202
            $obs[$idobs]['mots_cles_obs_cel'] = $imgdata['cel_photo_tag'];
-
 
203
 
-
 
204
			$obs[$idobs]['date_observation'] = $imgdata['date_observation'];
200
 
205
            $obs[$idobs]['date_creation'] = $imgdata['date_created'];
201
			$obs[$idobs]['date_observation'] = $imgdata['date_observation'];
206
            $obs[$idobs]['date_changement'] = $ids['modif_date'];
202
			$obs[$idobs]['date_publication'] = $imgdata['date_transmission'];
207
			$obs[$idobs]['date_publication'] = $imgdata['date_published'];
-
 
208
			$obs[$idobs]['is_wild'] = $imgdata['is_wild'];
203
			$obs[$idobs]['date_creation'] = $imgdata['date_creation'];
209
			$obs[$idobs]['identiplante_score'] = $imgdata['identiplante_score'];
-
 
210
			$obs[$idobs]['is_identiplante_validated'] = $imgdata['is_identiplante_validated'];
204
			$obs[$idobs]['date_changement'] = $ids['modif_date'];
211
 
205
 
212
			$obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
206
			$obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
213
			$obs[$idobs]['nom_sel_nn'] = $imgdata['nom_sel_nn'];
207
			$obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
-
 
208
			$obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
214
			$obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
209
			//$obs[$idobs]['nn'] = $imgdata['nom_ret_nn'];
215
			$obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
210
			//$obs[$idobs]['nt'] = $imgdata['nt'];
216
			$obs[$idobs]['nom_ret_nn'] = $imgdata['nom_ret_nn'];
211
			$obs[$idobs]['famille'] = $imgdata['famille'];
217
			$obs[$idobs]['famille'] = $imgdata['famille'];
212
 
218
 
213
			$obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
219
			$obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
214
			$obs[$idobs]['latitude'] = floatval($imgdata['latitude']);
220
			$obs[$idobs]['altitude'] = $imgdata['altitude'];
215
			$obs[$idobs]['longitude'] = floatval($imgdata['longitude']);
-
 
216
 
221
 
217
			if (!isset($obs[$idobs]['images'])) {
222
			if (!isset($obs[$idobs]['images'])) {
218
				$obs[$idobs]['images'] = array();
223
				$obs[$idobs]['images'] = array();
219
			}
224
			}
220
 
225
 
221
			$img_obj = array(
226
			$img_obj = array(
222
				'id_image' => $idimg,
227
				'id_image' => $idimg,
223
				'nom_image' => $imgdata['nom_image'],
228
				'nom_image' => $imgdata['nom_image'],
-
 
229
                'image_updated' => $imgdata['image_updated'],
224
				'url' => sprintf($imgCelTpl, $idimg, 'O'),
230
				'url' => sprintf($imgCelTpl, $idimg, 'O'),
225
				'votes' => array_map('intval', explode(',', $ids['votes'])),
231
				'votes' => array_map('intval', explode(',', $ids['votes'])),
226
				'tags' => explode(',', $ids['tags']),
232
				'tags' => explode(',', $ids['del_image_tags']),
227
				'mots_cles_img_cel' => $this->formaterMotsClesCel($imgdata['mots_cles_texte_image'])
233
//				'mots_cles_img_cel' => $this->formaterMotsClesCel($imgdata['mots_cles_texte_image'])
228
				);
234
				);
229
			// push
235
			// push
230
			$obs[$idobs]['images'][] = $img_obj;
236
			$obs[$idobs]['images'][] = $img_obj;
231
		}
237
		}
232
		return $obs;
238
		return $obs;
233
	}
239
	}
234
 
240
 
235
	/**
241
	/**
236
	 * Charger les votes pour chaque image
242
	 * Charger les votes pour chaque image
237
	 */
243
	 */
238
	private function chargerPropositionPlusProbable(&$obs) {
244
	private function chargerPropositionPlusProbable(&$obs) {
239
		$obsIds = array_keys($obs);
245
		$obsIds = array_keys($obs);
240
		$idsObsConcat = implode(',', $obsIds);
246
		$idsObsConcat = implode(',', $obsIds);
241
 
247
 
242
		$requete = 'SELECT ce_observation, id_commentaire, valeur, nom_sel, nom_sel_nn, nom_ret, cv.ce_utilisateur '.
248
		$requete = 'SELECT ce_observation, id_commentaire, valeur, nom_sel, nom_sel_nn, nom_ret, cv.ce_utilisateur '.
243
			'FROM del_commentaire_vote AS cv, del_commentaire AS c '.
249
			'FROM del_commentaire_vote AS cv, del_commentaire AS c '.
244
			"WHERE ce_observation IN ($idsObsConcat) ".
250
			"WHERE ce_observation IN ($idsObsConcat) ".
245
			'AND nom_sel IS NOT NULL '.
251
			'AND nom_sel IS NOT NULL '.
246
			'AND c.id_commentaire = cv.ce_proposition '.
252
			'AND c.id_commentaire = cv.ce_proposition '.
247
			' -- '.__FILE__.':'.__LINE__;
253
			' -- '.__FILE__.':'.__LINE__;
248
		$resultats = $this->bdd->recupererTous($requete);
254
		$resultats = $this->bdd->recupererTous($requete);
249
 
255
 
250
		// calcul des votes
256
		// calcul des votes
251
		// un vote identifié a un facteur de 3
257
		// un vote identifié a un facteur de 3
252
		// additionne tous les vote par ce_proposition
258
		// additionne tous les vote par ce_proposition
253
		$votes = array(); // map ce_proposition -> score
259
		$votes = array(); // map ce_proposition -> score
254
		foreach ($resultats as $vote) {
260
		foreach ($resultats as $vote) {
255
			if (!isset($votes[$vote['id_commentaire']])) {
261
			if (!isset($votes[$vote['id_commentaire']])) {
256
				$votes[$vote['id_commentaire']] = 0;
262
				$votes[$vote['id_commentaire']] = 0;
257
			}
263
			}
258
			$valeur = ($vote['valeur'] == 1) ? 1 : -1;
264
			$valeur = ($vote['valeur'] == 1) ? 1 : -1;
259
			$votes[$vote['id_commentaire']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
265
			$votes[$vote['id_commentaire']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
260
		}
266
		}
261
 
267
 
262
		foreach ($resultats as $vote) {
268
		foreach ($resultats as $vote) {
263
			$idobs = $vote['ce_observation'];
269
			$idobs = $vote['ce_observation'];
264
 
270
 
265
			if (!isset($obs[$idobs]['determinations'])) {
271
			if (!isset($obs[$idobs]['determinations'])) {
266
				$obs[$idobs]['determinations'] = array();
272
				$obs[$idobs]['determinations'] = array();
267
			}
273
			}
268
 
274
 
269
			$obs[$idobs]['determinations'][$vote['id_commentaire']] =
275
			$obs[$idobs]['determinations'][$vote['id_commentaire']] =
270
			array('nom_sel' => $vote['nom_sel'],
276
			array('nom_sel' => $vote['nom_sel'],
271
				'nom_ret' => $vote['nom_ret'],
277
				'nom_ret' => $vote['nom_ret'],
272
				'score' => $votes[$vote['id_commentaire']],
278
				'score' => $votes[$vote['id_commentaire']],
273
				'nn' => $vote['nom_sel_nn']);
279
				'nn' => $vote['nom_sel_nn']);
274
		}
280
		}
275
		return $obs;
281
		return $obs;
276
	}
282
	}
277
 
283
 
278
	private function orderArray(&$obs) {
284
	private function orderArray(&$obs) {
279
		$ret = array();
285
		$ret = array();
280
		foreach ($obs as $o) {
286
		foreach ($obs as $o) {
281
			$ret[] = $o;
287
			$ret[] = $o;
282
		}
288
		}
283
 
289
 
284
		function cmpDesc($a, $b) {
290
		function cmpDesc($a, $b) {
285
			return ($a['date_changement'] < $b['date_changement']) ? 1 : -1;
291
			return ($a['date_changement'] < $b['date_changement']) ? 1 : -1;
286
		}
292
		}
287
		function cmpAsc($a, $b) {
293
		function cmpAsc($a, $b) {
288
			return cmpDesc($b, $a);
294
			return cmpDesc($b, $a);
289
		}
295
		}
290
 
296
 
291
		if ($this->parametres['ordre'] == 'desc') {
297
		if ($this->parametres['ordre'] == 'desc') {
292
			usort($ret, 'cmpDesc');
298
			usort($ret, 'cmpDesc');
293
		} else {
299
		} else {
294
			usort($ret, 'cmpAsc');
300
			usort($ret, 'cmpAsc');
295
		}
301
		}
296
		return $ret;
302
		return $ret;
297
	}
303
	}
298
 
304
 
299
	/**
305
	/**
300
	 * Formater les mots clés du cel en n'affichant que ceux faisant partie
306
	 * Formater les mots clés du cel en n'affichant que ceux faisant partie
301
	 * d'une liste définie dans le fichier de configuration
307
	 * d'une liste définie dans le fichier de configuration
302
	 * @param $chaineMotCleCel la chaine de mots clés du cel
308
	 * @param $chaineMotCleCel la chaine de mots clés du cel
303
	 * @return string la chaine filtrée
309
	 * @return string la chaine filtrée
304
	 */
310
	 */
305
	private function formaterMotsClesCel($chaineMotCleCel) {
311
	private function formaterMotsClesCel($chaineMotCleCel) {
306
		$mots_cles_cel_affiches = "fleur,fleurs,feuille,feuilles,ecorce,fruit,fruits,port,plantnet,plantscan_new,plantnet-mobile";
312
		$mots_cles_cel_affiches = "fleur,fleurs,feuille,feuilles,ecorce,fruit,fruits,port,plantnet,plantscan_new,plantnet-mobile";
307
 
313
 
308
		$result = array_intersect(
314
		$result = array_intersect(
309
			explode(',', $mots_cles_cel_affiches), // $tabMotsClesAffiches
315
			explode(',', $mots_cles_cel_affiches), // $tabMotsClesAffiches
310
			explode(',', $chaineMotCleCel)); // $tabMotsClesCel
316
			explode(',', $chaineMotCleCel)); // $tabMotsClesCel
311
 
317
 
312
		if (count($result) === 0) {
318
		if (count($result) === 0) {
313
		  return array();
319
		  return array();
314
		}
320
		}
315
		$ret = explode(',', implode(',', $result));
321
		$ret = explode(',', implode(',', $result));
316
		return $ret;
322
		return $ret;
317
	}
323
	}
318
 
324
 
319
}
325
}