/branches/v1.2-lithium/widget/modules/vote/config.defaut.ini |
---|
New file |
0,0 → 1,5 |
[vote] |
; URL des services web du CEL sous forme de template à utiliser avec sprintf |
baseURLServicesDelTpl = "http://localhost/del/services/0.1/" |
; Squelette d'Url permettant d'afficher une image du CEL (remplace %s par l'id de l'image sans underscore) |
celImgUrlTpl = "http://api.tela-botanica.org/img:%s.jpg" |
/branches/v1.2-lithium/widget/modules/vote/bibliotheque/Cache.php |
---|
New file |
0,0 → 1,128 |
<?php |
class Cache { |
private $actif = null; |
private $dossier_stockage = null; |
private $duree_de_vie = null; |
public function __construct($dossier_stockage = null, $duree_de_vie = null, $activation = true) { |
$this->actif = ($activation) ? true : false; |
if ($this->actif) { |
$this->dossier_stockage = $dossier_stockage; |
if (is_null($dossier_stockage)) { |
$this->dossier_stockage = self::getDossierTmp(); |
} |
$this->duree_de_vie = $duree_de_vie; |
if (is_null($duree_de_vie)) { |
$this->duree_de_vie = 3600*24; |
} |
} |
} |
public function charger($id) { |
$contenu = false; |
if ($this->actif) { |
$chemin_fichier_cache = $this->dossier_stockage.DIRECTORY_SEPARATOR.$id.'.txt'; |
if (file_exists($chemin_fichier_cache ) && (time() - @filemtime($chemin_fichier_cache) < $this->duree_de_vie)) { |
$contenu = file_get_contents($chemin_fichier_cache); |
} |
} |
return $contenu; |
} |
public function sauver($id, $contenu) { |
if ($this->actif) { |
$chemin_fichier_cache = $this->dossier_stockage.DIRECTORY_SEPARATOR.$id.'.txt'; |
if (!file_exists($chemin_fichier_cache) || (time() - @filemtime($chemin_fichier_cache) > $this->duree_de_vie)) { |
$fh = fopen($chemin_fichier_cache,'w+'); |
if ($fh) { |
fputs($fh, $contenu); |
fclose($fh); |
} |
} |
} |
} |
/** |
* Détermine le dossier système temporaire et détecte si nous y avons accès en lecture et écriture. |
* |
* Inspiré de Zend_File_Transfer_Adapter_Abstract & Zend_Cache |
* |
* @return string|false le chemine vers le dossier temporaire ou false en cas d'échec. |
*/ |
private static function getDossierTmp() { |
$dossier_tmp = false; |
foreach (array($_ENV, $_SERVER) as $environnement) { |
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $cle) { |
if (isset($environnement[$cle])) { |
if (($cle == 'windir') or ($cle == 'SystemRoot')) { |
$dossier = realpath($environnement[$cle] . '\\temp'); |
} else { |
$dossier = realpath($environnement[$cle]); |
} |
if (self::etreAccessibleEnLectureEtEcriture($dossier)) { |
$dossier_tmp = $dossier; |
break 2; |
} |
} |
} |
} |
if ( ! $dossier_tmp) { |
$dossier_televersement_tmp = ini_get('upload_tmp_dir'); |
if ($dossier_televersement_tmp) { |
$dossier = realpath($dossier_televersement_tmp); |
if (self::etreAccessibleEnLectureEtEcriture($dossier)) { |
$dossier_tmp = $dossier; |
} |
} |
} |
if ( ! $dossier_tmp) { |
if (function_exists('sys_get_temp_dir')) { |
$dossier = sys_get_temp_dir(); |
if (self::etreAccessibleEnLectureEtEcriture($dossier)) { |
$dossier_tmp = $dossier; |
} |
} |
} |
if ( ! $dossier_tmp) { |
// Tentative de création d'un fichier temporaire |
$fichier_tmp = tempnam(md5(uniqid(rand(), TRUE)), ''); |
if ($fichier_tmp) { |
$dossier = realpath(dirname($fichier_tmp)); |
unlink($fichier_tmp); |
if (self::etreAccessibleEnLectureEtEcriture($dossier)) { |
$dossier_tmp = $dossier; |
} |
} |
} |
if ( ! $dossier_tmp && self::etreAccessibleEnLectureEtEcriture('/tmp')) { |
$dossier_tmp = '/tmp'; |
} |
if ( ! $dossier_tmp && self::etreAccessibleEnLectureEtEcriture('\\temp')) { |
$dossier_tmp = '\\temp'; |
} |
return $dossier_tmp; |
} |
/** |
* Vérifie si le fichier ou dossier est accessible en lecture et écriture. |
* |
* @param $ressource chemin vers le dossier ou fichier à tester |
* @return boolean true si la ressource est accessible en lecture et écriture. |
*/ |
protected static function etreAccessibleEnLectureEtEcriture($ressource){ |
$accessible = false; |
if (is_readable($ressource) && is_writable($ressource)) { |
$accessible = true; |
} |
return $accessible; |
} |
} |
?> |
/branches/v1.2-lithium/widget/modules/vote/squelettes/scripts/vote.js |
---|
New file |
0,0 → 1,162 |
/**----------------------------------------------------------------------------------------------------------*/ |
/** Variables globales et initialisation |
* Variables crées par php dans le squelettes |
* |
* var g_idObservation : id de l'observation en cours de consultation |
* var g_urlServiceVotes : url du service web des votes à appeler |
* var g_urlServiceUtilisateurs : url du service web utilisateur à appeler |
* var g_votes : tableau des votes |
* |
*/ |
var boutonClique = null; |
var g_idUtilisateur = null; |
$(document).ready(function() { |
getIdUtilisateur(); |
gererEvenementsClicsVotes(); |
gererEvenementClicImageSecondaire(); |
}); |
$(document).bind('pageload', function() { |
gererEvenementsClicsVotes(); |
mettreEnValeurVotesUtilisateur(); |
}); |
function getIdUtilisateur() { |
$.getJSON(g_urlServiceUtilisateurs, function(data) { |
g_idUtilisateur = data.id_utilisateur; |
mettreEnValeurVotesUtilisateur(); |
}); |
} |
function gererEvenementsClicsVotes() { |
$('.bouton_vote').unbind('click'); |
$('.bouton_vote').click(function(event) { |
boutonClique = $(this); |
voter(getValeurVote()); |
}); |
} |
function gererEvenementClicImageSecondaire() { |
$('.image_secondaire').live('click', function(event) { |
$('.image_secondaire').removeClass('image_active'); |
var urlImageSecondaire = $(this).attr('src'); |
urlImageSecondaireAgrandie = urlImageSecondaire.replace('CRX2S','CRS'); |
var urlImagePrincipale = $('.image_principale').attr('src'); |
urlImagePrincipaleMiniature = urlImagePrincipale.replace('CRS','CRX2S'); |
$(this).addClass('image_active'); |
$('.image_principale').attr('src', urlImageSecondaireAgrandie); |
}); |
} |
function getValeurVote() { |
valeur = 0; |
if(boutonClique.hasClass('bouton_vote_oui')) { |
valeur = 1; |
} |
return valeur; |
} |
function getIdProposition() { |
var chaineProposition = boutonClique.parent().attr('id'); |
return chaineProposition.replace('vote_determination_', ''); |
} |
/**----------------------------------------------------------------------------------------------------------*/ |
/** Affichage **/ |
function mettreEnValeurBoutonClique() { |
boutonClique.parent().find(".bouton_vote").removeClass("bouton_selectionne"); |
boutonClique.effect("highlight", {}, 500, function() {$(this).addClass("bouton_selectionne");}); |
} |
function mettreEnValeurVotesUtilisateur() { |
$('.votes_determination').each(function() { |
var id_proposition = $(this).attr('id').replace('vote_determination_', ''); |
if(g_votes[id_proposition] != undefined && g_votes[id_proposition][g_idUtilisateur] != undefined) { |
if(g_votes[id_proposition][g_idUtilisateur] == 1) { |
$(this).children('.bouton_vote_oui').addClass("bouton_selectionne"); |
} else { |
$(this).children('.bouton_vote_non').addClass("bouton_selectionne"); |
} |
} |
}); |
} |
function mettreAJourAffichageNbVotes(idProposition) { |
affichageVotes = boutonClique.parent().find(".nb_votes"); |
affichageVotes.each(function() { |
if($(this).hasClass("nb_votes_oui")) { |
$(this).html(calculerVotes(idProposition,1)); |
} |
if($(this).hasClass("nb_votes_non")) { |
$(this).html(calculerVotes(idProposition,0)); |
} |
}); |
} |
/**----------------------------------------------------------------------------------------------------------*/ |
/** Requetes **/ |
function getUrlVoteProposition(idProposition) { |
return g_urlServiceVotes+'/'+idProposition+'/vote/'; |
} |
function getMethodeRequete(idProposition, idUtilisateur) { |
var methode = "PUT"; |
if(g_votes[idProposition] != undefined && g_votes[idProposition] != null && |
g_votes[idProposition][idUtilisateur] != undefined && g_votes[idProposition][idUtilisateur] != null) { |
methode = "POST"; |
} |
return methode; |
} |
function voter(ouiOuNon) { |
var idProposition = getIdProposition(); |
var urlVote = getUrlVoteProposition(idProposition); |
var type = getMethodeRequete(idProposition, g_idUtilisateur); |
if(!voteEstIdentique(idProposition, g_idUtilisateur, ouiOuNon)) { |
$.ajax({ |
url : urlVote, |
type: type, |
data: "utilisateur="+g_idUtilisateur+"&valeur="+ouiOuNon |
}).done(function(data) { |
mettreAjourTableauVotes(idProposition, g_idUtilisateur, ouiOuNon); |
mettreAJourAffichageNbVotes(idProposition); |
mettreEnValeurBoutonClique(); |
boutonClique = null; |
}); |
} |
} |
/**----------------------------------------------------------------------------------------------------------*/ |
/** Mise à jour et accès au tableau des votes **/ |
function mettreAjourTableauVotes(idProposition, idUtilisateur, valeurVote) { |
if(g_votes[idProposition] == undefined) { |
g_votes[idProposition] = new Array(); |
} |
g_votes[idProposition][idUtilisateur] = valeurVote; |
} |
function calculerVotes(id_proposition, ouiOuNon) { |
var nb = 0; |
for (var votant in g_votes[id_proposition]) { |
if(g_votes[id_proposition][votant] == ouiOuNon) { |
nb++; |
} |
} |
return nb; |
} |
function voteEstIdentique(id_proposition, id_utilisateur, ouiOuNon) { |
return (g_votes[id_proposition] != undefined && |
g_votes[id_proposition][id_utilisateur] != undefined && |
g_votes[id_proposition][id_utilisateur] == ouiOuNon); |
} |
/branches/v1.2-lithium/widget/modules/vote/squelettes/css/vote.css |
---|
New file |
0,0 → 1,53 |
@charset "UTF-8"; |
/*+-----------------------------------------------------------------------------------------------------------------+*/ |
/* Widget */ |
.intitule_determination { |
float:left; |
} |
.votes_determination { |
float:right; |
} |
.auteur_determination { |
font-style:italic; |
} |
.image_secondaire { |
height: 40px; |
cursor:pointer; |
} |
.nb_votes { |
position: relative; |
top: -12px; |
} |
.image_active { |
border: solid 1px black; |
} |
.bouton_selectionne > * { |
background-color: #BBBBBB; |
cursor: default; |
} |
.bouton_selectionne { |
cursor: default; |
} |
.lien_connexion { |
float: right; |
} |
.info_observation { |
font-size: 14px; |
font-weight: bold; |
padding-bottom: 5px; |
padding-left: 10px; |
padding-top: 5px; |
} |
.images { |
text-align: center; |
} |
/branches/v1.2-lithium/widget/modules/vote/squelettes/vote.tpl.html |
---|
New file |
0,0 → 1,113 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<title>Votez !</title> |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> |
<meta http-equiv="Content-style-type" content="text/css" /> |
<meta http-equiv="Content-script-type" content="text/javascript" /> |
<meta http-equiv="Content-language" content="fr" /> |
<meta name="revisit-after" content="15 days" /> |
<meta name="robots" content="index,follow" /> |
<meta name="author" content="Delphine Cauquil, Aurélien Peronnet" /> |
<meta name="keywords" content="Tela Botanica, photographie, DEL" /> |
<meta name="description" content="Widget de vote sur les dernières images proposées dans DEL" /> |
<!-- Spécial mobile --> |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> |
<!-- Favicones --> |
<link rel="icon" type="image/png" href="http://www.tela-botanica.org/sites/commun/generique/images/favicones/tela_botanica.png" /> |
<link rel="shortcut icon" type="image/x-icon" href="http://www.tela-botanica.org/sites/commun/generique/images/favicones/tela_botanica.ico" /> |
<!-- Feuilles de styles --> |
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> |
<link rel="stylesheet" type="text/css" href="<?=$url_css?>vote.css" media="screen" /> |
<!-- Javascript : bibliothèques --> |
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> |
<script type="text/Javascript"> |
</script> |
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> |
<!-- attention le script suivant a besoin des variables globales initialisées ci dessous, donc, ne rien utiliser |
avant le document.ready() --> |
<script src="<?=$url_js?>vote.js"></script> |
</head> |
<body> |
<!-- WIDGET:DEL:VOTE - DEBUT --> |
<div data-role="page"> |
<!-- Variables globales à réinjecter à chaque changement de page |
(hors jquery mobile ne recharge pas le contenu du header --> |
<script type="text/Javascript"> |
//<![CDATA[ |
var g_urlServiceVotes = "<?= $donnees['url_service_votes']; ?>"; |
var g_urlServiceUtilisateurs = "<?= $donnees['url_service_utilisateurs']; ?>"; |
var g_idObservation = "<?= $donnees['id_observation']; ?>"; |
<?= $donnees['votes_js']; ?>; |
//]]> |
</script> |
<!-- /navbar --> |
<div data-role="header" data-position="fixed"> |
<div data-role="navbar" > |
<ul> |
<?php if($donnees['urls_navigation']['url_precedent'] != null) { ?> |
<li><a id="url_precedent" href="<?= $donnees['urls_navigation']['url_precedent']; ?>" data-transition="reverse slide">Précédent</a></li> |
<?php } ?> |
<?php if($donnees['urls_navigation']['url_suivant'] != null) { ?> |
<li><a id="url_suivant" href="<?= $donnees['urls_navigation']['url_suivant']; ?>" data-transition="slide">Suivant</a></li> |
<?php } ?> |
</ul> |
</div> |
</div> |
<!-- /navbar --> |
<div class="del-vote-contenu"> |
<div class="images"> |
<div style="height:305px"> |
<img class="image_principale" src="<?= str_replace('XL', 'CRS', $donnees['url']); ?>" alt="image" /> |
</div> |
<div class="conteneur_image_secondaire"> |
<?php $premiere_image = true; ?> |
<?php foreach($donnees['images'] as $image) : ?> |
<img class="image_secondaire <?php if($premiere_image) { echo 'image_active';} ?>" src="<?= str_replace('XL', 'CRX2S', $image['binaire.href']); ?>" alt="image" /> |
<?php $premiere_image = false; ?> |
<?php endforeach ?> |
</div> |
</div> |
<div class="info_observation"> |
<?= $donnees['titre']; ?> |
</div> |
<ul class="ui-listview" data-role="listview"> |
<?php foreach($donnees['liste_votes_determination'] as $vote_determination) : ?> |
<li class="ui-li ui-li-static ui-body-c"> |
<div class="intitule_determination"> |
<div><?= $vote_determination['nom_sel']; ?></div> |
<div class="auteur_determination">Proposé par : <?= $vote_determination['auteur.prenom']; ?> <?= $vote_determination['auteur.nom']; ?></div> |
</div> |
<div id="vote_determination_<?= $vote_determination['id_commentaire']; ?>" class="votes_determination"> |
<a href="#" class="bouton_vote bouton_vote_oui" data-role="button" data-mini="true" data-inline="true"> oui</a> |
<span class="nb_votes nb_votes_oui"> |
<?= $vote_determination['votes']['oui']; ?> |
</span> |
<a href="#" class="bouton_vote bouton_vote_non" data-role="button" data-mini="true" data-inline="true"> non</a> |
<span class="nb_votes nb_votes_non"> |
<?= $vote_determination['votes']['non']; ?> |
</span> |
</div> |
<hr style="visibility:hidden;clear:both" /> |
</li> |
<?php endforeach ?> |
</ul> |
</div> |
<div data-role="footer" data-theme="b"> |
<div data-role="navbar" > |
<ul> |
<li><a href="">Aide</a></li> |
<li><a href="">Se connecter</a></li> |
</ul> |
</div> |
</div> |
</div> |
<!-- WIDGET:DEL:VOTE - FIN --> |
</body> |
</html> |
/branches/v1.2-lithium/widget/modules/vote/squelettes/vote_ajax.tpl.html |
---|
New file |
0,0 → 1,54 |
<!-- WIDGET:DEL:VOTE - DEBUT --> |
<div id="contenu" data-role="page"> |
<!-- /navbar --> |
<div data-role="header" data-position="fixed"> |
<div data-role="navbar" > |
<ul> |
<?php if($donnees['urls_navigation']['url_precedent'] != null) { ?> |
<li><a href="<?= $donnees['urls_navigation']['url_precedent']; ?>" class="ui-btn-active">Précédent</a></li> |
<?php } ?> |
<?php if($donnees['urls_navigation']['url_suivant'] != null) { ?> |
<li><a href="<?= $donnees['urls_navigation']['url_suivant']; ?>">Suivant</a></li> |
<?php } ?> |
</ul> |
</div> |
</div> |
<!-- /navbar --> |
<div class="del-vote-contenu"> |
<img id="image_principale" src="<?= str_replace('XL', 'CRS', $donnees['url']); ?>" alt="image" /> |
<div class="conteneur_image_secondaire"> |
<?php $premiere_image = true; ?> |
<?php foreach($donnees['images'] as $image) : ?> |
<img class="image_secondaire <?php if($premiere_image) { echo 'image_active';} ?>" src="<?= str_replace('XL', 'CRX2S', $image['binaire.href']); ?>" alt="image" /> |
<?php $premiere_image = false; ?> |
<?php endforeach ?> |
</div> |
<div class="info_observation"> |
<?= $donnees['titre']; ?> |
</div> |
<ul class="ui-listview" data-role="listview"> |
<?php foreach($donnees['liste_votes_determination'] as $vote_determination) : ?> |
<li class="ui-li ui-li-static ui-body-c"> |
<div class="intitule_determination"> |
<div><?= $vote_determination['nom_sel']; ?></div> |
<div class="auteur_determination">Proposé par : <?= $vote_determination['auteur.prenom']; ?> <?= $vote_determination['auteur.nom']; ?></div> |
</div> |
<div id="vote_determination_<?= $vote_determination['id_commentaire']; ?>" class="votes_determination"> |
<a href="#" class="bouton_vote bouton_vote_oui" data-role="button" data-mini="true" data-inline="true"> oui</a> |
<span class="nb_votes nb_votes_oui"> |
<?= $vote_determination['votes']['oui']; ?> |
</span> |
<a href="#" class="bouton_vote bouton_vote_non" data-role="button" data-mini="true" data-inline="true"> non</a> |
<span class="nb_votes nb_votes_non"> |
<?= $vote_determination['votes']['non']; ?> |
</span> |
</div> |
<hr style="visibility:hidden;clear:both" /> |
</li> |
<?php endforeach ?> |
</ul> |
</div> |
<div data-role="footer" data-theme="b" data-position="fixed"> |
</div> |
</div> |
<!-- WIDGET:DEL:VOTE - FIN --> |
/branches/v1.2-lithium/widget/modules/vote/squelettes/aide.tpl.html |
---|
New file |
0,0 → 1,60 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<title>Votez !</title> |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> |
<meta http-equiv="Content-style-type" content="text/css" /> |
<meta http-equiv="Content-script-type" content="text/javascript" /> |
<meta http-equiv="Content-language" content="fr" /> |
<meta name="revisit-after" content="15 days" /> |
<meta name="robots" content="index,follow" /> |
<meta name="author" content="Delphine Cauquil, Aurélien Peronnet" /> |
<meta name="keywords" content="Tela Botanica, photographie, DEL" /> |
<meta name="description" content="Widget de vote sur les dernières images proposées dans DEL" /> |
<!-- Spécial mobile --> |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> |
<!-- Favicones --> |
<link rel="icon" type="image/png" href="http://www.tela-botanica.org/sites/commun/generique/images/favicones/tela_botanica.png" /> |
<link rel="shortcut icon" type="image/x-icon" href="http://www.tela-botanica.org/sites/commun/generique/images/favicones/tela_botanica.ico" /> |
<!-- Feuilles de styles --> |
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> |
<link rel="stylesheet" type="text/css" href="<?=$url_css?>vote.css" media="screen" /> |
<!-- Javascript : bibliothèques --> |
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> |
<script type="text/Javascript"> |
//<![CDATA[ |
$(document).bind("mobileinit", function(){ |
$.extend( $.mobile , { |
ajaxEnabled: false |
}); |
}); |
//]]> |
</script> |
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> |
<script src="<?=$url_js?>vote.js"></script> |
</head> |
<body> |
<!-- WIDGET:DEL:VOTE - DEBUT --> |
<div data-role="page"> |
<div class="aide-contenu"> |
</div> |
<div data-role="footer" data-theme="b" data-position="fixed"> |
<div data-role="navbar" > |
<ul> |
<li><a href="">Aide</a></li> |
<li><a href="">Se connecter</a></li> |
</ul> |
</div> |
</div> |
</div> |
<!-- WIDGET:DEL:VOTE - FIN --> |
</body> |
</html> |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri_decroissant.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri_decroissant.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/chargement.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/chargement.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/fermeture.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/fermeture.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/ouverture.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/ouverture.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri_croissant.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/tri_croissant.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/information.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/branches/v1.2-lithium/widget/modules/vote/squelettes/images/information.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/branches/v1.2-lithium/widget/modules/vote/Vote.php |
---|
New file |
0,0 → 1,208 |
<?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_suivant = null; |
private $id_observation_precedent = 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() { |
$requete = ''; |
$mapping = $this->config['mapping_masque']; |
if(!empty($this->parametres)) { |
foreach ($this->parametres as $parametre=>$valeur) { |
if (isset($mapping[$parametre])) { |
$requete .= '&'.$mapping[$parametre].'='.urlencode($valeur); |
} |
} |
} |
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() { |
$ids = json_decode(file_get_contents($this->del_url_service_tpl.'observations?retour.format=widget'.$this->convertirParametresEnChaineRequeteService()), true); |
if($this->id_observation == null) { |
$this->id_observation = $ids['resultats'][0]; |
} |
return $ids['resultats']; |
} |
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); |
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) { |
$determination_formatee = $determination; |
if($determination['nom_sel'] != null && $determination['nom_sel'] != '') { |
$determination_formatee['votes'] = $this->formaterVotes($determination['votes']); |
$liste_determinations_formatees[] = $determination_formatee; |
} |
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 creerDeterminationAPartirObservation($observation) { |
$proposition = array("id_commentaire" => "0", |
"observation" => $observation['id_observation'], |
"proposition" => "0", |
"id_parent" => "0", |
"auteur.id" => $observation['auteur.id'], |
"texte" => null, |
"auteur.nom" => $observation['auteur.nom'], |
"auteur.prenom" => $observation['auteur.prenom'], |
"auteur.courriel" => $observation['observateur'], |
"date" => $observation['date_observation'], |
"nom_sel" => $observation['determination.ns'], |
"votes" => array('oui' => 0, 'non' => 0) |
); |
return $proposition; |
} |
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; |
} |
} |
?> |
/branches/v1.2-lithium/widget/modules/vote |
---|
New file |
Property changes: |
Added: svn:ignore |
+config.ini |