Subversion Repositories eFlore/Applications.cel

Rev

Rev 3857 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Retourne des infos au format RDF sur les imags.
 *
 * @internal   Mininum PHP version : 5.2
 * @category   CEL
 * @package    Services
 * @subpackage Images
 * @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 ImageRDF extends Cel {

        /**
         * Recherche des images associee au numero nomenclatural
         * @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M,  L (default)
         */
        public function getElement($uid){
                $nomSelNnP = Cel::db()->proteger($uid[0]);
                $taille = isset($uid[1]) ? $uid[1] : 'L';

                // Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
                $requete = 'SELECT co.id_observation, co.nom_sel, co.ordre, '.
                        '       co.prenom_utilisateur, co.nom_utilisateur, co.courriel_utilisateur, '.
                        '       co.zone_geo, .co.ce_zone_geo, co.date_observation, '.
                        '       ci.id_image, ci.nom_original '.
                        'FROM cel_obs AS co INNER JOIN cel_images AS ci ON (co.id_observation = ci.ce_observation) '.
                        "WHERE co.nom_sel_nn = $nomSelNnP ".
                        'AND co.transmission = 1 '.
                        ' -- '.__FILE__.':'.__LINE__;
                //echo $requete;
                $resultats = Cel::db()->requeter($requete);

                $auteursEmails = array();
                $donnees = array();
                if ($resultats !== false && is_array($resultats)) {
                        $urlImgTpl = $this->config['settings']['celImgUrlTpl'];
                        foreach ($resultats as $picture) {
                                $id = sprintf('%09s', $picture['id_image']) ;
                                $dateObsTimestamp = $this->convertirDateHeureMysqlEnTimestamp($picture['date_observation']);
                                $auteursEmails[] = $picture['courriel_utilisateur'];

                                $data = array();
                                $data['url_img'] = sprintf($urlImgTpl, $id.$taille);
                                $data['id_image'] = $picture['id_image'];
                                $data['guid'] = 'urn:lsid:tela-botanica.org:celpic:'.$data['id_image'];
                                $data['nom_original'] = $picture['nom_original'];
                                $data['id_observation'] = $picture['id_observation'];
                                $data['nom_sel'] = $picture['nom_sel'];
                                $data['ordre'] = $picture['ordre'];
                                $data['zone_geo'] = utf8_decode($picture['zone_geo']);
                                $data['ce_zone_geo'] = $picture['ce_zone_geo'];
                                $data['ce_zone_geo'] = $picture['ce_zone_geo'];
                                $data['courriel_utilisateur'] = $picture['courriel_utilisateur'];
                                $data['date_observation'] = ($dateObsTimestamp != 0) ? date('d/m/Y', $dateObsTimestamp) : null;
                                $donnees[] = $data;
                        }
                }
                $auteursIntitules = $this->creerAuteurs($auteursEmails);
                $xml = $this->formaterRdf($donnees, $auteursIntitules);
                // Envoi du xml au navigateur
                header("Content-Type: text/xml");
                echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));
        }

        private function formaterRdf($donnees, $auteurs) {
                $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
                        '<rdf:RDF'."\n".
                        '       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".
                        '       xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
                        '       xmlns:dcterms="http://purl.org/dc/terms">'."\n";
                if (count($donnees) > 0) {
                        foreach ($donnees as $data) {
                                $intituleAuteur = $auteurs[$data['courriel_utilisateur']];
                                $xml .= '       <rdf:Description about="'.$data['url_img'].'"'."\n".
                                        '               dc:identifier="'.$data['guid'].'"'."\n".
                                        '               dc:title="'.$data['nom_sel'].'"'."\n".
                                        '               dc:description="'.$data['nom_sel'].' - '.
                                        '[fichier_origine:'.$data['nom_original'].']'.
                                        '[image_identifiant:'.$data['id_image'].']'.
                                        '[image_ordre:'.$data['ordre'].']'.
                                        '[observation_identifiant:'.$data['id_observation'].']'.
                                        '[observation_ordre:'.$data['ordre'].']'.'"'."\n".
                                        '               dc:creator="'.$intituleAuteur.'"'."\n".
                                        '               dc:publisher="CEL"'."\n".
                                        '               dcterms:spatial="'.$data['zone_geo']." (".$data['ce_zone_geo'].")".'"'."\n";
                                if (isset($data['date_observation'])) {
                                        $xml .= '               dcterms:created="'.$data['date_observation'].'"'."\n";
                                }
                                $xml .= '               dcterms:licence="CC BY-SA"/>'."\n";
                        }
                }
                $xml .= '</rdf:RDF>'."\n";
                return $xml;
        }
}