Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2
/**
3
* PHP Version 5
4
*
5
* Retourne un RDF des images pour eflore
6
*
7
* @category  PHP
8
* @package   jrest
9
* @author    david <david@tela-botania.org>
10
* @copyright 2010 Tela-Botanica
11
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
* @version   SVN: <svn_id>
13
* @link      /doc/jrest/
14
*/
15
Class ImageRDF extends DBAccessor {
16
 
17
	var $config;
18
 
19
    function ImageRDF($config) {
20
 
21
    	$this->config=$config;
22
    }
23
 
24
 
25
 
26
	/**
27
	 * Recherche des images associee au numero nomenclatural
28
	 * @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M,  L (default)
29
	 */
30
 
31
 
32
    // TODO : recherche taxon ?
33
 
34
	function getElement($uid){
35
 
36
 
37
		// Taille
38
		if (isset($uid[1])) {
39
			$taille=$uid[1]; // S , M ou L
40
		}
41
		else {
42
			$taille='L';
43
		}
44
 
45
 
46
        $DB=$this->connectDB($this->config,'cel_db');
47
 
48
        // Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee.
49
 
50
        $query = 'SELECT * FROM cel_inventory, cel_obs_images, cel_images '.
51
        		' WHERE cel_inventory.num_nom_sel = "'.mysql_escape_string($uid[0]).'"'.
52
        		' AND cel_obs_images.coi_ce_utilisateur = cel_inventory.identifiant '.
53
        		' AND cel_obs_images.coi_ce_observation = cel_inventory.ordre '.
54
				' AND cel_inventory.transmission =  1 '.
55
				' AND cel_images.ci_ce_utilisateur = cel_obs_images.coi_ce_utilisateur '.
56
				' AND  ci_id_image = cel_obs_images.coi_ce_image';
57
 
58
 
59
        $result =& $DB->query($query);
60
 
61
        if (DB::isError($result)) {
62
            die($result->getMessage());
63
        }
64
 
65
 
66
        $picture_path = $this->config['cel_db']['url_images'];
67
 
68
 
69
		// Formatage du xml
70
		$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
71
		$xml .= '<rdf:RDF'."\n";
72
		$xml .= '	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
73
		$xml .= '	xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
74
		$xml .= '	xmlns:dcterms="http://purl.org/dc/terms">'."\n";
75
 
76
 
77
        while ($picture =& $result->fetchrow(DB_FETCHMODE_ASSOC)) {
78
 
79
 
80
        	// Calcul du chemin sur le serveur en fonction de l'identifiant (id)
81
 
82
        	$id = $picture['ci_id_image'];
83
			$id = sprintf('%09s', $id) ;
84
            $id = wordwrap($id, 3 , '_', true) ;
85
 
86
            $id_fichier = $id.".jpg" ;
87
 
88
            $niveauDossier = split("_", $id) ;
89
 
90
            $dossierNiveau1 = $niveauDossier[0] ;
91
            $dossierNiveau2 = $niveauDossier[1] ;
92
 
93
            $picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
94
 
95
 
96
 
97
			$xml .= '	<rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
98
			$xml .= '		dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['ci_id_image'].'"'."\n";
99
			$xml .= '		dc:title="'.$picture['nom_sel'].'"'."\n";
100
			$xml .= '		dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['ci_nom_original'].'][image_identifiant:'.$picture['ci_id_image'].']';
101
			$xml .= '[image_ordre:'.$picture['ci_ordre'].']';
102
			$xml .= '[observation_identifiant:'.$picture['id'].']';
103
			$xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
104
 
105
			list($identifiant) = split("@", $picture['identifiant']);
106
			$creator=$identifiant."@...";
107
 
108
			$xml .= '		dc:creator="'.$creator.'"'."\n";
109
			$xml .= '		dc:publisher="CEL"'."\n";
110
			$xml .= '		dcterms:spatial="'.utf8_decode($picture['location'])." (".$picture['id_location'].")".'"'."\n";
111
 
112
	        if ($picture['date_observation'] != '0000-00-00 00:00:00') {
113
				list($year,$month,$day) = split ('-',$picture['date_observation']);
114
	            list($day) = split (' ',$day);
115
				$created = $day.'/'.$month.'/'.$year;
116
				$xml .= '		dcterms:created="'.$created.'"'."\n";
117
			}
118
			$xml .= '		dcterms:licence="CC BY-SA"/>'."\n";
119
		}
120
 
121
		$xml .= '</rdf:RDF>'."\n";
122
 
123
		// Envoi du xml au navigateur
124
		header("Content-Type: text/xml");
540 david 125
		echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));
416 aurelien 126
 
127
 
128
      }
129
 
130
 
131
}
540 david 132
?>