Rev 1876 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php// declare(encoding='UTF-8');/*** Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.* Encodage en entrée : utf8* Encodage en sortie : utf8** Cas d'utilisation et documentation :* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto** Paramètres :* ===> extra = booléen (1 ou 0) [par défaut : 1]* Affiche / Cache la vignette en taille plus importante au bas du widget.* ===> vignette = [0-9]+,[0-9]+ [par défaut : 4,3]* Indique le nombre de vignette par ligne et le nombre de ligne.** @author Jean-Pascal MILCENT <jpm@tela-botanica.org>* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>* @version $Id$* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)*/class Vote extends WidgetCommun {const DS = DIRECTORY_SEPARATOR;const SERVICE_DEFAUT = 'photo';private $ce_img_url_tpl = null;private $del_url_service_tpl = null;private $id_observation = null;/*** Méthode appelée par défaut pour charger ce widget.*/public function executer() {$this->del_url_service_tpl = $this->config['vote']['baseURLServicesDelTpl'];$this->ce_img_url_tpl = $this->config['vote']['celImgUrlTpl'];$this->collecterParametres();$ids_observations = $this->obtenirIdsObservation();$donnees = $this->obtenirDonnees($this->id_observation);$widget['donnees']['id_observation'] = $this->id_observation;$widget['donnees']['titre'] = $this->construireTitreImage($donnees);$widget['donnees']['url'] = $this->obtenirUrlImage($donnees['images']);$widget['donnees']['images'] = $donnees['images'];$widget['donnees']['liste_votes_determination'] = $this->formaterDeterminations($donnees);$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/css/');$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/vote/squelettes/scripts/');$widget['donnees']['votes_js'] = $this->convertirTableauVotesEnJs($donnees['commentaires']);$widget['donnees']['url_service_votes'] = $this->del_url_service_tpl.'observations/'.$this->id_observation;$widget['donnees']['url_service_utilisateurs'] = $this->del_url_service_tpl.'utilisateurs/';$widget['donnees']['urls_navigation'] = $this->construireUrlsSuivantesEtPrecedentes($ids_observations);if (isset($this->parametres['mode']) && $this->parametres['mode'] == 'ajax') {$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote_ajax.tpl.html';} else {$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'vote.tpl.html';}$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);$this->envoyer($contenu);}private function collecterParametres() {$this->id_observation = (isset($_GET['id_observation'])) ? $_GET['id_observation'] : null;unset($_GET['id_observation']);$this->parametres = $_GET;}private function convertirParametresEnChaineRequeteService() {$parametresWs = array();$mapping = $this->transformerEnTableau($this->config['vote']['mapping_masque']);if (!empty($this->parametres)) {foreach ($this->parametres as $parametre => $valeur) {if (isset($mapping[$parametre])) {$parametresWs[] = $mapping[$parametre].'='.urlencode($valeur);}}}$requete = (!empty($parametresWs)) ? '?'.implode('&', $parametresWs) : '';return $requete;}private function convertirParametresEnChaineRequete() {$requete = str_replace('masque_','masque.',http_build_query($this->parametres));if(!empty($this->parametres)) {$requete = '&'.$requete;}return $requete;}private function obtenirIdsObservation() {$url = $this->del_url_service_tpl.'observations'.$this->convertirParametresEnChaineRequeteService();//exit('<pre>'.print_r($url, true).'</pre>');$infos = json_decode(file_get_contents($url), true);//exit('<pre>'.print_r($infos, true).'</pre>');$ids = array();foreach ($infos['resultats'] as $resultat) {if ($this->id_observation == null) {$this->id_observation = $resultat['id_observation'];}$ids[] = $resultat['id_observation'];}return $ids;}private function obtenirUrlBaseWidget() {return $this->config['chemins']['baseURL'].'vote';}private function construireUrlsSuivantesEtPrecedentes($tableau_id_observation) {$indices_id_obs = array_flip($tableau_id_observation);$indice_obs_courante = $indices_id_obs[$this->id_observation];$url_base = $this->obtenirUrlBaseWidget();$indice_predecent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $tableau_id_observation[$indice_obs_courante - 1] : '';$indice_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $tableau_id_observation[$indice_obs_courante + 1] : '';$url_suivant = isset($tableau_id_observation[$indice_obs_courante + 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante + 1].$this->convertirParametresEnChaineRequete() : null;$url_precedent = isset($tableau_id_observation[$indice_obs_courante - 1]) ? $url_base.'?id_observation='.$tableau_id_observation[$indice_obs_courante - 1].$this->convertirParametresEnChaineRequete() : null;return array('url_suivant' => $url_suivant, 'url_precedent' => $url_precedent);}private function obtenirDonnees($id_observation) {$donnees = json_decode(file_get_contents($this->del_url_service_tpl.'observations/'.$id_observation), true);//exit('<pre>'.print_r($donnees, true).'</pre>');return $donnees;}private function construireTitreImage($donnees) {return 'Pris par '.$donnees['auteur.prenom'].' '.$donnees['auteur.nom'].' à '.$donnees['zone_geo'].' le '.$this->formaterDate($donnees['date_observation'],'%d/%m/%Y');}private function obtenirUrlImage($images) {return $images[0]['binaire.href'];}private function formaterDeterminations($observation) {$liste_determinations = $observation['commentaires'];$liste_determinations_formatees = array();$creerPropositionAPartirObservation = true;foreach ($liste_determinations as $determination) {if ($determination['nom_sel'] != null && $determination['nom_sel'] != '') {$liste_determinations_formatees[] = $this->formaterDetermination($determination);}if ($determination['nom_sel'] == $observation['determination.ns'] &&$determination['auteur.id'] == $observation['auteur.id']) {$creerPropositionAPartirObservation = false;}}if ($creerPropositionAPartirObservation) {$liste_determinations_formatees[] = $this->creerDeterminationAPartirObservation($observation);}return $liste_determinations_formatees;}private function formaterDetermination($infos) {//exit('<pre>'.print_r($infos, true).'</pre>');$determination = array("id_commentaire" => $infos['id_commentaire'],"observation" => $infos['observation'],"proposition" => $infos['proposition'],"id_parent" => $infos['id_parent'],"texte" => $infos['texte'],"date" => $infos['date_observation'],"nom_sel" => $infos['nom_sel'],"auteur_intitule" => $this->formaterIntituleAuteur($infos),"votes" => $this->formaterVotes($infos['votes']));return $determination;}private function creerDeterminationAPartirObservation($observation) {$determination = array("id_commentaire" => "0","observation" => $observation['id_observation'],"proposition" => "0","id_parent" => "0","texte" => null,"date" => $observation['date_observation'],"nom_sel" => $observation['determination.ns'],"auteur_intitule" => $this->formaterIntituleAuteur($observation),"votes" => array('oui' => 0, 'non' => 0));return $determination;}private function formaterIntituleAuteur($donnees) {$intitule = 'Anonyme';// TODO : si auteur.id existe, appelé le WS de l'annuaire...if (!empty($donnees['auteur.prenom']) && !empty($donnees['auteur.nom'])) {$intitule = $donnees['auteur.prenom'].' '.$donnees['auteur.nom'];} else if (!empty($donnees['auteur.courriel'])) {$intitule = strstr($donnees['auteur.courriel'], '@').'@...';}return $intitule;}private function formaterVotes($liste_votes) {$liste_votes_formates = array('oui' => 0, 'non' => 0);foreach($liste_votes as $vote) {if($vote['vote'] == 1) {$liste_votes_formates['oui']++;} else {$liste_votes_formates['non']++;}}return $liste_votes_formates;}private function convertirTableauVotesEnJs($liste_commentaires) {$tableau_js = "var g_votes = new Array();";foreach($liste_commentaires as $commentaire) {$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"] = new Array();';if(isset($commentaire['votes'])) {foreach($commentaire['votes'] as $vote) {$tableau_js .= 'g_votes["'.$commentaire['id_commentaire'].'"]["'.$vote['auteur.id'].'"] = '.$vote['vote'].';';}}}return $tableau_js;}}