Subversion Repositories eFlore/Applications.cel

Rev

Rev 2446 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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