Subversion Repositories eFlore/Applications.del

Rev

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

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