Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1924 Rev 2156
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Web service récupèrant toutes les données de la table del_obs_images
4
 * Web service récupèrant toutes les données de la table del_obs_images
5
 * pour retourner une liste d'images associées à la détermination la plus probable.
5
 * pour retourner une liste d'images associées à la détermination la plus probable.
6
 *
6
 *
7
 * Possibilité de ne renvoyer que les images les mieux notées pour un protocole donné.
7
 * Possibilité de ne renvoyer que les images les mieux notées pour un protocole donné.
8
 *
8
 *
9
 * @category   DEL
9
 * @category   DEL
10
 * @package    Services
10
 * @package    Services
11
 * @subpackage Determinations
11
 * @subpackage Determinations
12
 * @version    0.1
12
 * @version    0.1
13
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
13
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
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 ListeImagesDeterminationsProbables {
21
class ListeImagesDeterminationsProbables {
22
 
22
 
23
	private $indexImagesIds = array();
23
	private $indexImagesIds = array();
24
	private $conteneur;
24
	private $conteneur;
25
	private $navigation;
25
	private $navigation;
26
	private $bdd;
26
	private $bdd;
27
 
27
 
28
	private $erreurs = array();
28
	private $erreurs = array();
29
	private $parametres = array();
29
	private $parametres = array();
30
	private $protocoles = array();
30
	private $protocoles = array();
31
 
31
 
32
	private $idsImagesOrdonnees = array();
32
	private $idsImagesOrdonnees = array();
33
	private $resultats = array();
33
	private $resultats = array();
34
	private $propositions = array();
34
	private $propositions = array();
35
	private $votes = array();
35
	private $votes = array();
36
 
36
 
37
	public function __construct(Conteneur $conteneur = null) {
37
	public function __construct(Conteneur $conteneur = null) {
38
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
38
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
39
		$this->navigation = $conteneur->getNavigation();
39
		$this->navigation = $conteneur->getNavigation();
40
		$this->bdd = $this->conteneur->getBdd();
40
		$this->bdd = $this->conteneur->getBdd();
41
		$this->chargerProtocoles();
41
		$this->chargerProtocoles();
42
	}
42
	}
43
 
43
 
44
	private function chargerProtocoles() {
44
	private function chargerProtocoles() {
45
		$requete = 'SELECT id_protocole FROM del_image_protocole -- '.__FILE__.' : '.__LINE__;
45
		$requete = 'SELECT id_protocole FROM del_image_protocole -- '.__FILE__.' : '.__LINE__;
46
		$resultats = $this->bdd->recupererTous($requete);
46
		$resultats = $this->bdd->recupererTous($requete);
47
		if ($resultats) {
47
		if ($resultats) {
48
			foreach ($resultats as $infos) {
48
			foreach ($resultats as $infos) {
49
				$this->protocoles[] = $infos['id_protocole'];
49
				$this->protocoles[] = $infos['id_protocole'];
50
			}
50
			}
51
			sort($this->protocoles);
51
			sort($this->protocoles);
52
		}
52
		}
53
	}
53
	}
54
 
54
 
55
	public function consulter($parametres) {
55
	public function consulter($parametres) {
56
		$this->parametres = $parametres;
56
		$this->parametres = $parametres;
57
		$this->verifierParametres();
57
		$this->verifierParametres();
58
 
58
 
59
		// Lancement du service
59
		// Lancement du service
60
		$this->idsImagesOrdonnees = $this->getIdsImages();
60
		$this->idsImagesOrdonnees = $this->getIdsImages();
61
		$this->modifierEnteteTotal();
61
		$this->modifierEnteteTotal();
62
		$infos = $this->chargerInfos();
62
		$infos = $this->chargerInfos();
63
		if ($infos) {
63
		if ($infos) {
64
			$this->traiterResultats($infos);
64
			$this->traiterResultats($infos);
65
			$this->completerResutlats();
65
			$this->completerResutlats();
66
		}
66
		}
67
 
67
 
68
		// Mettre en forme le résultat et l'envoyer pour affichage
68
		// Mettre en forme le résultat et l'envoyer pour affichage
69
		$resultat = new ResultatService();
69
		$resultat = new ResultatService();
70
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $this->resultats);
70
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $this->resultats);
71
		return $resultat;
71
		return $resultat;
72
	}
72
	}
