416 |
aurelien |
1 |
<?php
|
871 |
aurelien |
2 |
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
|
|
|
3 |
|
416 |
aurelien |
4 |
/**
|
|
|
5 |
* PHP Version 5
|
2446 |
jpm |
6 |
*
|
416 |
aurelien |
7 |
* Retourne un RDF des images pour eflore
|
|
|
8 |
*
|
|
|
9 |
* @category PHP
|
|
|
10 |
* @package jrest
|
881 |
aurelien |
11 |
* @author david <david@tela-botanica.org>
|
416 |
aurelien |
12 |
* @copyright 2010 Tela-Botanica
|
|
|
13 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
14 |
* @version SVN: <svn_id>
|
|
|
15 |
* @link /doc/jrest/
|
|
|
16 |
*/
|
871 |
aurelien |
17 |
class ImageRDF extends Cel {
|
416 |
aurelien |
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Recherche des images associee au numero nomenclatural
|
|
|
21 |
* @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M, L (default)
|
2446 |
jpm |
22 |
*/
|
416 |
aurelien |
23 |
function getElement($uid){
|
2446 |
jpm |
24 |
$nomSelNnP = Cel::db()->proteger($uid[0]);
|
|
|
25 |
$taille = isset($uid[1]) ? $uid[1] : 'L';
|
416 |
aurelien |
26 |
|
2446 |
jpm |
27 |
// Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
|
|
|
28 |
$requete = 'SELECT co.id_observation, co.nom_sel, co.ordre, '.
|
|
|
29 |
' co.prenom_utilisateur, co.nom_utilisateur, co.courriel_utilisateur, '.
|
|
|
30 |
' co.zone_geo, .co.ce_zone_geo, co.date_observation, '.
|
|
|
31 |
' ci.id_image, ci.nom_original '.
|
|
|
32 |
'FROM cel_obs AS co INNER JOIN cel_images AS ci ON (co.id_observation = ci.ce_observation) '.
|
|
|
33 |
"WHERE co.nom_sel_nn = $nomSelNnP ".
|
|
|
34 |
'AND co.transmission = 1 '.
|
|
|
35 |
' -- '.__FILE__.':'.__LINE__;
|
|
|
36 |
//echo $requete;
|
|
|
37 |
$resultats = Cel::db()->requeter($requete);
|
416 |
aurelien |
38 |
|
2446 |
jpm |
39 |
$auteursEmails = array();
|
|
|
40 |
$donnees = array();
|
|
|
41 |
if ($resultats !== false && is_array($resultats)) {
|
|
|
42 |
$urlImgTpl = $this->config['settings']['celImgUrlTpl'];
|
|
|
43 |
foreach ($resultats as $picture) {
|
|
|
44 |
$id = sprintf('%09s', $picture['id_image']) ;
|
|
|
45 |
$dateObsTimestamp = $this->convertirDateHeureMysqlEnTimestamp($picture['date_observation']);
|
|
|
46 |
$auteursEmails[] = $picture['courriel_utilisateur'];
|
|
|
47 |
|
|
|
48 |
$data = array();
|
|
|
49 |
$data['url_img'] = sprintf($urlImgTpl, $id.$taille);
|
|
|
50 |
$data['id_image'] = $picture['id_image'];
|
|
|
51 |
$data['guid'] = 'urn:lsid:tela-botanica.org:celpic:'.$data['id_image'];
|
|
|
52 |
$data['nom_original'] = $picture['nom_original'];
|
|
|
53 |
$data['id_observation'] = $picture['id_observation'];
|
|
|
54 |
$data['nom_sel'] = $picture['nom_sel'];
|
|
|
55 |
$data['ordre'] = $picture['ordre'];
|
|
|
56 |
$data['zone_geo'] = utf8_decode($picture['zone_geo']);
|
|
|
57 |
$data['ce_zone_geo'] = $picture['ce_zone_geo'];
|
|
|
58 |
$data['ce_zone_geo'] = $picture['ce_zone_geo'];
|
|
|
59 |
$data['courriel_utilisateur'] = $picture['courriel_utilisateur'];
|
|
|
60 |
$data['date_observation'] = ($dateObsTimestamp != 0) ? date('d/m/Y', $dateObsTimestamp) : null;
|
|
|
61 |
$donnees[] = $data;
|
|
|
62 |
}
|
871 |
aurelien |
63 |
}
|
2446 |
jpm |
64 |
$auteursIntitules = $this->creerAuteurs($auteursEmails);
|
|
|
65 |
$xml = $this->formaterRdf($donnees, $auteursIntitules);
|
|
|
66 |
// Envoi du xml au navigateur
|
|
|
67 |
header("Content-Type: text/xml");
|
|
|
68 |
echo utf8_encode(str_replace(' & ', ' & ', $xml));
|
|
|
69 |
}
|
416 |
aurelien |
70 |
|
2446 |
jpm |
71 |
private function formaterRdf($donnees, $auteurs) {
|
|
|
72 |
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
|
|
|
73 |
'<rdf:RDF'."\n".
|
|
|
74 |
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".
|
|
|
75 |
' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
|
|
|
76 |
' xmlns:dcterms="http://purl.org/dc/terms">'."\n";
|
|
|
77 |
if (count($donnees) > 0) {
|
|
|
78 |
foreach ($donnees as $data) {
|
|
|
79 |
$intituleAuteur = $auteurs[$data['courriel_utilisateur']];
|
|
|
80 |
$xml .= ' <rdf:Description about="'.$data['url_img'].'"'."\n".
|
|
|
81 |
' dc:identifier="'.$data['guid'].'"'."\n".
|
|
|
82 |
' dc:title="'.$data['nom_sel'].'"'."\n".
|
|
|
83 |
' dc:description="'.$data['nom_sel'].' - '.
|
|
|
84 |
'[fichier_origine:'.$data['nom_original'].']'.
|
|
|
85 |
'[image_identifiant:'.$data['id_image'].']'.
|
|
|
86 |
'[image_ordre:'.$data['ordre'].']'.
|
|
|
87 |
'[observation_identifiant:'.$data['id_observation'].']'.
|
|
|
88 |
'[observation_ordre:'.$data['ordre'].']'.'"'."\n".
|
|
|
89 |
' dc:creator="'.$intituleAuteur.'"'."\n".
|
|
|
90 |
' dc:publisher="CEL"'."\n".
|
|
|
91 |
' dcterms:spatial="'.$data['zone_geo']." (".$data['ce_zone_geo'].")".'"'."\n";
|
|
|
92 |
if (isset($data['date_observation'])) {
|
|
|
93 |
$xml .= ' dcterms:created="'.$data['date_observation'].'"'."\n";
|
2009 |
mathias |
94 |
}
|
2446 |
jpm |
95 |
$xml .= ' dcterms:licence="CC BY-SA"/>'."\n";
|
416 |
aurelien |
96 |
}
|
|
|
97 |
}
|
|
|
98 |
$xml .= '</rdf:RDF>'."\n";
|
2446 |
jpm |
99 |
return $xml;
|
|
|
100 |
}
|
|
|
101 |
}
|