Subversion Repositories eFlore/Applications.cel

Rev

Rev 2458 | Details | Compare with Previous | Last modification | View Log | RSS feed

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