Subversion Repositories eFlore/Applications.del

Rev

Rev 2202 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2202 Rev 2227
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 = 'asc';
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 = isset($this->parametres['navigation.limite']) ? intval($this->parametres['navigation.limite']) : 10;
101
		$limite = $limite ? $limite : 100; // 0 => 10
-
 
102
		$depart = intval(@$this->parametres['navigation.depart']);
104
		$depart = intval(@$this->parametres['navigation.depart']);
103
		$ordre = $this->parametres['ordre'];
105
		$ordre = $this->parametres['ordre'];
-
 
106
        $date_debut = "'{$date_debut}'";
-
 
107
        $date_fin = "'{$date_fin}'";
104
 
108
 
105
		$requete =
109
		$requete =
-
 
110
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, GROUP_CONCAT(DISTINCT p.id_image) as id_image, '.
106
			'SELECT SQL_CALC_FOUND_ROWS p.id_observation, p.id_image, '.
111
			'iv.moyenne AS moyenne_votes, '.
-
 
112
			'iv.nb_votes AS nb_votes, '.
107
			'GROUP_CONCAT(iv.valeur) AS votes, '.
113
			'iv.nb_points AS nb_points_votes, '.
108
			'GROUP_CONCAT(DISTINCT tag) AS tags, '.
114
			'GROUP_CONCAT(DISTINCT it.tag) AS del_image_tags, '.
109
			'modif_date '.
-
 
110
 
115
			'modif_date '.
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_stat 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 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
 
-
 
129
		return $this->bdd->recupererTous($requete);
133
		return $this->bdd->recupererTous($requete);
-
 
134
        // On récupère id_obs, id_image, votes, tags, modif_date
130
	}
135
	}
131
 
136
 
132
	private function getTotal() {
137
	private function getTotal() {
133
		$compte = $this->bdd->recuperer('SELECT FOUND_ROWS() AS nbre');
138
		$compte = $this->bdd->recuperer('SELECT FOUND_ROWS() AS nbre');
134
		$total = (int) $compte['nbre'];
139
		$total = (int) $compte['nbre'];
135
		return $total;
140
		return $total;
136
	}
141
	}
137
 
142
 
138
	// 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)
139
	private function recupererInfos() {
144
	private function recupererInfos() {
140
		// recuperer les ids
145
		// recuperer les ids
141
		$idsImg = array();
146
		$idsImg = array();
142
		foreach ($this->idsObsImg as $ids) {
147
		foreach ($this->idsObsImg as $ids) {
143
			$id = $ids['id_image'];
148
			$id = $ids['id_image'];
144
			$idsImg[] = $id;
149
			$idsImg[] = $id;
145
		}
150
		}
146
		$idsImgConcat = implode(',', $idsImg);
151
		$idsImgConcat = implode(',', $idsImg);
147
 
152
 
148
		$requete = 'SELECT '.
153
		$requete = 'SELECT '.
149
			'p.id_observation, p.id_image, '.
154
			'p.id_observation, p.id_plantnet, p.id_image, '.
150
			'cp.id_plantnet, ' .
155
			'cp.plant_net_occurrence_id, ' .
151
			'p.nom_sel, '.
156
			'p.nom_sel, p.nom_sel_nn, p.nom_ret, p.nom_ret_nn,'.
152
			'p.nom_referentiel, p.nom_ret, p.famille, '.
157
			'p.nom_referentiel, p.famille, '.
153
			'p.zone_geo, p.latitude, p.longitude, '.
158
			'p.zone_geo, p.latitude, p.longitude,'.
154
			'p.date_observation, p.date_creation, p.date_transmission, '.
159
			'p.date_observation, p.date_created, p.date_published, '.
155
			'p.mots_cles_texte, '.
160
			'p.type_donnees, p.identiplante_score, p.is_identiplante_validated, p.mots_cles_cel_obs, p.programme, '.
156
			'p.ce_utilisateur, p.prenom_utilisateur, p.nom_utilisateur, p.courriel_utilisateur, '.
161
			'p.ce_utilisateur, p.courriel_utilisateur, '.
157
			'p.i_mots_cles_texte AS mots_cles_texte_image, p.nom_original AS nom_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 '.
158
			'FROM del_plantnet AS p '.
163
			'FROM del_plantnet AS p '.
159
			'LEFT JOIN tb_cel.cel_plantnet AS cp ON p.id_observation = cp.id_observation '.
164
			'LEFT JOIN tb_new_cel.pn_tb_pair AS cp ON p.id_observation = cp.occurrence_id '.
160
			"WHERE id_image IN ($idsImgConcat) ".
165
			"WHERE id_image IN ($idsImgConcat) ".
161
			' -- '.__FILE__.':'.__LINE__;
166
			' -- '.__FILE__.':'.__LINE__;
162
		// recuperer les donnees
167
		// recuperer les donnees
163
		$resultats = $this->bdd->recupererTous($requete);
168
		$resultats = $this->bdd->recupererTous($requete);
164
 
169
 
165
		// regroupe les données par id_image
170
		// regroupe les données par id_image
166
		$img_data = array();
171
		$img_data = array();
167
		foreach ($resultats as $infos) {
172
		foreach ($resultats as $infos) {
168
			$idImg = $infos['id_image'];
173
			$idImg = $infos['id_image'];
169
			$img_data[$idImg] = $infos;
174
			$img_data[$idImg] = $infos;
170
		}
175
		}
171
		return $img_data;
176
		return $img_data;
172
	}
177
	}
