Subversion Repositories eFlore/Applications.del

Rev

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

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