Subversion Repositories eFlore/Applications.del

Rev

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

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