173
 
178
 
174
	/**
179
	/**
175
	* 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
176
	* @param $liaisons les liaisons de la table del_obs_images
181
	* @param $liaisons les liaisons de la table del_obs_images
177
	*/
182
	*/
178
	private function formaterInfos() {
183
	private function formaterInfos() {
179
		// regroupe les observations
184
		// regroupe les observations
180
		$obs = array();
185
		$obs = array();
181
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
186
		$imgCelTpl = $this->conteneur->getParametre('cel_img_url_tpl');
182
		foreach ($this->idsObsImg as $ids) {
187
		foreach ($this->idsObsImg as $ids) {
183
			$idobs = $ids['id_observation'];
188
			$idobs = $ids['id_observation'];
184
			$idimg = $ids['id_image'];
189
			$idimg = explode(',', $ids['id_image']);
185
 
190
 
186
			$imgdata = $this->infosObsImg[$idimg];
191
            $obs[$idobs]['id_observation'] = $idobs;
-
 
192
 
187
 
193
            foreach ($idimg as $image){
188
			if (!isset($obs[$idobs])) {
-
 
189
				$obs[$idobs] = array();
194
                $imgInfos = null;
190
			}
195
                $imgdata = null;
191
 
196
 
-
 
197
                $imgdata = $this->infosObsImg[$image];
192
			$obs[$idobs]['id_observation'] = $idobs;
198
                $imgInfos = $this->recupererInfosParImage($image);
193
			$obs[$idobs]['id_plantnet'] = $imgdata['id_plantnet'];
199
 
-
 
200
                if (!isset($obs[$idobs])) {
-
 
201
                    $obs[$idobs] = array();
194
			$obs[$idobs]['auteur_id'] = $imgdata['ce_utilisateur'];
202
                }
195
			$obs[$idobs]['auteur_prenom'] = $imgdata['prenom_utilisateur'];
203
 
196
			$obs[$idobs]['auteur_nom'] = $imgdata['nom_utilisateur'];
204
                $obs[$idobs]['id_plantnet'] = $imgdata['id_plantnet'];
197
			$obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
205
                $obs[$idobs]['auteur_courriel'] = $imgdata['courriel_utilisateur'];
-
 
206
 
198
 
207
                $obs[$idobs]['mots_cles_cel_obs'] = $imgdata['mots_cles_cel_obs'];
199
			$obs[$idobs]['mots_cles_obs_cel'] = $this->formaterMotsClesCel($imgdata['mots_cles_texte']);
208
                $obs[$idobs]['programme'] = $imgdata['programme'];
200
 
209
 
-
 
210
                $obs[$idobs]['date_observation'] = $imgdata['date_observation'];
201
			$obs[$idobs]['date_observation'] = $imgdata['date_observation'];
211
                $obs[$idobs]['date_creation'] = $imgdata['date_created'];
202
			$obs[$idobs]['date_publication'] = $imgdata['date_transmission'];
212
                $obs[$idobs]['date_changement'] = $ids['modif_date'];
-
 
213
                $obs[$idobs]['date_publication'] = $imgdata['date_published'];
-
 
214
                $obs[$idobs]['type_donnees'] = $imgdata['type_donnees'];
203
			$obs[$idobs]['date_creation'] = $imgdata['date_creation'];
215
                $obs[$idobs]['identiplante_score'] = $imgdata['identiplante_score'];
204
			$obs[$idobs]['date_changement'] = $ids['modif_date'];
216
                $obs[$idobs]['is_identiplante_validated'] = $imgdata['is_identiplante_validated'];
205
 
217
 
206
			$obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
218
                $obs[$idobs]['nom_sel'] = $imgdata['nom_sel'];
207
			$obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
219
                $obs[$idobs]['nom_sel_nn'] = $imgdata['nom_sel_nn'];
208
			$obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
220
                $obs[$idobs]['nom_referentiel'] = $imgdata['nom_referentiel'];
209
			//$obs[$idobs]['nn'] = $imgdata['nom_ret_nn'];
221
                $obs[$idobs]['nom_ret'] = $imgdata['nom_ret'];
210
			//$obs[$idobs]['nt'] = $imgdata['nt'];
222
                $obs[$idobs]['nom_ret_nn'] = $imgdata['nom_ret_nn'];
211
			$obs[$idobs]['famille'] = $imgdata['famille'];
223
                $obs[$idobs]['famille'] = $imgdata['famille'];
212
 
224
 
213
			$obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
225
                $obs[$idobs]['zone_geo'] = $imgdata['zone_geo'];
214
			$obs[$idobs]['latitude'] = floatval($imgdata['latitude']);
226
                $obs[$idobs]['latitude'] = $imgdata['latitude'];
215
			$obs[$idobs]['longitude'] = floatval($imgdata['longitude']);
227
                $obs[$idobs]['longitude'] = $imgdata['longitude'];
216
 
228
 
-
 
229
                if (!isset($obs[$idobs]['images'])) {
217
			if (!isset($obs[$idobs]['images'])) {
230
                    $obs[$idobs]['images'] = array();
-
 
231
                }
-
 
232
 
-
 
233
                $img_obj = array(
-
 
234
                    'id_image' => $image,
-
 
235
                    'nom_image' => $imgdata['nom_image'],
-
 
236
                    'image_updated' => $imgdata['image_updated'],
-
 
237
                    'date_shot' => $imgdata['date_shot'],
-
 
238
                    'mots_cles_cel_image' => $imgInfos[0]['mots_cles_cel_image'],
-
 
239
                    'url' => sprintf($imgCelTpl, $idimg, 'O'),
-
 
240
                    'votes' => [
-
 
241
                        'moyenne_votes' => $imgInfos[0]['moyenne_votes'],
-
 
242
                        'nb_votes' => $imgInfos[0]['nb_votes'],
-
 
243
                        'nb_points_votes' => $imgInfos[0]['nb_points_votes'],
-
 
244
                    ],
-
 
245
                    'del_tags' => explode(',', $imgInfos[0]['del_image_tags']),
-
 
246
                );
-
 
247
                // push
218
				$obs[$idobs]['images'] = array();
-
 
219
			}
-
 
220
 
-
 
221
			$img_obj = array(
-
 
222
				'id_image' => $idimg,
-
 
223
				'nom_image' => $imgdata['nom_image'],
-
 
224
				'url' => sprintf($imgCelTpl, $idimg, 'O'),
-
 
225
				'votes' => array_map('intval', explode(',', $ids['votes'])),
-
 
226
				'tags' => explode(',', $ids['tags']),
-
 
227
				'mots_cles_img_cel' => $this->formaterMotsClesCel($imgdata['mots_cles_texte_image'])
-
 
228
				);
248
                $obs[$idobs]['images'][] = $img_obj;
229
			// push
249
            }
230
			$obs[$idobs]['images'][] = $img_obj;
250
 
231
		}
251
		}
232
		return $obs;
252
		return $obs;
233
	}
253
	}
