Line 19... |
Line 19... |
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
20 |
* @version $Id$
|
20 |
* @version $Id$
|
21 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
21 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
22 |
*/
|
22 |
*/
|
23 |
class Vote extends WidgetCommun {
|
23 |
class Vote extends WidgetCommun {
|
24 |
|
24 |
|
25 |
const DS = DIRECTORY_SEPARATOR;
|
25 |
const DS = DIRECTORY_SEPARATOR;
|
26 |
const SERVICE_DEFAUT = 'photo';
|
26 |
const SERVICE_DEFAUT = 'photo';
|
- |
|
27 |
|
27 |
private $ce_img_url_tpl = null;
|
28 |
private $ce_img_url_tpl = null;
|
28 |
private $del_url_service_tpl = null;
|
29 |
private $del_url_service_tpl = null;
|
29 |
|
30 |
|
30 |
private $id_observation_suivant = null;
|
- |
|
31 |
private $id_observation_precedent = null;
|
- |
|
32 |
private $id_observation = null;
|
31 |
private $id_observation = null;
|
33 |
|
32 |
|
34 |
/**
|
33 |
/**
|
35 |
* Méthode appelée par défaut pour charger ce widget.
|
34 |
* Méthode appelée par défaut pour charger ce widget.
|
36 |
*/
|
35 |
*/
|
37 |
public function executer() {
|
36 |
public function executer() {
|
38 |
$this->del_url_service_tpl = $this->config['vote']['baseURLServicesDelTpl'];
|
37 |
$this->del_url_service_tpl = $this->config['vote']['baseURLServicesDelTpl'];
|
39 |
$this->ce_img_url_tpl = $this->config['vote']['celImgUrlTpl'];
|
38 |
$this->ce_img_url_tpl = $this->config['vote']['celImgUrlTpl'];
|
40 |
|
39 |
|
41 |
$this->collecterParametres();
|
40 |
$this->collecterParametres();
|
42 |
$ids_observations = $this->obtenirIdsObservation();
|
41 |
$ids_observations = $this->obtenirIdsObservation();
|
43 |
$donnees = $this->obtenirDonnees($this->id_observation);
|
42 |
$donnees = $this->obtenirDonnees($this->id_observation);
|
Line 44... |
Line 43... |
44 |
|
43 |
|
Line 51... |
Line 50... |
51 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/scripts/');
|
50 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/scripts/');
|
52 |
$widget['donnees']['votes_js'] = $this->convertirTableauVotesEnJs($donnees['commentaires']);
|
51 |
$widget['donnees']['votes_js'] = $this->convertirTableauVotesEnJs($donnees['commentaires']);
|
53 |
$widget['donnees']['url_service_votes'] = $this->del_url_service_tpl.'observations/'.$this->id_observation;
|
52 |
$widget['donnees']['url_service_votes'] = $this->del_url_service_tpl.'observations/'.$this->id_observation;
|
54 |
$widget['donnees']['url_service_utilisateurs'] = $this->del_url_service_tpl.'utilisateurs/';
|
53 |
$widget['donnees']['url_service_utilisateurs'] = $this->del_url_service_tpl.'utilisateurs/';
|
55 |
$widget['donnees']['urls_navigation'] = $this->construireUrlsSuivantesEtPrecedentes($ids_observations);
|
54 |
$widget['donnees']['urls_navigation'] = $this->construireUrlsSuivantesEtPrecedentes($ids_observations);
|
56 |
|
55 |
|
57 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == 'ajax') {
|
56 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == 'ajax') {
|
58 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote_ajax.tpl.html';
|
57 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote_ajax.tpl.html';
|
59 |
} else {
|
58 |
} else {
|
60 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote.tpl.html';
|
59 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote.tpl.html';
|
61 |
}
|
60 |
}
|
62 |
|
61 |
|
63 |
$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);
|
62 |
$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);
|
64 |
|
63 |
|
65 |
$this->envoyer($contenu);
|
64 |
$this->envoyer($contenu);
|
66 |
}
|
65 |
}
|
67 |
|
66 |
|
68 |
private function collecterParametres() {
|
67 |
private function collecterParametres() {
|
69 |
$this->id_observation = (isset($_GET['id_observation'])) ? $_GET['id_observation'] : null;
|
68 |
$this->id_observation = (isset($_GET['id_observation'])) ? $_GET['id_observation'] : null;
|
70 |
unset($_GET['id_observation']);
|
69 |
unset($_GET['id_observation']);
|
71 |
$this->parametres = $_GET;
|
70 |
$this->parametres = $_GET;
|
72 |
}
|
71 |
}
|
73 |
|
72 |
|
74 |
private function convertirParametresEnChaineRequeteService() {
|
73 |
private function convertirParametresEnChaineRequeteService() {
|
75 |
$requete = '';
|
74 |
$parametresWs = array();
|
76 |
$mapping = $this->config['mapping_masque'];
|
75 |
$mapping = $this->transformerEnTableau($this->config['vote']['mapping_masque']);
|
77 |
if(!empty($this->parametres)) {
|
76 |
if (!empty($this->parametres)) {
|
78 |
foreach ($this->parametres as $parametre=>$valeur) {
|
77 |
foreach ($this->parametres as $parametre => $valeur) {
|
79 |
if (isset($mapping[$parametre])) {
|
78 |
if (isset($mapping[$parametre])) {
|
80 |
$requete .= '&'.$mapping[$parametre].'='.urlencode($valeur);
|
79 |
$parametresWs[] = $mapping[$parametre].'='.urlencode($valeur);
|
81 |
}
|
80 |
}
|
82 |
}
|
81 |
}
|
83 |
}
|
82 |
}
|
- |
|
83 |
$requete = (!empty($parametresWs)) ? '?'.implode('&', $parametresWs) : '';
|
84 |
return $requete;
|
84 |
return $requete;
|
85 |
}
|
85 |
}
|
86 |
|
86 |
|
87 |
private function convertirParametresEnChaineRequete() {
|
87 |
private function convertirParametresEnChaineRequete() {
|
88 |
$requete = str_replace('masque_','masque.',http_build_query($this->parametres));
|
88 |
$requete = str_replace('masque_','masque.',http_build_query($this->parametres));
|
89 |
if(!empty($this->parametres)) {
|
89 |
if(!empty($this->parametres)) {
|
90 |
$requete = '&'.$requete;
|
90 |
$requete = '&'.$requete;
|
91 |
}
|
91 |
}
|
92 |
return $requete;
|
92 |
return $requete;
|
93 |
}
|
93 |
}
|
94 |
|
94 |
|
95 |
private function obtenirIdsObservation() {
|
95 |
private function obtenirIdsObservation() {
|
96 |
$ids = json_decode(file_get_contents($this->del_url_service_tpl.'observations?retour.format=widget'.$this->convertirParametresEnChaineRequeteService()), true);
|
96 |
$url = $this->del_url_service_tpl.'observations'.$this->convertirParametresEnChaineRequeteService();
|
- |
|
97 |
//exit('<pre>'.print_r($url, true).'</pre>');
|
- |
|
98 |
$infos = json_decode(file_get_contents($url), true);
|
- |
|
99 |
//exit('<pre>'.print_r($infos, true).'</pre>');
|
- |
|
100 |
$ids = array();
|
- |
|
101 |
foreach ($infos['resultats'] as $resultat) {
|
97 |
if($this->id_observation == null) {
|
102 |
if ($this->id_observation == null) {
|
98 |
$this->id_observation = $ids['resultats'][0];
|
103 |
$this->id_observation = $resultat['id_observation'];
|
- |
|
104 |
}
|
- |
|
105 |
$ids[] = $resultat['id_observation'];
|
99 |
}
|
106 |
}
|
100 |
return $ids['resultats'];
|
107 |
return $ids;
|
101 |
}
|
108 |
}
|
102 |
|
109 |
|
103 |
private function obtenirUrlBaseWidget() {
|
110 |
private function obtenirUrlBaseWidget() {
|
104 |
return $this->config['chemins']['baseURL'].'vote';
|
111 |
return $this->config['chemins']['baseURL'].'vote';
|
105 |
}
|
112 |
}
|
106 |
|
113 |
|
107 |
private function construireUrlsSuivantesEtPrecedentes($tableau_id_observation) {
|
114 |
private function construireUrlsSuivantesEtPrecedentes($tableau_id_observation) {
|
108 |
|
- |
|
109 |
$indices_id_obs = array_flip($tableau_id_observation);
|
115 |
$indices_id_obs = array_flip($tableau_id_observation);
|
110 |
$indice_obs_courante = $indices_id_obs[$this->id_observation];
|
116 |
$indice_obs_courante = $indices_id_obs[$this->id_observation];
|
111 |
$url_base = $this->obtenirUrlBaseWidget();
|
117 |
$url_base = $this->obtenirUrlBaseWidget();
|
112 |
|
118 |
|
113 |
$indice_predecent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $tableau_id_observation[$indice_obs_courante - 1] : '';
|
119 |
$indice_predecent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $tableau_id_observation[$indice_obs_courante - 1] : '';
|
114 |
$indice_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $tableau_id_observation[$indice_obs_courante + 1] : '';
|
120 |
$indice_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $tableau_id_observation[$indice_obs_courante + 1] : '';
|
115 |
|
121 |
|
116 |
$url_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante + 1].$this->convertirParametresEnChaineRequete() : null;
|
122 |
$url_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante + 1].$this->convertirParametresEnChaineRequete() : null;
|
117 |
$url_precedent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante - 1].$this->convertirParametresEnChaineRequete() : null;
|
123 |
$url_precedent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante - 1].$this->convertirParametresEnChaineRequete() : null;
|
Line 118... |
Line 124... |
118 |
|
124 |
|
119 |
return array('url_suivant' => $url_suivant,
|
- |
|
120 |
'url_precedent' => $url_precedent
|
- |
|
121 |
);
|
125 |
return array('url_suivant' => $url_suivant, 'url_precedent' => $url_precedent);
|
122 |
}
|
126 |
}
|
123 |
|
127 |
|
124 |
private function obtenirDonnees($id_observation) {
|
128 |
private function obtenirDonnees($id_observation) {
|
- |
|
129 |
$donnees = json_decode(file_get_contents($this->del_url_service_tpl.'observations/'.$id_observation), true);
|
125 |
$donnees = json_decode(file_get_contents($this->del_url_service_tpl.'observations/'.$id_observation), true);
|
130 |
//exit('<pre>'.print_r($donnees, true).'</pre>');
|
126 |
return $donnees;
|
131 |
return $donnees;
|
127 |
}
|
132 |
}
|
128 |
|
133 |
|
129 |
private function construireTitreImage($donnees) {
|
134 |
private function construireTitreImage($donnees) {
|
130 |
return 'Pris par '.$donnees['auteur.prenom'].' '.$donnees['auteur.nom'].' à '.$donnees['zone_geo'].' le '.$this->formaterDate($donnees['date_observation'],'%d/%m/%Y');
|
135 |
return 'Pris par '.$donnees['auteur.prenom'].' '.$donnees['auteur.nom'].' à '.$donnees['zone_geo'].' le '.$this->formaterDate($donnees['date_observation'],'%d/%m/%Y');
|
131 |
}
|
136 |
}
|
132 |
|
137 |
|
133 |
private function obtenirUrlImage($images) {
|
138 |
private function obtenirUrlImage($images) {
|
134 |
return $images[0]['binaire.href'];
|
139 |
return $images[0]['binaire.href'];
|
135 |
}
|
140 |
}
|
136 |
|
141 |
|
137 |
private function formaterDeterminations($observation) {
|
142 |
private function formaterDeterminations($observation) {
|
138 |
$liste_determinations = $observation['commentaires'];
|
143 |
$liste_determinations = $observation['commentaires'];
|
139 |
$liste_determinations_formatees = array();
|
- |
|
140 |
|
144 |
$liste_determinations_formatees = array();
|
141 |
$creerPropositionAPartirObservation = true;
|
145 |
$creerPropositionAPartirObservation = true;
|
142 |
|
146 |
|
143 |
foreach ($liste_determinations as $determination) {
|
- |
|
144 |
$determination_formatee = $determination;
|
147 |
foreach ($liste_determinations as $determination) {
|
145 |
if($determination['nom_sel'] != null && $determination['nom_sel'] != '') {
|
- |
|
146 |
$determination_formatee['votes'] = $this->formaterVotes($determination['votes']);
|
148 |
if ($determination['nom_sel'] != null && $determination['nom_sel'] != '') {
|
147 |
$liste_determinations_formatees[] = $determination_formatee;
|
149 |
$liste_determinations_formatees[] = $this->formaterDetermination($determination);
|
148 |
}
|
150 |
}
|
149 |
|
151 |
|
150 |
if($determination['nom_sel'] == $observation['determination.ns'] &&
|
152 |
if ($determination['nom_sel'] == $observation['determination.ns'] &&
|
151 |
$determination['auteur.id'] == $observation['auteur.id']) {
|
153 |
$determination['auteur.id'] == $observation['auteur.id']) {
|
152 |
$creerPropositionAPartirObservation = false;
|
154 |
$creerPropositionAPartirObservation = false;
|
153 |
}
|
155 |
}
|
154 |
}
|
156 |
}
|
155 |
|
157 |
|
156 |
if($creerPropositionAPartirObservation) {
|
158 |
if ($creerPropositionAPartirObservation) {
|
157 |
$liste_determinations_formatees[] = $this->creerDeterminationAPartirObservation($observation);
|
159 |
$liste_determinations_formatees[] = $this->creerDeterminationAPartirObservation($observation);
|
158 |
}
|
160 |
}
|
159 |
|
161 |
|
160 |
return $liste_determinations_formatees;
|
162 |
return $liste_determinations_formatees;
|
161 |
}
|
163 |
}
|
- |
|
164 |
|
- |
|
165 |
private function formaterDetermination($infos) {
|
- |
|
166 |
//exit('<pre>'.print_r($infos, true).'</pre>');
|
- |
|
167 |
$determination = array(
|
- |
|
168 |
"id_commentaire" => $infos['id_commentaire'],
|
- |
|
169 |
"observation" => $infos['observation'],
|
- |
|
170 |
"proposition" => $infos['proposition'],
|
- |
|
171 |
"id_parent" => $infos['id_parent'],
|
- |
|
172 |
"texte" => $infos['texte'],
|
- |
|
173 |
"date" => $infos['date_observation'],
|
- |
|
174 |
"nom_sel" => $infos['nom_sel'],
|
- |
|
175 |
"auteur_intitule" => $this->formaterIntituleAuteur($infos),
|
- |
|
176 |
"votes" => $this->formaterVotes($infos['votes'])
|
- |
|
177 |
);
|
- |
|
178 |
return $determination;
|
- |
|
179 |
}
|
162 |
|
180 |
|
- |
|
181 |
private function creerDeterminationAPartirObservation($observation) {
|
163 |
private function creerDeterminationAPartirObservation($observation) {
|
182 |
$determination = array(
|
164 |
$proposition = array("id_commentaire" => "0",
|
183 |
"id_commentaire" => "0",
|
165 |
"observation" => $observation['id_observation'],
|
184 |
"observation" => $observation['id_observation'],
|
166 |
"proposition" => "0",
|
185 |
"proposition" => "0",
|
167 |
"id_parent" => "0",
|
- |
|
168 |
"auteur.id" => $observation['auteur.id'],
|
186 |
"id_parent" => "0",
|
169 |
"texte" => null,
|
- |
|
170 |
"auteur.nom" => $observation['auteur.nom'],
|
- |
|
171 |
"auteur.prenom" => $observation['auteur.prenom'],
|
187 |
"texte" => null,
|
172 |
"auteur.courriel" => $observation['observateur'],
|
188 |
"date" => $observation['date_observation'],
|
173 |
"date" => $observation['date_observation'],
|
189 |
"nom_sel" => $observation['determination.ns'],
|
174 |
"nom_sel" => $observation['determination.ns'],
|
190 |
"auteur_intitule" => $this->formaterIntituleAuteur($observation),
|
175 |
"votes" => array('oui' => 0, 'non' => 0)
|
191 |
"votes" => array('oui' => 0, 'non' => 0)
|
176 |
);
|
- |
|
177 |
|
192 |
);
|
178 |
return $proposition;
|
193 |
return $determination;
|
179 |
}
|
194 |
}
|
- |
|
195 |
|
- |
|
196 |
private function formaterIntituleAuteur($donnees) {
|
- |
|
197 |
$intitule = 'Anonyme';
|
- |
|
198 |
// TODO : si auteur.id existe, appelé le WS de l'annuaire...
|
- |
|
199 |
if (!empty($donnees['auteur.prenom']) && !empty($donnees['auteur.nom'])) {
|
- |
|
200 |
$intitule = $donnees['auteur.prenom'].' '.$donnees['auteur.nom'];
|
- |
|
201 |
} else if (!empty($donnees['auteur.courriel'])) {
|
- |
|
202 |
$intitule = strstr($donnees['auteur.courriel'], '@').'@...';
|
- |
|
203 |
}
|
- |
|
204 |
return $intitule;
|
- |
|
205 |
}
|
180 |
|
206 |
|
181 |
private function formaterVotes($liste_votes) {
|
207 |
private function formaterVotes($liste_votes) {
|
182 |
$liste_votes_formates = array('oui' => 0, 'non' => 0);
|
208 |
$liste_votes_formates = array('oui' => 0, 'non' => 0);
|
183 |
foreach($liste_votes as $vote) {
|
209 |
foreach($liste_votes as $vote) {
|
184 |
if($vote['vote'] == 1) {
|
210 |
if($vote['vote'] == 1) {
|
185 |
$liste_votes_formates['oui']++;
|
211 |
$liste_votes_formates['oui']++;
|
186 |
} else {
|
212 |
} else {
|
187 |
$liste_votes_formates['non']++;
|
213 |
$liste_votes_formates['non']++;
|
188 |
}
|
214 |
}
|
189 |
}
|
- |
|
190 |
|
215 |
}
|
191 |
return $liste_votes_formates;
|
216 |
return $liste_votes_formates;
|
192 |
}
|
217 |
}
|
193 |
|
218 |
|
194 |
private function convertirTableauVotesEnJs($liste_commentaires) {
|
219 |
private function convertirTableauVotesEnJs($liste_commentaires) {
|
195 |
$tableau_js = "var g_votes = new Array();";
|
220 |
$tableau_js = "var g_votes = new Array();";
|
196 |
foreach($liste_commentaires as $commentaire) {
|
221 |
foreach($liste_commentaires as $commentaire) {
|
197 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"] = new Array();';
|
222 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"] = new Array();';
|
198 |
if(isset($commentaire['votes'])) {
|
223 |
if(isset($commentaire['votes'])) {
|
199 |
foreach($commentaire['votes'] as $vote) {
|
224 |
foreach($commentaire['votes'] as $vote) {
|
200 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"]["'.$vote['auteur.id'].'"] = '.$vote['vote'].';';
|
225 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"]["'.$vote['auteur.id'].'"] = '.$vote['vote'].';';
|
201 |
}
|
226 |
}
|
202 |
}
|
227 |
}
|
203 |
}
|
- |
|
204 |
|
228 |
}
|
205 |
return $tableau_js;
|
229 |
return $tableau_js;
|
206 |
}
|
- |
|
207 |
}
|
- |
|
208 |
?>
|
230 |
}
|
- |
|
231 |
}
|
209 |
|
232 |
|