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