Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
940 aurelien 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe implémentant l'API d'eFlore concernant les statuts de protection
5
 *
6
 * @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01ListeRouge
7
 *
8
 * @package eFlore/services
9
 * @author Aurélien PERONNET <aurelien@tela-botanica.org>
10
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
 * @version 1.0
13
 * @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
 */
15
class Categorie extends Commun {
16
 
17
	protected $parametres = array();
18
	protected $ressources = array();
19
 
20
	private $bdd;
21
 
22
	public function __construct($config = null) {
23
		$this->config = $config;
24
		$this->bdd = $this->getBdd();
25
	}
26
 
27
	public function consulter($ressources, $parametres) {
28
 
29
		$this->parametres = $parametres;
30
		$this->ressources = $ressources;
31
 
32
		$this->verifierParametres();
33
 
34
		$resultat = new ResultatService();
35
		$resultat->corps = $this->obtenirCategorieListeRouge();
36
 
37
		return $resultat;
38
	}
39
 
40
	private function verifierParametres() {
41
		$erreurs = array();
42
 
43
		if (empty($this->parametres['masque.nn'])) {
44
			$erreurs[] = 'renseignez une valeur pour masque.nn';
45
		}
46
 
47
		if(!is_numeric($this->parametres['masque.nn'])) {
48
			$erreurs[] = 'la valeur pour masque.nn doit être un entier';
49
		}
50
 
51
		if (count($erreurs) > 0) {
52
			$message = implode('<br />', $erreurs);
53
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
54
			throw new Exception($message, $code);
55
		}
56
	}
57
 
58
	public function obtenirCategorieListeRouge() {
59
		$nn = $this->parametres['masque.nn'];
941 aurelien 60
		$nns = $this->obtenirNumNomTaxonsSuperieurs(Config::get('referentiel'), $nn);
940 aurelien 61
		$nns[] = $nn;
62
		$nns = array_map(array($this->bdd, 'proteger') ,$nns);
63
 
64
		$requete = "SELECT * FROM ".Config::get('bdd_table_liste_rouge').' '.
65
				           "WHERE num_nom_retenu IN (".implode(',',$nns).") ";
66
 
67
		return $this->bdd->recupererTous($requete);
68
	}
69
}