* @author Jean-Pascal MILCENT * @author Aurelien PERONNET * @license GPL v3 * @license CECILL v2 * @copyright 1999-2014 Tela Botanica */ 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 = ''. '

'."Vote pictoFlora #$idVote pour l'image #$idImg de l'observation #$idObs".'

'. '
'. ' '. ' Img #'.$idImg.''. ' '. '
'. '
'. "

Image #$idImg de l'observation #$idObs

". '
    '. '
  • '."Auteur de l'image : $observateur
  • ". '
  • '."Nom saisi actuel : $nomSelActuel
  • ". '
  • '."Lieu : $lieuObs
  • ". '
  • '."Date : $dateObs
  • ". '
'. '
'. '
'. "

Vote #$idVote

". '
    '. '
  • '."Protocole : $protocole
  • ". '
  • '."Valeur : {$donnees['valeur']}/5
  • ". '
  • '."Votant : $votant
  • ". '
  • '."À voté le : $dateVote
  • ". '
'. '
'; 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() { $elements = array(); $idsVotes = $this->getIdsDerniersVotesImage(); if (!empty($idsVotes)) { $idsVotesConcat = implode(', ', $idsVotes); $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 '. "WHERE id_vote IN ($idsVotesConcat) ". 'ORDER BY divo.date DESC '. 'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(). ' -- '.__FILE__.' : '.__LINE__; $elements = $this->bdd->recupererTous($requete); } return $elements; } /** * Retrouver les ids des derniers votes image * */ private function getIdsDerniersVotesImage() { $clauseWhere = $this->chargerClauseWhere(); $requete = 'SELECT DISTINCT id_vote '. 'FROM del_image_vote '. ($clauseWhere != '' ? "WHERE $clauseWhere " : ''). 'ORDER BY date DESC '. 'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite(). ' -- '.__FILE__.' : '.__LINE__; $resultats = $this->bdd->recupererTous($requete); $idsVotes = array(); if ($resultats != false && is_array($resultats)) { foreach ($resultats as $infos) { $idsVotes[] = $infos['id_vote']; } } return $idsVotes; } 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) : ''; } }