/branches/v1.5-carbone/services/modules/0.1/syndication/VotesParProtocole.php |
---|
File deleted |
\ No newline at end of file |
/branches/v1.5-carbone/services/modules/0.1/syndication/VotesParTag.php |
---|
File deleted |
\ No newline at end of file |
/branches/v1.5-carbone/services/modules/0.1/syndication/Tags.php |
---|
New file |
0,0 → 1,210 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service fournissant des informations concernant les tags sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* |
* @category DEL |
* @package Services |
* @subpackage Syndication |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien PERONNET <aurelien@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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class Tags { |
private $categorie = 'Tag'; |
private $conteneur; |
private $bdd; |
private $navigation; |
private $syndication; |
private $mapping = array(); |
public function __construct(Conteneur $conteneur) { |
$this->conteneur = $conteneur; |
$this->bdd = $this->conteneur->getBdd(); |
$this->navigation = $this->conteneur->getNavigation(); |
$this->syndication = $this->conteneur->getSyndicationOutils(); |
$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping'); |
} |
public function consulter() { |
if ($this->syndication->fluxAdminDemande()) { |
$this->syndication->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$derniere_info_en_date = reset($elements); |
$donnees = $this->syndication->construireDonneesCommunesAuFlux('tag', $derniere_info_en_date['date']); |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* Générer les données communes & spécifiques à chaque item |
* */ |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = strtotime($info['date']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$item['titre'] = $this->creerTitre($info); |
$item['guid'] = $this->creerGuidItem($info); |
$item['lien'] = $this->creerLienItem($info); |
$item['categorie'] = htmlentities($this->categorie); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->formaterNomTagueur($info); |
return $item; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('syndication.tag_guid_tpl'), $element['id_tag']); |
return $guid; |
} |
private function creerLienItem($element) { |
// TODO : ajouter un lien vers la plateforme validation de picto lorsqu'elle sera dispo |
$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['id_image']); |
return $lien; |
} |
private function creerTitre($element) { |
$tag = $element['tag']; |
$nomSel = htmlspecialchars($element['nom_sel']); |
$tagueur = htmlspecialchars($this->formaterNomTagueur($element)); |
$auteurImg = $this->formaterNomAuteurImg($element); |
$titre = "Tag «{$tag}» par $tagueur pour $nomSel de $auteurImg"; |
return $titre; |
} |
private function creerDescription($donnees, $item) { |
$idTag = htmlspecialchars($donnees['id_tag']); |
$idObs = htmlspecialchars($donnees['id_observation']); |
$idImg = htmlspecialchars($donnees['id_image']); |
$urlImg = $this->syndication->getUrlImage($donnees['id_image']); |
$miniatureUrl = $this->syndication->getUrlImage($donnees['id_image'], 'CRS'); |
$nomSelActuel = htmlspecialchars($donnees['nom_sel']); |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation'])); |
$lieuObs = htmlspecialchars($donnees['zone_geo']); |
$tag = htmlspecialchars($donnees['tag']); |
$dateTag = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date']))); |
$auteurImg = htmlspecialchars($this->creerAuteurImg($donnees)); |
$tagueur = htmlspecialchars($this->creerTagueur($donnees)); |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'. |
'<h2>'."Tag pictoFlora #$idTag pour l'image #$idImg de l'observation #$idObs".'</h2>'. |
'<div class="gauche">'. |
' <a href="'.$urlImg.'">'. |
' <img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'. |
' </a>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Image #$idImg de l'observation #$idObs</h3>". |
' <ul>'. |
' <li><span class="champ">'."Auteur de l'image :</span> $auteurImg</li>". |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>". |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>". |
' <li><span class="champ">'."Date :</span> $dateObs</li>". |
' </ul>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Tag #$idTag</h3>". |
' <ul>'. |
' <li><span class="champ">'."Tag :</span> <strong>$tag</strong></li>". |
' <li><span class="champ">'."Auteur :</span> $tagueur</li>". |
' <li><span class="champ">'."Taguée le :</span> $dateTag</li>". |
' </ul>'. |
'</div>'; |
return $description; |
} |
private function creerAuteurImg($info) { |
$auteur = $this->formaterNomAuteurImg($info). |
($this->syndication->fluxAdminDemande() ? ' ('.$info['auteur_courriel'].')' : ''); |
return $auteur; |
} |
private function formaterNomAuteurImg($info) { |
$auteur = 'Anonyme'; |
if ($info['auteur_prenom'] != '' && $info['auteur_nom'] != '') { |
$auteur = $info['auteur_prenom'].' '.$info['auteur_nom']; |
} |
return $auteur; |
} |
private function creerTagueur($info) { |
$tagueur = $this->formaterNomTagueur($info). |
($this->syndication->fluxAdminDemande() ? ' ('.$info['tagueur_courriel'].')' : ''); |
return $tagueur; |
} |
private function formaterNomTagueur($info) { |
$tagueur = 'Anonyme'; |
if ($info['tagueur_prenom'] != '' && $info['tagueur_nom'] != '') { |
$tagueur = $info['tagueur_prenom'].' '.$info['tagueur_nom']; |
} |
return $tagueur; |
} |
/** |
* Retrouver les derniers votes image |
* */ |
private function getDerniersVotesImage() { |
$clauseWhere = $this->chargerClauseWhere(); |
$requete = 'SELECT DISTINCT id_tag, tag, date, '. |
' do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, di.id_image, '. |
' duo.prenom AS auteur_prenom, duo.nom AS auteur_nom, duo.courriel AS auteur_courriel, '. |
' du.prenom AS tagueur_prenom, du.nom AS tagueur_nom, du.courriel AS tagueur_courriel '. |
'FROM del_image_tag AS dit '. |
' INNER JOIN del_image AS di '. |
' ON ce_image = id_image '. |
' INNER JOIN del_observation AS do '. |
' ON di.ce_observation = do.id_observation '. |
' LEFT JOIN del_utilisateur AS duo '. |
' ON do.ce_utilisateur = duo.id_utilisateur '. |
' LEFT JOIN del_utilisateur AS du '. |
' ON if((CHAR_LENGTH(dit.ce_utilisateur) <> 32),CAST(dit.ce_utilisateur AS unsigned),0) '. |
' = du.id_utilisateur '. |
'WHERE actif = 1 '. |
($clauseWhere != '' ? "AND $clauseWhere " : ''). |
'ORDER BY date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '. |
' -- '.__FILE__.' : '.__LINE__; |
$elements = $this->bdd->recupererTous($requete); |
return $elements; |
} |
private function chargerClauseWhere() { |
$where = array(); |
$filtres = $this->navigation->getFiltre(); |
if (!empty($filtres)) { |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.tag_filtres'); |
foreach ($filtres as $cleFiltre => $valeur) { |
if (in_array($cleFiltre, $filtrePossibles)) { |
$champ = $this->mapping[$cleFiltre]; |
$valeurP = $this->bdd->proteger($valeur); |
$where[] = " $champ = $valeurP "; |
} |
} |
} |
return (!empty($where)) ? implode('AND', $where) : ''; |
} |
} |
/branches/v1.5-carbone/services/modules/0.1/syndication/Votes.php |
---|
New file |
0,0 → 1,201 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service fournissant des informations concernant les votes sur les images de DEL en fonction d'un protocole |
* au format RSS1, RSS2 ou ATOM. |
* |
* @category DEL |
* @package Services |
* @subpackage Syndication |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien PERONNET <aurelien@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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class Votes { |
private $categorie = 'Vote protocole'; |
private $conteneur; |
private $bdd; |
private $navigation; |
private $syndication; |
private $mapping = array(); |
public function __construct(Conteneur $conteneur) { |
$this->conteneur = $conteneur; |
$this->bdd = $this->conteneur->getBdd(); |
$this->navigation = $this->conteneur->getNavigation(); |
$this->syndication = $this->conteneur->getSyndicationOutils(); |
$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping'); |
} |
public function consulter() { |
if ($this->syndication->fluxAdminDemande()) { |
$this->syndication->demanderAutorisationAdmin(); |
} |
$donnees_brutes = $this->getDerniersVotesImage(); |
$commentaires_formates = $this->formaterPourRss($donnees_brutes) ; |
return $commentaires_formates; |
} |
/** |
* Formater les données pour mettre en page le RSS |
* */ |
private function formaterPourRss($elements) { |
$derniere_info_en_date = reset($elements); |
$donnees = $this->syndication->construireDonneesCommunesAuFlux('vote', $derniere_info_en_date['date_vote']); |
foreach ($elements as $element) { |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element); |
} |
return $donnees; |
} |
/** |
* Générer les données communes & spécifiques à chaque item |
* */ |
private function construireDonneesCommunesAuxItems($info) { |
$item = array(); |
$date_modification_timestamp = strtotime($info['date_vote']); |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp); |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp); |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp); |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp); |
$item['titre'] = $this->creerTitre($info); |
$item['guid'] = $this->creerGuidItem($info); |
$item['lien'] = $this->creerLienItem($info); |
$item['categorie'] = htmlentities($this->categorie); |
$item['description'] = $this->creerDescription($info, $item); |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item)); |
$item['modifier_par'] = $this->creerVotant($info); |
return $item; |
} |
private function creerGuidItem($element) { |
$guid = sprintf($this->conteneur->getParametre('syndication.vote_guid_tpl'), $element['id_vote']); |
return $guid; |
} |
private function creerLienItem($element) { |
$lien = sprintf($this->conteneur->getParametre('img_fiche_tpl'), $element['ce_image']); |
return $lien; |
} |
private function creerTitre($element) { |
$noteVote = $element['valeur']; |
$nomSci = htmlspecialchars($element['nom_sel']); |
$votant = htmlspecialchars($this->creerVotant($element)); |
$observateur = htmlspecialchars($this->creerObservateur($element)); |
$titre = "Vote $noteVote par $votant pour $nomSci de $observateur"; |
return $titre; |
} |
private function creerDescription($donnees, $item) { |
$idVote = htmlspecialchars($donnees['id_vote']); |
$idObs = htmlspecialchars($donnees['id_observation']); |
$idImg = htmlspecialchars($donnees['ce_image']); |
$urlImg = $this->syndication->getUrlImage($donnees['ce_image']); |
$miniatureUrl = $this->syndication->getUrlImage($donnees['ce_image'], 'CRS'); |
$nomSelActuel = htmlspecialchars($donnees['nom_sel']); |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['date_observation'])); |
$lieuObs = htmlspecialchars($donnees['zone_geo']); |
$protocole = htmlspecialchars($donnees['intitule']); |
$votant = htmlspecialchars($this->creerVotant($donnees)); |
$dateVote = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date_vote']))); |
$observateur = htmlspecialchars($this->creerObservateur($donnees)); |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'. |
'<h2>'."Vote pictoFlora #$idVote pour l'image #$idImg de l'observation #$idObs".'</h2>'. |
'<div class="gauche">'. |
' <a href="'.$urlImg.'">'. |
' <img src="'.$miniatureUrl.'" alt="Img #'.$idImg.'"/>'. |
' </a>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Image #$idImg de l'observation #$idObs</h3>". |
' <ul>'. |
' <li><span class="champ">'."Auteur de l'image :</span> $observateur</li>". |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>". |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>". |
' <li><span class="champ">'."Date :</span> $dateObs</li>". |
' </ul>'. |
'</div>'. |
'<div class="gauche">'. |
" <h3>Vote #$idVote</h3>". |
' <ul>'. |
' <li><span class="champ">'."Protocole :</span> <strong>$protocole</strong></li>". |
' <li><span class="champ">'."Valeur :</span> <strong>{$donnees['valeur']}</strong>/5</li>". |
' <li><span class="champ">'."Votant :</span> $votant</li>". |
' <li><span class="champ">'."À voté le :</span> $dateVote</li>". |
' </ul>'. |
'</div>'; |
return $description; |
} |
private function creerVotant($info) { |
$votant = 'Anonyme'; |
if (isset($info['votant_prenom']) && isset($info['votant_nom'])) { |
$votant = $info['votant_prenom'].' '.$info['votant_nom']; |
} |
return $votant; |
} |
private function creerObservateur($info) { |
$observateur = 'Anonyme'; |
if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') { |
$observateur = $info['observateur_prenom'].' '.$info['observateur_nom']; |
} |
return $observateur; |
} |
/** |
* Retrouver les derniers votes image |
* */ |
private function getDerniersVotesImage() { |
$clauseWhere = $this->chargerClauseWhere(); |
$requete = 'SELECT DISTINCT id_vote, ce_image, valeur, divo.date AS date_vote, '. |
' duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, '. |
' duv.prenom AS votant_prenom, duv.nom AS votant_nom, '. |
' do.id_observation, do.nom_sel, do.zone_geo, do.date_observation, dip.intitule '. |
'FROM del_image_vote AS divo '. |
' INNER JOIN del_image AS di '. |
' ON divo.ce_image = di.id_image '. |
' INNER JOIN del_observation AS do '. |
' ON di.ce_observation = do.id_observation '. |
' INNER JOIN del_image_protocole AS dip '. |
' ON ce_protocole = id_protocole '. |
' LEFT JOIN del_utilisateur AS duo '. |
' ON do.ce_utilisateur = duo.id_utilisateur '. |
' LEFT JOIN del_utilisateur AS duv '. |
' ON if((CHAR_LENGTH(divo.ce_utilisateur) <> 32),CAST(divo.ce_utilisateur AS unsigned),0) '. |
' = duv.id_utilisateur '. |
($clauseWhere != '' ? "WHERE $clauseWhere " : ''). |
'ORDER BY divo.date DESC '. |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(). |
' -- '.__FILE__.' : '.__LINE__; |
$elements = $this->bdd->recupererTous($requete); |
return $elements; |
} |
private function chargerClauseWhere() { |
$where = array(); |
$filtres = $this->navigation->getFiltre(); |
if (!empty($filtres)) { |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.vote_filtres'); |
foreach ($filtres as $cleFiltre => $valeur) { |
if (in_array($cleFiltre, $filtrePossibles)) { |
$champ = $this->mapping[$cleFiltre]; |
$valeurP = $this->bdd->proteger($valeur); |
$where[] = " $champ = $valeurP "; |
} |
} |
} |
return (!empty($where)) ? implode('AND', $where) : ''; |
} |
} |