73
 
73
 
74
	private function verifierParametres() {
74
	private function verifierParametres() {
75
		$this->verifierParamProtocole();
75
		$this->verifierParamProtocole();
76
		$this->verifierParamVote();
76
		$this->verifierParamVote();
77
 
77
 
78
		if (!empty($this->erreurs)) {
78
		if (!empty($this->erreurs)) {
79
			$msg = "Erreur de configuration :\n".implode("\n\n", $this->erreurs);
79
			$msg = "Erreur de configuration :\n".implode("\n\n", $this->erreurs);
80
			throw new Exception($msg, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
80
			throw new Exception($msg, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
81
		}
81
		}
82
	}
82
	}
83
 
83
 
84
	private function verifierParamProtocole() {
84
	private function verifierParamProtocole() {
85
		if (isset($this->parametres['masque.protocole'])) {
85
		if (isset($this->parametres['masque.protocole'])) {
86
			$protocoleExistant = in_array($this->parametres['masque.protocole'], $this->protocoles);
86
			$protocoleExistant = in_array($this->parametres['masque.protocole'], $this->protocoles);
87
 
87
 
88
			if (!is_numeric($this->parametres['masque.protocole']) || $protocoleExistant === false) {
88
			if (!is_numeric($this->parametres['masque.protocole']) || $protocoleExistant === false) {
89
				$protocolesListe = implode(', ', $this->protocoles);
89
				$protocolesListe = implode(', ', $this->protocoles);
90
				$msg = "La valeur pour le protocole doit être un entier compris dans les numéros de protocole ".
90
				$msg = "La valeur pour le protocole doit être un entier compris dans les numéros de protocole ".
91
					"existants : $protocolesListe";
91
					"existants : $protocolesListe";
92
				$this->erreurs[] = $msg;
92
				$this->erreurs[] = $msg;
93
			}
93
			}
94
		}
94
		}
95
	}
95
	}
96
 
96
 
97
	private function verifierParamVote() {
97
	private function verifierParamVote() {
98
		if (isset($this->parametres['masque.valeur_min_vote'])) {
98
		if (isset($this->parametres['masque.valeur_min_vote'])) {
99
			$minVote = $this->parametres['masque.valeur_min_vote'];
99
			$minVote = $this->parametres['masque.valeur_min_vote'];
100
			if (!is_numeric($minVote) || ($minVote < 0 && $minVote > 5)) {
100
			if (!is_numeric($minVote) || ($minVote < 0 && $minVote > 5)) {
101
				$this->erreurs[] = "La valeur minimum de valeur des votes doit être un entier compris entre 0 et 5.";
101
				$this->erreurs[] = "La valeur minimum de valeur des votes doit être un entier compris entre 0 et 5.";
102
			}
102
			}
103
		}
103
		}
104
	}
104
	}
105
 
105
 
106
	private function getIdsImages() {
106
	private function getIdsImages() {
107
		$whereClause = $this->getClauseWhere();
107
		$whereClause = $this->getClauseWhere();
108
		$depart = $this->navigation->getDepart();
108
		$depart = $this->navigation->getDepart();
109
		$limite = $this->navigation->getLimite();
109
		$limite = $this->navigation->getLimite();
110
 
110
 
111
		$requete = 'SELECT DISTINCT SQL_CALC_FOUND_ROWS di.id_image '.
111
		$requete = 'SELECT DISTINCT SQL_CALC_FOUND_ROWS di.id_image '.
112
			'FROM del_image AS di '.
112
			'FROM del_image AS di '.
113
			'	LEFT JOIN del_image_stat AS ds ON (di.id_image = ds.ce_image) '.
113
			'	LEFT JOIN del_image_stat AS ds ON (di.id_image = ds.ce_image) '.
114
			"$whereClause ".
114
			"$whereClause ".
115
			'ORDER BY moyenne DESC, id_image DESC '.
115
			'ORDER BY moyenne DESC, id_image DESC '.
116
			"LIMIT $depart, $limite ".
116
			"LIMIT $depart, $limite ".
117
			' -- '.__FILE__.' : '.__LINE__;
117
			' -- '.__FILE__.' : '.__LINE__;
118
		//Debug::printr($requete);
118
		//Debug::printr($requete);
119
		$resultats = $this->bdd->recupererTous($requete);
119
		$resultats = $this->bdd->recupererTous($requete);
120
		$idImgs = array();
120
		$idImgs = array();
121
		if ($resultats !== false ) {
121
		if ($resultats !== false ) {
122
			foreach ($resultats as $resultat) {
122
			foreach ($resultats as $resultat) {
123
				$idImgs[] = $resultat['id_image'];
123
				$idImgs[] = $resultat['id_image'];
124
			}
124
			}
125
		}
125
		}
126
		return $idImgs;
126
		return $idImgs;
127
	}
127
	}
128
 
128
 
129
	private function getClauseWhere() {
129
	private function getClauseWhere() {
130
		$where = array();
130
		$where = array();
131
		if (isset($this->parametres['masque.protocole'])) {
131
		if (isset($this->parametres['masque.protocole'])) {
132
			$protocoleIdP = $this->bdd->proteger($this->parametres['masque.protocole']);
132
			$protocoleIdP = $this->bdd->proteger($this->parametres['masque.protocole']);
133
			$where[] = "ds.ce_protocole = $protocoleIdP ";
133
			$where[] = "ds.ce_protocole = $protocoleIdP ";
134
		}
134
		}
135
		if (isset($this->parametres['masque.valeur_vote_min'])) {
135
		if (isset($this->parametres['masque.valeur_vote_min'])) {
136
			$voteP = $this->bdd->proteger($this->parametres['masque.valeur_vote_min']);
136
			$voteP = $this->bdd->proteger($this->parametres['masque.valeur_vote_min']);
137
			$where[] = "moyenne >= $voteP";
137
			$where[] = "moyenne >= $voteP";
138
		}
138
		}
139
		return (count($where) > 0) ? 'WHERE '.implode(' AND ', $where).' ' : '';
139
		return (count($where) > 0) ? 'WHERE '.implode(' AND ', $where).' ' : '';
140
	}
140
	}
141
 
141
 
142
	private function chargerInfos() {
142
	private function chargerInfos() {
143
		$idImgsConcat = implode(',', $this->idsImagesOrdonnees);
143
		$idImgsConcat = implode(',', $this->idsImagesOrdonnees);
144
 
144
 
145
		$requete = 'SELECT DISTINCT SQL_CALC_FOUND_ROWS '.
145
		$requete = 'SELECT DISTINCT SQL_CALC_FOUND_ROWS '.
146
			'di.id_image, di.mots_cles_texte AS mots_cles_texte_image, '.
146
			'di.id_image, di.mots_cles_texte AS mots_cles_texte_image, '.
147
			'do.id_observation, nom_referentiel, nom_ret, '.
147
			'do.id_observation, nom_referentiel, nom_ret, '.
148
			'nom_ret_nn, nt, famille, ce_zone_geo, zone_geo, date_observation, '.
148
			'nom_ret_nn, nt, famille, ce_zone_geo, zone_geo, date_observation, '.
149
			'do.ce_utilisateur, do.nom_utilisateur, do.prenom_utilisateur, '.
149
			'do.ce_utilisateur, do.nom_utilisateur, do.prenom_utilisateur, '.
150
			'du.prenom, du.nom '.
150
			'di.prenom_utilisateur as prenom, di.nom_utilisateur as nom '. // retrocompatibilité redondance cheloute
151
			'FROM del_image AS di '.
151
			'FROM del_image AS di '.
152
			'	INNER JOIN del_observation AS do ON (di.ce_observation = do.id_observation) '.
152
			'	INNER JOIN del_observation AS do ON (di.ce_observation = do.id_observation) '.
153
			'	LEFT JOIN del_utilisateur AS du ON (di.ce_utilisateur = du.id_utilisateur) '.
-
 
154
			'	LEFT JOIN del_image_stat AS ds ON (di.id_image = ds.ce_image) '.
153
			'	LEFT JOIN del_image_stat AS ds ON (di.id_image = ds.ce_image) '.
155
			"WHERE di.id_image IN ($idImgsConcat) ".
154
			"WHERE di.id_image IN ($idImgsConcat) ".
156
			'ORDER BY moyenne DESC, id_image DESC '.
155
			'ORDER BY moyenne DESC, id_image DESC '.
157
			' -- '.__FILE__.' : '.__LINE__;
156
			' -- '.__FILE__.' : '.__LINE__;
158
		//Debug::printr($requete);
157
		//Debug::printr($requete);
159
		return $this->bdd->recupererTous($requete);
158
		return $this->bdd->recupererTous($requete);
160
	}
159
	}
161
 
160
 
162
	private function modifierEnteteTotal() {
161
	private function modifierEnteteTotal() {
163
		$requete = 'SELECT FOUND_ROWS() AS nbre -- '.__FILE__.' : '.__LINE__;
162
		$requete = 'SELECT FOUND_ROWS() AS nbre -- '.__FILE__.' : '.__LINE__;
164
		$compte = $this->bdd->recuperer($requete);
163
		$compte = $this->bdd->recuperer($requete);
165
		$total = ($compte !== false) ? (int) $compte['nbre'] : 0;
164
		$total = ($compte !== false) ? (int) $compte['nbre'] : 0;
166
		$this->navigation->setTotal($total);
165
		$this->navigation->setTotal($total);
167
	}
166
	}
168
 
167
 
169
	/**
168
	/**
170
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
169
	* Retourner un tableau d'images formaté en fonction des liaisons trouvées
171
	* @param $infos les infos sur les images et observations
170
	* @param $infos les infos sur les images et observations
172
	* */
171
	* */
173
	private function traiterResultats($infos) {
172
	private function traiterResultats($infos) {
174
		//Debug::printr($infos);
173
		//Debug::printr($infos);
175
		foreach ($infos as $info) {
174
		foreach ($infos as $info) {
176
			$idImage = $info['id_image'];
175
			$idImage = $info['id_image'];
177
			$index = $this->formaterIndexResultat($info);
176
			$index = $this->formaterIndexResultat($info);
178
 
177
 
179
			$this->obsIds[] = $info['id_observation'];
178
			$this->obsIds[] = $info['id_observation'];
180
			$this->indexImagesIds[$idImage] = $index;
179
			$this->indexImagesIds[$idImage] = $index;
181
			$this->resultats[$index] = array(
180
			$this->resultats[$index] = array(
182
				'id_image' => $idImage,
181
				'id_image' => $idImage,
183
				'id_observation' => $info['id_observation'],
182
				'id_observation' => $info['id_observation'],
184
				'auteur.intitule' => $this->formaterIntituleAuteur($info),
183
				'auteur.intitule' => $this->formaterIntituleAuteur($info),
185
				'binaire.href' => $this->formaterBinaireHref($info),
184
				'binaire.href' => $this->formaterBinaireHref($info),
186
				'determination.famille' => $info['famille'],
185
				'determination.famille' => $info['famille'],
187
				'determination.referentiel' => $info['nom_referentiel'],
186
				'determination.referentiel' => $info['nom_referentiel'],
188
				'determination.ns' => $info['nom_ret'],
187
				'determination.ns' => $info['nom_ret'],
189
				'determination.nn' => $info['nom_ret_nn'],
188
				'determination.nn' => $info['nom_ret_nn'],
190
				'determination.nt' => $info['nt'],
189
				'determination.nt' => $info['nt'],
191
				'date_observation' => $info['date_observation'],
190
				'date_observation' => $info['date_observation'],
192
				'localite' => $this->formaterLieu($info),
191
				'localite' => $this->formaterLieu($info),
193
				'mots_cles_image_cel' => $this->formaterMotsClesCel($info),
192
				'mots_cles_image_cel' => $this->formaterMotsClesCel($info),
194
				'mots_cles_image_del' => ''
193
				'mots_cles_image_del' => ''
195
			);
194
			);
196
		}
195
		}
197
	}
196
	}
198
 
197
 
199
	private function formaterIndexResultat($infos) {
198
	private function formaterIndexResultat($infos) {
200
		return $infos['id_image'].'-'.$infos['id_observation'];
199
		return $infos['id_image'].'-'.$infos['id_observation'];
201
	}
200
	}
202
 
201
 
203
	private function formaterIntituleAuteur($infos) {
202
	private function formaterIntituleAuteur($infos) {
204
		if ($infos['ce_utilisateur'] == 0) {
203
		if ($infos['ce_utilisateur'] == 0) {
205
			$infos['prenom'] = $infos['prenom_utilisateur'];
204
			$infos['prenom'] = $infos['prenom_utilisateur'];
206
			$infos['nom'] = $infos['nom_utilisateur'];
205
			$infos['nom'] = $infos['nom_utilisateur'];
207
		}
206
		}
208
		$intitule = $infos['prenom'].' '.$infos['nom'];
207
		$intitule = $infos['prenom'].' '.$infos['nom'];
209
		return $intitule;
208
		return $intitule;
210
	}
209
	}
211
 
210
 
212
	private function formaterBinaireHref($infos) {
211
	private function formaterBinaireHref($infos) {
213
		return sprintf(
212
		return sprintf(
214
			$this->conteneur->getParametre('cel_img_url_tpl'),
213
			$this->conteneur->getParametre('cel_img_url_tpl'),
215
			$infos['id_image'],
214
			$infos['id_image'],
216
			$this->conteneur->getParametre('determinations.format_image')
215
			$this->conteneur->getParametre('determinations.format_image')
217
		);
216
		);
218
	}
217
	}
219
 
218
 
220
	private function formaterLieu($infos) {
219
	private function formaterLieu($infos) {
221
		$lieuFormate = '';
220
		$lieuFormate = '';
222
		if ($infos['ce_zone_geo']) {
221
		if ($infos['ce_zone_geo']) {
223
			$lieu = $infos['zone_geo'];
222
			$lieu = $infos['zone_geo'];
224
			$id_zone_geo = $infos['ce_zone_geo'];
223
			$id_zone_geo = $infos['ce_zone_geo'];
225
			if (strpos($infos['ce_zone_geo'], 'INSEE-C:') === 0) {
224
			if (strpos($infos['ce_zone_geo'], 'INSEE-C:') === 0) {
226
				$id_zone_geo = str_replace('INSEE-C:', '', $infos['ce_zone_geo']);
225
				$id_zone_geo = str_replace('INSEE-C:', '', $infos['ce_zone_geo']);
227
				$id_zone_geo = strlen($id_zone_geo) >= 5 ? substr($id_zone_geo, 0, 2) : $id_zone_geo;
226
				$id_zone_geo = strlen($id_zone_geo) >= 5 ? substr($id_zone_geo, 0, 2) : $id_zone_geo;
228
			}
227
			}
229
			$lieuFormate =  "$lieu ($id_zone_geo)";
228
			$lieuFormate =  "$lieu ($id_zone_geo)";
230
		}
229
		}
231
		return $lieuFormate;
230
		return $lieuFormate;
232
	}
231
	}
233
 
232
 
234
	/**
233
	/**
235
	 * Formater les mots clés du cel en n'affichant que ceux faisant partie d'une liste définie dans le
234
	 * Formater les mots clés du cel en n'affichant que ceux faisant partie d'une liste définie dans le
236
	 * fichier de configuration.
235
	 * fichier de configuration.
237
	 *
236
	 *
238
	 * @param $infos le tableau contenant les infos sur une image.
237
	 * @param $infos le tableau contenant les infos sur une image.
239
	 * @return string la chaine filtrée
238
	 * @return string la chaine filtrée
240
	 */
239
	 */
241
	private function formaterMotsClesCel($infos) {
240
	private function formaterMotsClesCel($infos) {
242
		$motsClesAffiches = $this->conteneur->getParametreTableau('determinations.mots_cles_cel_affiches');
241
		$motsClesAffiches = $this->conteneur->getParametreTableau('determinations.mots_cles_cel_affiches');
243
		$motsClesCel = explode(',', $infos['mots_cles_texte_image']);
242
		$motsClesCel = explode(',', $infos['mots_cles_texte_image']);
244
		$motsCles = array_intersect($motsClesAffiches, $motsClesCel);
243
		$motsCles = array_intersect($motsClesAffiches, $motsClesCel);
245
		return implode(',', $motsCles);
244
		return implode(',', $motsCles);
246
	}
245
	}
247
 
246
 
248
	private function completerResutlats() {
247
	private function completerResutlats() {
249
		$this->chargerVotes();
248
		$this->chargerVotes();
250
		$this->chargerPropositions();
249
		$this->chargerPropositions();
251
 
250
 
252
		$this->completerMotsCles();
251
		$this->completerMotsCles();
253
 
252
 
254
		foreach ($this->resultats as $index => $infos) {
253
		foreach ($this->resultats as $index => $infos) {
255
			if ($this->doitRemplacerObservationParProposition($index)) {
254
			if ($this->doitRemplacerObservationParProposition($index)) {
256
				$id_obs = $infos['id_observation'];
255
				$id_obs = $infos['id_observation'];
257
				$this->resultats[$index]['determination.famille'] = $this->propositions[$id_obs]['famille'];
256
				$this->resultats[$index]['determination.famille'] = $this->propositions[$id_obs]['famille'];
258
				$this->resultats[$index]['determination.ns'] = $this->propositions[$id_obs]['nom_sel'];
257
				$this->resultats[$index]['determination.ns'] = $this->propositions[$id_obs]['nom_sel'];
259
				$this->resultats[$index]['determination.nn'] = $this->propositions[$id_obs]['nom_sel_nn'];
258
				$this->resultats[$index]['determination.nn'] = $this->propositions[$id_obs]['nom_sel_nn'];
260
				$this->resultats[$index]['determination.nt'] = $this->propositions[$id_obs]['nt'];
259
				$this->resultats[$index]['determination.nt'] = $this->propositions[$id_obs]['nt'];
261
				$this->resultats[$index]['determination.referentiel'] = $this->propositions[$id_obs]['nom_referentiel'];
260
				$this->resultats[$index]['determination.referentiel'] = $this->propositions[$id_obs]['nom_referentiel'];
262
			}
261
			}
263
			$this->completerUrlFicheEflore($index);
262
			$this->completerUrlFicheEflore($index);
264
		}
263
		}
265
	}
264
	}
266
 
265
 
267
	private function chargerVotes() {
266
	private function chargerVotes() {
268
		$idsObs = implode(',', $this->obsIds);
267
		$idsObs = implode(',', $this->obsIds);
269
		$requete = 'SELECT ce_proposition, valeur, ce_utilisateur '.
268
		$requete = 'SELECT ce_proposition, valeur, ce_utilisateur '.
270
			'FROM del_commentaire_vote '.
269
			'FROM del_commentaire_vote '.
271
			'WHERE ce_proposition IN '.
270
			'WHERE ce_proposition IN '.
272
			'( SELECT id_commentaire '.
271
			'( SELECT id_commentaire '.
273
			'	FROM del_commentaire '.
272
			'	FROM del_commentaire '.
274
			"	WHERE ce_observation IN ($idsObs) AND nom_sel IS NOT NULL ) ".
273
			"	WHERE ce_observation IN ($idsObs) AND nom_sel IS NOT NULL ) ".
275
			'ORDER BY ce_proposition '.
274
			'ORDER BY ce_proposition '.
276
			' -- '.__FILE__.' : '.__LINE__;
275
			' -- '.__FILE__.' : '.__LINE__;
277
		$resultats = $this->bdd->recupererTous($requete);
276
		$resultats = $this->bdd->recupererTous($requete);
278
		if ($resultats !== false) {
277
		if ($resultats !== false) {
279
			foreach ($resultats as $vote) {
278
			foreach ($resultats as $vote) {
280
				if (!isset($this->votes[$vote['ce_proposition']])) {
279
				if (!isset($this->votes[$vote['ce_proposition']])) {
281
					$this->votes[$vote['ce_proposition']] = 0;
280
					$this->votes[$vote['ce_proposition']] = 0;
282
				}
281
				}
283
				$valeur = ($vote['valeur'] == 1) ? 1 : -1;
282
				$valeur = ($vote['valeur'] == 1) ? 1 : -1;
284
				$this->votes[$vote['ce_proposition']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
283
				$this->votes[$vote['ce_proposition']] += is_numeric($vote['ce_utilisateur']) ? 3 * $valeur : $valeur;
285
			}
284
			}
286
		}
285
		}
287
	}
286
	}
288
 
287
 
289
	private function chargerPropositions() {
288
	private function chargerPropositions() {
290
		$idsObs = implode(',', $this->obsIds);
289
		$idsObs = implode(',', $this->obsIds);
291
		$requete = 'SELECT * '.
290
		$requete = 'SELECT * '.
292
			'FROM del_commentaire '.
291
			'FROM del_commentaire '.
293
			"WHERE ce_observation IN ($idsObs) ".
292
			"WHERE ce_observation IN ($idsObs) ".
294
			'AND nom_sel IS NOT NULL '.
293
			'AND nom_sel IS NOT NULL '.
295
			' -- '.__FILE__.' : '.__LINE__;
294
			' -- '.__FILE__.' : '.__LINE__;
296
		$resultats = $this->bdd->recupererTous($requete);
295
		$resultats = $this->bdd->recupererTous($requete);
297
 
296
 
298
		foreach($resultats as $proposition) {
297
		foreach($resultats as $proposition) {
299
			$id_proposition = $proposition['id_commentaire'];
298
			$id_proposition = $proposition['id_commentaire'];
300
			$id_obs = $proposition['ce_observation'];
299
			$id_obs = $proposition['ce_observation'];
301
			$proposition['valeur'] = (isset($this->votes[$id_proposition])) ? $this->votes[$id_proposition] : -1;
300
			$proposition['valeur'] = (isset($this->votes[$id_proposition])) ? $this->votes[$id_proposition] : -1;
302
 
301
 
303
			if (!isset($this->propositions[$id_obs])) {
302
			if (!isset($this->propositions[$id_obs])) {
304
				$this->propositions[$id_obs] = $proposition;
303
				$this->propositions[$id_obs] = $proposition;
305
			} else {
304
			} else {
306
				$score_actuel = $proposition['valeur'];
305
				$score_actuel = $proposition['valeur'];
307
				$score_precedent = $this->propositions[$id_obs]['valeur'];
306
				$score_precedent = $this->propositions[$id_obs]['valeur'];
308
				if ($score_actuel >= $score_precedent) {
307
				if ($score_actuel >= $score_precedent) {
309
					$this->propositions[$id_obs] = $proposition;
308
					$this->propositions[$id_obs] = $proposition;
310
				}
309
				}
311
			}
310
			}
312
		}
311
		}
313
	}
312
	}
314
 
313
 
315
	private function completerMotsCles() {
314
	private function completerMotsCles() {
316
		$idsImages = implode(',', array_keys($this->indexImagesIds));
315
		$idsImages = implode(',', array_keys($this->indexImagesIds));
317
		$requete = 'SELECT tag, ce_image '.
316
		$requete = 'SELECT tag, ce_image '.
318
			'FROM del_image_tag '.
317
			'FROM del_image_tag '.
319
			"WHERE ce_image IN ($idsImages) ".
318
			"WHERE ce_image IN ($idsImages) ".
320
			'AND actif = 1 '.
319
			'AND actif = 1 '.
321
			' -- '.__FILE__.' : '.__LINE__;
320
			' -- '.__FILE__.' : '.__LINE__;
322
		$resultats = $this->bdd->recupererTous($requete);
321
		$resultats = $this->bdd->recupererTous($requete);
323
 
322
 
324
		foreach ($resultats as $info) {
323
		foreach ($resultats as $info) {
325
			$index = $this->indexImagesIds[$info['ce_image']];
324
			$index = $this->indexImagesIds[$info['ce_image']];
326
			$tag = ($this->resultats[$index]['mots_cles_image_del'] != '') ? ','.$info['tag'] : $info['tag'];
325
			$tag = ($this->resultats[$index]['mots_cles_image_del'] != '') ? ','.$info['tag'] : $info['tag'];
327
			$this->resultats[$index]['mots_cles_image_del'] .= $tag ;
326
			$this->resultats[$index]['mots_cles_image_del'] .= $tag ;
328
		}
327
		}
329
	}
328
	}
330
 
329
 
331
	private function doitRemplacerObservationParProposition($index) {
330
	private function doitRemplacerObservationParProposition($index) {
332
		$idObs = $this->resultats[$index]['id_observation'];
331
		$idObs = $this->resultats[$index]['id_observation'];
333
		return ((isset($this->propositions[$idObs])
332
		return ((isset($this->propositions[$idObs])
334
			&& $this->propositions[$idObs] != null
333
			&& $this->propositions[$idObs] != null
335
			&& $this->propositions[$idObs]['nom_sel_nn'] != 0)
334
			&& $this->propositions[$idObs]['nom_sel_nn'] != 0)
336
			&& ($this->propositions[$idObs]['valeur'] > 0 || 	$this->resultats[$index]['determination.nn'] == 0)
335
			&& ($this->propositions[$idObs]['valeur'] > 0 || 	$this->resultats[$index]['determination.nn'] == 0)
337
		);
336
		);
338
	}
337
	}
339
 
338
 
340
	private function completerUrlFicheEflore($index) {
339
	private function completerUrlFicheEflore($index) {
341
		if (isset($this->resultats[$index]['determination.nn'])) {
340
		if (isset($this->resultats[$index]['determination.nn'])) {
342
			$urlTpl = $this->conteneur->getParametre('determinations.url_fiche_eflore_tpl');
341
			$urlTpl = $this->conteneur->getParametre('determinations.url_fiche_eflore_tpl');
343
			$nn = (int) $this->resultats[$index]['determination.nn'];
342
			$nn = (int) $this->resultats[$index]['determination.nn'];
344
			$ref = $this->resultats[$index]['determination.referentiel'];
343
			$ref = $this->resultats[$index]['determination.referentiel'];
345
			$code_ref = $this->getCodeReferentiel($ref);
344
			$code_ref = $this->getCodeReferentiel($ref);
346
			if (is_int($nn) && ! isset($code_ref)) {
345
			if (is_int($nn) && ! isset($code_ref)) {
347
				$code_ref = 'bdtfx';
346
				$code_ref = 'bdtfx';
348
			}
347
			}
349
			$this->resultats[$index]['url_fiche_eflore'] = sprintf($urlTpl, $code_ref, $nn);
348
			$this->resultats[$index]['url_fiche_eflore'] = sprintf($urlTpl, $code_ref, $nn);
350
		}
349
		}
351
	}
350
	}
352
 
351
 
353
	private function getCodeReferentiel($ref) {
352
	private function getCodeReferentiel($ref) {
354
		$code = $ref;
353
		$code = $ref;
355
		if ($position = strpos($ref, '_')) {
354
		if ($position = strpos($ref, '_')) {
356
			$code = substr($ref, 0, $position);
355
			$code = substr($ref, 0, $position);
357
		} else if ($position = strpos($ref, ':')) {
356
		} else if ($position = strpos($ref, ':')) {
358
			$code = substr($ref, 0, $position);
357
			$code = substr($ref, 0, $position);
359
		}
358
		}
360
		return $code;
359
		return $code;
361
	}
360
	}
362
}
361
}