983 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
|
|
|
5 |
* Encodage en entrée : utf8
|
|
|
6 |
* Encodage en sortie : utf8
|
|
|
7 |
*
|
|
|
8 |
* Cas d'utilisation et documentation :
|
|
|
9 |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
|
|
|
10 |
*
|
|
|
11 |
* Paramètres :
|
|
|
12 |
* ===> extra = booléen (1 ou 0) [par défaut : 1]
|
|
|
13 |
* Affiche / Cache la vignette en taille plus importante au bas du widget.
|
|
|
14 |
* ===> vignette = [0-9]+,[0-9]+ [par défaut : 4,3]
|
|
|
15 |
* Indique le nombre de vignette par ligne et le nombre de ligne.
|
|
|
16 |
*
|
|
|
17 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
20 |
* @version $Id$
|
|
|
21 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
|
|
22 |
*/
|
|
|
23 |
class Vote extends WidgetCommun {
|
|
|
24 |
|
|
|
25 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
26 |
const SERVICE_DEFAUT = 'photo';
|
|
|
27 |
private $ce_img_url_tpl = null;
|
|
|
28 |
private $del_url_service_tpl = null;
|
|
|
29 |
|
986 |
aurelien |
30 |
private $id_observation_suivant = null;
|
|
|
31 |
private $id_observation_precedent = null;
|
|
|
32 |
private $id_observation = null;
|
|
|
33 |
|
983 |
aurelien |
34 |
/**
|
|
|
35 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
36 |
*/
|
|
|
37 |
public function executer() {
|
|
|
38 |
$this->del_url_service_tpl = $this->config['vote']['baseURLServicesDelTpl'];
|
|
|
39 |
$this->ce_img_url_tpl = $this->config['vote']['celImgUrlTpl'];
|
|
|
40 |
|
986 |
aurelien |
41 |
$this->collecterParametres();
|
|
|
42 |
$ids_observations = $this->obtenirIdsObservation();
|
|
|
43 |
$donnees = $this->obtenirDonnees($this->id_observation);
|
983 |
aurelien |
44 |
|
992 |
aurelien |
45 |
$widget['donnees']['id_observation'] = $this->id_observation;
|
983 |
aurelien |
46 |
$widget['donnees']['titre'] = $this->construireTitreImage($donnees);
|
991 |
aurelien |
47 |
$widget['donnees']['url'] = $this->obtenirUrlImage($donnees['images']);
|
983 |
aurelien |
48 |
$widget['donnees']['images'] = $donnees['images'];
|
|
|
49 |
$widget['donnees']['liste_votes_determination'] = $this->formaterDeterminations($donnees);
|
|
|
50 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/css/');
|
|
|
51 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/scripts/');
|
984 |
aurelien |
52 |
$widget['donnees']['votes_js'] = $this->convertirTableauVotesEnJs($donnees['commentaires']);
|
986 |
aurelien |
53 |
$widget['donnees']['url_service_votes'] = $this->del_url_service_tpl.'observations/'.$this->id_observation;
|
984 |
aurelien |
54 |
$widget['donnees']['url_service_utilisateurs'] = $this->del_url_service_tpl.'utilisateurs/';
|
986 |
aurelien |
55 |
$widget['donnees']['urls_navigation'] = $this->construireUrlsSuivantesEtPrecedentes($ids_observations);
|
983 |
aurelien |
56 |
|
993 |
delphine |
57 |
if (isset($this->parametres['mode']) && $this->parametres['mode'] == 'ajax') {
|
|
|
58 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote_ajax.tpl.html';
|
|
|
59 |
} else {
|
|
|
60 |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote.tpl.html';
|
|
|
61 |
}
|
|
|
62 |
|
983 |
aurelien |
63 |
$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);
|
|
|
64 |
|
|
|
65 |
$this->envoyer($contenu);
|
|
|
66 |
}
|
|
|
67 |
|
986 |
aurelien |
68 |
private function collecterParametres() {
|
|
|
69 |
$this->id_observation = (isset($_GET['id_observation'])) ? $_GET['id_observation'] : null;
|
991 |
aurelien |
70 |
unset($_GET['id_observation']);
|
|
|
71 |
$this->parametres = $_GET;
|
986 |
aurelien |
72 |
}
|
|
|
73 |
|
999 |
delphine |
74 |
private function convertirParametresEnChaineRequeteService() {
|
|
|
75 |
$requete = '';
|
|
|
76 |
$mapping = $this->config['mapping_masque'];
|
|
|
77 |
if(!empty($this->parametres)) {
|
|
|
78 |
foreach ($this->parametres as $parametre=>$valeur) {
|
|
|
79 |
if (isset($mapping[$parametre])) {
|
|
|
80 |
$requete .= '&'.$mapping[$parametre].'='.urlencode($valeur);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
return $requete;
|
|
|
85 |
}
|
|
|
86 |
|
991 |
aurelien |
87 |
private function convertirParametresEnChaineRequete() {
|
|
|
88 |
$requete = str_replace('masque_','masque.',http_build_query($this->parametres));
|
|
|
89 |
if(!empty($this->parametres)) {
|
|
|
90 |
$requete = '&'.$requete;
|
|
|
91 |
}
|
|
|
92 |
return $requete;
|
|
|
93 |
}
|
|
|
94 |
|
986 |
aurelien |
95 |
private function obtenirIdsObservation() {
|
999 |
delphine |
96 |
$ids = json_decode(file_get_contents($this->del_url_service_tpl.'observations?retour.format=widget'.$this->convertirParametresEnChaineRequeteService()), true);
|
986 |
aurelien |
97 |
if($this->id_observation == null) {
|
|
|
98 |
$this->id_observation = $ids['resultats'][0];
|
|
|
99 |
}
|
|
|
100 |
return $ids['resultats'];
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
private function obtenirUrlBaseWidget() {
|
|
|
104 |
return $this->config['chemins']['baseURL'].'vote';
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
private function construireUrlsSuivantesEtPrecedentes($tableau_id_observation) {
|
|
|
108 |
|
|
|
109 |
$indices_id_obs = array_flip($tableau_id_observation);
|
|
|
110 |
$indice_obs_courante = $indices_id_obs[$this->id_observation];
|
|
|
111 |
$url_base = $this->obtenirUrlBaseWidget();
|
|
|
112 |
|
|
|
113 |
$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] : '';
|
|
|
115 |
|
991 |
aurelien |
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;
|
|
|
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;
|
|
|
118 |
|
986 |
aurelien |
119 |
return array('url_suivant' => $url_suivant,
|
|
|
120 |
'url_precedent' => $url_precedent
|
|
|
121 |
);
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
private function obtenirDonnees($id_observation) {
|
|
|
125 |
$donnees = json_decode(file_get_contents($this->del_url_service_tpl.'observations/'.$id_observation), true);
|
983 |
aurelien |
126 |
return $donnees;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
private function construireTitreImage($donnees) {
|
991 |
aurelien |
130 |
return 'Pris par '.$donnees['auteur.prenom'].' '.$donnees['auteur.nom'].' à '.$donnees['zone_geo'].' le '.$this->formaterDate($donnees['date_observation'],'%d/%m/%Y');
|
983 |
aurelien |
131 |
}
|
|
|
132 |
|
|
|
133 |
private function obtenirUrlImage($images) {
|
991 |
aurelien |
134 |
return $images[0]['binaire.href'];
|
983 |
aurelien |
135 |
}
|
|
|
136 |
|
|
|
137 |
private function formaterDeterminations($observation) {
|
|
|
138 |
$liste_determinations = $observation['commentaires'];
|
|
|
139 |
$liste_determinations_formatees = array();
|
|
|
140 |
|
|
|
141 |
$creerPropositionAPartirObservation = true;
|
|
|
142 |
|
|
|
143 |
foreach ($liste_determinations as $determination) {
|
|
|
144 |
$determination_formatee = $determination;
|
|
|
145 |
if($determination['nom_sel'] != null && $determination['nom_sel'] != '') {
|
|
|
146 |
$determination_formatee['votes'] = $this->formaterVotes($determination['votes']);
|
|
|
147 |
$liste_determinations_formatees[] = $determination_formatee;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
if($determination['nom_sel'] == $observation['determination.ns'] &&
|
|
|
151 |
$determination['auteur.id'] == $observation['auteur.id']) {
|
|
|
152 |
$creerPropositionAPartirObservation = false;
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
if($creerPropositionAPartirObservation) {
|
|
|
157 |
$liste_determinations_formatees[] = $this->creerDeterminationAPartirObservation($observation);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return $liste_determinations_formatees;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
private function creerDeterminationAPartirObservation($observation) {
|
|
|
164 |
$proposition = array("id_commentaire" => "0",
|
|
|
165 |
"observation" => $observation['id_observation'],
|
|
|
166 |
"proposition" => "0",
|
|
|
167 |
"id_parent" => "0",
|
|
|
168 |
"auteur.id" => $observation['auteur.id'],
|
|
|
169 |
"texte" => null,
|
|
|
170 |
"auteur.nom" => $observation['auteur.nom'],
|
|
|
171 |
"auteur.prenom" => $observation['auteur.prenom'],
|
|
|
172 |
"auteur.courriel" => $observation['observateur'],
|
|
|
173 |
"date" => $observation['date_observation'],
|
|
|
174 |
"nom_sel" => $observation['determination.ns'],
|
|
|
175 |
"votes" => array('oui' => 0, 'non' => 0)
|
|
|
176 |
);
|
|
|
177 |
|
|
|
178 |
return $proposition;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
private function formaterVotes($liste_votes) {
|
|
|
182 |
$liste_votes_formates = array('oui' => 0, 'non' => 0);
|
|
|
183 |
foreach($liste_votes as $vote) {
|
|
|
184 |
if($vote['vote'] == 1) {
|
|
|
185 |
$liste_votes_formates['oui']++;
|
|
|
186 |
} else {
|
|
|
187 |
$liste_votes_formates['non']++;
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
return $liste_votes_formates;
|
|
|
192 |
}
|
|
|
193 |
|
984 |
aurelien |
194 |
private function convertirTableauVotesEnJs($liste_commentaires) {
|
|
|
195 |
$tableau_js = "var g_votes = new Array();";
|
|
|
196 |
foreach($liste_commentaires as $commentaire) {
|
|
|
197 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"] = new Array();';
|
|
|
198 |
if(isset($commentaire['votes'])) {
|
|
|
199 |
foreach($commentaire['votes'] as $vote) {
|
|
|
200 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"]["'.$vote['auteur.id'].'"] = '.$vote['vote'].';';
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
return $tableau_js;
|
|
|
206 |
}
|
983 |
aurelien |
207 |
}
|
|
|
208 |
?>
|