Subversion Repositories eFlore/Applications.cel

Rev

Rev 3818 | Rev 3823 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3817 delphine 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Service recherche d'images publique a partir de divers critères.
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
 */
18
class CelWidgetImage extends Cel {
19
 
20
	const start_defaut = 0;
21
	const limit_defaut = 100;
22
	const tri_defaut = 'ci.date_creation';
23
	const dir_defaut = 'DESC';
24
 
25
	public function getRessource() {
26
 
27
	}
28
 
29
	public function getElement($uid) {
30
		// restriction aux observations publiques
31
		$criteres = array('transmission' => '1');
32
 
33
		if ($uid[0] != '*' && empty($_GET)) {
34
			header("content-type: application/json");
35
			$images_json = json_encode(array());
36
			print $images_json;
37
			exit();
38
		}
39
 
40
		$this->start = isset($_GET['start']) ? $_GET['start'] : self::start_defaut;
41
		$this->limit = isset($_GET['limit']) ? $_GET['limit'] : self::limit_defaut;
42
 
43
		$criteres['mots_cles'] = isset($_GET['tag']) ? $_GET['tag'] : null;
44
		$criteres['auteur'] = isset($_GET['auteur']) ? $_GET['auteur'] : null;
45
		$criteres['zone_geo'] = isset($_GET['commune']) ? $_GET['commune'] : null;
46
		$criteres['taxon'] = isset($_GET['taxon']) ? $_GET['taxon'] : null;
47
		$criteres['ce_zone_geo'] = isset($_GET['dept']) ? $_GET['dept'] : null;
48
		$criteres['famille'] = isset($_GET['famille']) ? $_GET['famille'] : null;
49
		$criteres['recherche'] = isset($_GET['recherche']) ? $_GET['recherche'] : null;
50
		$criteres['standard'] = isset($_GET['standard']) ? $_GET['standard'] : 1;
51
		$criteres['tri'] = isset($_GET['tri']) ? $_GET['tri'] : self::tri_defaut;
52
		$criteres['dir'] = isset($_GET['dir']) ? $_GET['dir'] : self::dir_defaut;
53
 
54
		$chercheur_images = new RechercheImage($this->config);
55
		$total = $chercheur_images->compterImages(null, $criteres);
56
		$images = $chercheur_images->rechercherImagesJoinObservation(null, $criteres, $this->start, $this->limit);
3818 delphine 57
        $images = $this->mettreEnForme($images);
58
 
3817 delphine 59
		$resultat = array('total' => $total,'images' => $images);
60
		$images_json = json_encode($resultat);
61
		$images_json = str_replace('\u0000','',$images_json);
62
 
63
		header("content-type: application/json");
64
		print $images_json;
65
		exit();
66
	}
3818 delphine 67
	public function mettreEnForme($images) {
68
	    $retour = array();
3820 delphine 69
	    foreach ($images as $id => $image) {
3818 delphine 70
	       $retour[$id]['id_photo'] = $image['id_photo'];
71
	       unset($image['id_photo']);
72
	       $retour[$id]['guid'] = $image['guid'];
73
	       unset($image['guid']);
74
	       $retour[$id]['nom_original'] = $image['nom_original'];
75
	       unset($image['nom_original']);
76
	       $retour[$id]['date_photo'] = $image['date_photo'];
77
	       unset($image['date_photo']);
78
	       $retour[$id]['licence'] = $image['licence'];
79
	       unset($image['licence']);
80
	       $retour[$id]['attribution'] = $image['attribution'];
81
	       unset($image['attribution']);
82
	       $retour[$id]['url_photo'] = $image['url_photo'];
83
	       unset($image['url_photo']);
84
	       $retour[$id]['tags_photo'] = $image['tags_photo'];
85
	       unset($image['tags_photo']);
86
 
3820 delphine 87
	       $retour[$id]["utilisateur"]['id_utilisateur'] = $image['id_utilisateur'];
88
	       unset($image['id_utilisateur']);
89
	       $retour[$id]["utilisateur"]['mail_utilisateur'] = $image['mail_utilisateur'];
90
	       unset($image['mail_utilisateur']);
91
	       $retour[$id]["utilisateur"]['nom_utilisateur'] = $image['nom_utilisateur'];
92
	       unset($image['nom_utilisateur']);
93
 
3818 delphine 94
	       $retour[$id]['obs'] = $image;
95
	    }
96
	    return $retour;
97
	}
3817 delphine 98
}