Subversion Repositories eFlore/Applications.del

Rev

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

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