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 |
|
991 |
aurelien |
74 |
private function convertirParametresEnChaineRequete() {
|
|
|
75 |
$requete = str_replace('masque_','masque.',http_build_query($this->parametres));
|
|
|
76 |
if(!empty($this->parametres)) {
|
|
|
77 |
$requete = '&'.$requete;
|
|
|
78 |
}
|
|
|
79 |
return $requete;
|
|
|
80 |
}
|
|
|
81 |
|
986 |
aurelien |
82 |
private function obtenirIdsObservation() {
|
991 |
aurelien |
83 |
$ids = json_decode(file_get_contents($this->del_url_service_tpl.'observations?retour.format=widget'.$this->convertirParametresEnChaineRequete()), true);
|
986 |
aurelien |
84 |
if($this->id_observation == null) {
|
|
|
85 |
$this->id_observation = $ids['resultats'][0];
|
|
|
86 |
}
|
|
|
87 |
return $ids['resultats'];
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
private function obtenirUrlBaseWidget() {
|
|
|
91 |
return $this->config['chemins']['baseURL'].'vote';
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private function construireUrlsSuivantesEtPrecedentes($tableau_id_observation) {
|
|
|
95 |
|
|
|
96 |
$indices_id_obs = array_flip($tableau_id_observation);
|
|
|
97 |
$indice_obs_courante = $indices_id_obs[$this->id_observation];
|
|
|
98 |
$url_base = $this->obtenirUrlBaseWidget();
|
|
|
99 |
|
|
|
100 |
$indice_predecent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $tableau_id_observation[$indice_obs_courante - 1] : '';
|
|
|
101 |
$indice_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $tableau_id_observation[$indice_obs_courante + 1] : '';
|
|
|
102 |
|
991 |
aurelien |
103 |
$url_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante + 1].$this->convertirParametresEnChaineRequete() : null;
|
|
|
104 |
$url_precedent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante - 1].$this->convertirParametresEnChaineRequete() : null;
|
|
|
105 |
|
986 |
aurelien |
106 |
return array('url_suivant' => $url_suivant,
|
|
|
107 |
'url_precedent' => $url_precedent
|
|
|
108 |
);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
private function obtenirDonnees($id_observation) {
|
|
|
112 |
$donnees = json_decode(file_get_contents($this->del_url_service_tpl.'observations/'.$id_observation), true);
|
983 |
aurelien |
113 |
return $donnees;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
private function construireTitreImage($donnees) {
|
991 |
aurelien |
117 |
return 'Pris par '.$donnees['auteur.prenom'].' '.$donnees['auteur.nom'].' à '.$donnees['zone_geo'].' le '.$this->formaterDate($donnees['date_observation'],'%d/%m/%Y');
|
983 |
aurelien |
118 |
}
|
|
|
119 |
|
|
|
120 |
private function obtenirUrlImage($images) {
|
991 |
aurelien |
121 |
return $images[0]['binaire.href'];
|
983 |
aurelien |
122 |
}
|
|
|
123 |
|
|
|
124 |
private function formaterDeterminations($observation) {
|
|
|
125 |
$liste_determinations = $observation['commentaires'];
|
|
|
126 |
$liste_determinations_formatees = array();
|
|
|
127 |
|
|
|
128 |
$creerPropositionAPartirObservation = true;
|
|
|
129 |
|
|
|
130 |
foreach ($liste_determinations as $determination) {
|
|
|
131 |
$determination_formatee = $determination;
|
|
|
132 |
if($determination['nom_sel'] != null && $determination['nom_sel'] != '') {
|
|
|
133 |
$determination_formatee['votes'] = $this->formaterVotes($determination['votes']);
|
|
|
134 |
$liste_determinations_formatees[] = $determination_formatee;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
if($determination['nom_sel'] == $observation['determination.ns'] &&
|
|
|
138 |
$determination['auteur.id'] == $observation['auteur.id']) {
|
|
|
139 |
$creerPropositionAPartirObservation = false;
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
if($creerPropositionAPartirObservation) {
|
|
|
144 |
$liste_determinations_formatees[] = $this->creerDeterminationAPartirObservation($observation);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
return $liste_determinations_formatees;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
private function creerDeterminationAPartirObservation($observation) {
|
|
|
151 |
$proposition = array("id_commentaire" => "0",
|
|
|
152 |
"observation" => $observation['id_observation'],
|
|
|
153 |
"proposition" => "0",
|
|
|
154 |
"id_parent" => "0",
|
|
|
155 |
"auteur.id" => $observation['auteur.id'],
|
|
|
156 |
"texte" => null,
|
|
|
157 |
"auteur.nom" => $observation['auteur.nom'],
|
|
|
158 |
"auteur.prenom" => $observation['auteur.prenom'],
|
|
|
159 |
"auteur.courriel" => $observation['observateur'],
|
|
|
160 |
"date" => $observation['date_observation'],
|
|
|
161 |
"nom_sel" => $observation['determination.ns'],
|
|
|
162 |
"votes" => array('oui' => 0, 'non' => 0)
|
|
|
163 |
);
|
|
|
164 |
|
|
|
165 |
return $proposition;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
private function formaterVotes($liste_votes) {
|
|
|
169 |
$liste_votes_formates = array('oui' => 0, 'non' => 0);
|
|
|
170 |
foreach($liste_votes as $vote) {
|
|
|
171 |
if($vote['vote'] == 1) {
|
|
|
172 |
$liste_votes_formates['oui']++;
|
|
|
173 |
} else {
|
|
|
174 |
$liste_votes_formates['non']++;
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
return $liste_votes_formates;
|
|
|
179 |
}
|
|
|
180 |
|
984 |
aurelien |
181 |
private function convertirTableauVotesEnJs($liste_commentaires) {
|
|
|
182 |
$tableau_js = "var g_votes = new Array();";
|
|
|
183 |
foreach($liste_commentaires as $commentaire) {
|
|
|
184 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"] = new Array();';
|
|
|
185 |
if(isset($commentaire['votes'])) {
|
|
|
186 |
foreach($commentaire['votes'] as $vote) {
|
|
|
187 |
$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"]["'.$vote['auteur.id'].'"] = '.$vote['vote'].';';
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
return $tableau_js;
|
|
|
193 |
}
|
983 |
aurelien |
194 |
}
|
|
|
195 |
?>
|