234
 
254
 
235
	/**
255
	/**
236
	 * Charger les votes pour chaque image
256
	 * Charger les votes pour chaque image
237
	 */
257
	 */
238
	private function chargerPropositionPlusProbable(&$obs) {
258
	private function chargerPropositionPlusProbable(&$obs) {
239
		$obsIds = array_keys($obs);
259
		$obsIds = array_keys($obs);
240
		$idsObsConcat = implode(',', $obsIds);
260
		$idsObsConcat = implode(',', $obsIds);
241
 
261
 
242
		$requete = 'SELECT ce_observation, id_commentaire, valeur, nom_sel, nom_sel_nn, nom_ret, cv.ce_utilisateur '.
262
		$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 '.
263
			'FROM del_commentaire_vote AS cv, del_commentaire AS c '.
244
			"WHERE ce_observation IN ($idsObsConcat) ".
264
			"WHERE ce_observation IN ($idsObsConcat) ".
245
			'AND nom_sel IS NOT NULL '.
265
			'AND nom_sel IS NOT NULL '.
246
			'AND c.id_commentaire = cv.ce_proposition '.
266
			'AND c.id_commentaire = cv.ce_proposition '.
247
			' -- '.__FILE__.':'.__LINE__;
267
			' -- '.__FILE__.':'.__LINE__;
248
		$resultats = $this->bdd->recupererTous($requete);
268
		$resultats = $this->bdd->recupererTous($requete);
249
 
269
 
250
		// calcul des votes
270
		// calcul des votes
251
		// un vote identifié a un facteur de 3
271
		// un vote identifié a un facteur de 3
252
		// additionne tous les vote par ce_proposition
272
		// additionne tous les vote par ce_proposition
253
		$votes = array(); // map ce_proposition -> score
273
		$votes = array(); // map ce_proposition -> score
254
		foreach ($resultats as $vote) {
274
		foreach ($resultats as $vote) {
255
			if (!isset($votes[$vote['id_commentaire']])) {
275
			if (!isset($votes[$vote['id_commentaire']])) {
256
				$votes[$vote['id_commentaire']] = 0;
276
				$votes[$vote['id_commentaire']] = 0;
257
			}
277
			}
258
			$valeur = ($vote['valeur'] == 1) ? 1 : -1;
278
			$valeur = ($vote['valeur'] == 1) ? 1 : -1;
259
			$votes[$vote['id_commentaire']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
279
			$votes[$vote['id_commentaire']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
260
		}
280
		}
261
 
281
 
262
		foreach ($resultats as $vote) {
282
		foreach ($resultats as $vote) {
263
			$idobs = $vote['ce_observation'];
283
			$idobs = $vote['ce_observation'];
264
 
284
 
265
			if (!isset($obs[$idobs]['determinations'])) {
285
			if (!isset($obs[$idobs]['determinations'])) {
266
				$obs[$idobs]['determinations'] = array();
286
				$obs[$idobs]['determinations'] = array();
267
			}
287
			}
268
 
288
 
269
			$obs[$idobs]['determinations'][$vote['id_commentaire']] =
289
			$obs[$idobs]['determinations'][$vote['id_commentaire']] =
270
			array('nom_sel' => $vote['nom_sel'],
290
			array('nom_sel' => $vote['nom_sel'],
271
				'nom_ret' => $vote['nom_ret'],
291
				'nom_ret' => $vote['nom_ret'],
272
				'score' => $votes[$vote['id_commentaire']],
292
				'score' => $votes[$vote['id_commentaire']],
273
				'nn' => $vote['nom_sel_nn']);
293
				'nn' => $vote['nom_sel_nn']);
274
		}
294
		}
275
		return $obs;
295
		return $obs;
276
	}
296
	}
277
 
297
 
278
	private function orderArray(&$obs) {
298
	private function orderArray(&$obs) {
279
		$ret = array();
299
		$ret = array();
280
		foreach ($obs as $o) {
300
		foreach ($obs as $o) {
281
			$ret[] = $o;
301
			$ret[] = $o;
282
		}
302
		}
283
 
303
 
284
		function cmpDesc($a, $b) {
304
		function cmpDesc($a, $b) {
285
			return ($a['date_changement'] < $b['date_changement']) ? 1 : -1;
305
			return ($a['date_changement'] < $b['date_changement']) ? 1 : -1;
286
		}
306
		}
287
		function cmpAsc($a, $b) {
307
		function cmpAsc($a, $b) {
288
			return cmpDesc($b, $a);
308
			return cmpDesc($b, $a);
289
		}
309
		}
290
 
310
 
291
		if ($this->parametres['ordre'] == 'desc') {
311
		if ($this->parametres['ordre'] == 'desc') {
292
			usort($ret, 'cmpDesc');
312
			usort($ret, 'cmpDesc');
293
		} else {
313
		} else {
294
			usort($ret, 'cmpAsc');
314
			usort($ret, 'cmpAsc');
295
		}
315
		}
296
		return $ret;
316
		return $ret;
297
	}
317
	}
298
 
318
 
299
	/**
319
	/**
300
	 * Formater les mots clés du cel en n'affichant que ceux faisant partie
320
	 * 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
321
	 * d'une liste définie dans le fichier de configuration
302
	 * @param $chaineMotCleCel la chaine de mots clés du cel
322
	 * @param $chaineMotCleCel la chaine de mots clés du cel
303
	 * @return string la chaine filtrée
323
	 * @return string la chaine filtrée
304
	 */
324
	 */
305
	private function formaterMotsClesCel($chaineMotCleCel) {
325
	private function formaterMotsClesCel($chaineMotCleCel) {
306
		$mots_cles_cel_affiches = "fleur,fleurs,feuille,feuilles,ecorce,fruit,fruits,port,plantnet,plantscan_new,plantnet-mobile";
326
		$mots_cles_cel_affiches = "fleur,fleurs,feuille,feuilles,ecorce,fruit,fruits,port,plantnet,plantscan_new,plantnet-mobile";
307
 
327
 
308
		$result = array_intersect(
328
		$result = array_intersect(
309
			explode(',', $mots_cles_cel_affiches), // $tabMotsClesAffiches
329
			explode(',', $mots_cles_cel_affiches), // $tabMotsClesAffiches
310
			explode(',', $chaineMotCleCel)); // $tabMotsClesCel
330
			explode(',', $chaineMotCleCel)); // $tabMotsClesCel
311
 
331
 
312
		if (count($result) === 0) {
332
		if (count($result) === 0) {
313
		  return array();
333
		  return array();
314
		}
334
		}
315
		$ret = explode(',', implode(',', $result));
335
		$ret = explode(',', implode(',', $result));
316
		return $ret;
336
		return $ret;
317
	}
337
	}
-
 
338
 
-
 
339
    /**
-
 
340
     * On charge les infos spécifique à chaque image d'une obs
-
 
341
     */
-
 
342
    private function recupererInfosParImage($id_image){
-
 
343
        $requete =
-
 
344
            'SELECT SQL_CALC_FOUND_ROWS p.id_image, '.
-
 
345
            'p.mots_cles_cel_image, '.
-
 
346
            'iv.moyenne AS moyenne_votes, '.
-
 
347
            'iv.nb_votes AS nb_votes, '.
-
 
348
            'iv.nb_points AS nb_points_votes, '.
-
 
349
            'GROUP_CONCAT(DISTINCT it.tag) AS del_image_tags '.
-
 
350
            'FROM del_plantnet_images AS p '.
-
 
351
            '	LEFT JOIN del_image_stat AS iv '.
-
 
352
            '		ON (id_image = iv.ce_image AND iv.ce_protocole = 3) '.
-
 
353
            '	LEFT JOIN del_image_tag AS it '.
-
 
354
            '		ON (id_image = it.ce_image AND it.actif = 1) '.
-
 
355
            '		WHERE id_image = '. $id_image .' '.
-
 
356
            'GROUP BY p.id_image '.
-
 
357
            ' -- '.__FILE__.':'.__LINE__;
-
 
358
        return $this->bdd->recupererTous($requete);
318
 
359
    }
319
}
360
}