701 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe implémentant l'API d'eFlore Cartes pour le projet bdtxa.
|
|
|
5 |
*
|
|
|
6 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Cartes
|
|
|
7 |
*
|
|
|
8 |
* @package eFlore/services
|
|
|
9 |
* @author Jean-Pascal MILCENT <jpm@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-2012 Tela Botanica (accueil@tela-botanica.org)
|
|
|
14 |
*/
|
|
|
15 |
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
|
|
|
16 |
class Cartes {
|
|
|
17 |
|
|
|
18 |
private $parametres = array();
|
|
|
19 |
private $ressources = array();
|
|
|
20 |
|
|
|
21 |
public function consulter($ressources, $parametres) {
|
|
|
22 |
$this->parametres = $parametres;
|
|
|
23 |
$this->ressources = $ressources;
|
|
|
24 |
|
|
|
25 |
$this->analyserRessources();
|
|
|
26 |
$resultat = $this->executerSousService();
|
|
|
27 |
|
|
|
28 |
return $resultat;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
private function analyserRessources() {
|
|
|
32 |
$nbreRessources = count($this->ressources);
|
|
|
33 |
if ($nbreRessources == 0) {
|
|
|
34 |
$message = "A implémenter : carte proportionnelle ensemble des infos";
|
|
|
35 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
36 |
throw new Exception($message, $code);
|
|
|
37 |
} else if ($nbreRessources == 1) {
|
|
|
38 |
if ($this->etreRessourceIdentifiants(0)) {
|
|
|
39 |
$this->sousService = 'Taxons';
|
|
|
40 |
} else if ($this->etreRessourceLegende(0)) {
|
|
|
41 |
$message = "A implémenter : légende carte proportionnelle ensemble des infos";
|
|
|
42 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
43 |
throw new Exception($message, $code);
|
|
|
44 |
} else {
|
|
|
45 |
$message = "La ressource n°1 '{$this->ressources[0]} indiquée n'est pas valable.";
|
|
|
46 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
47 |
throw new Exception($message, $code);
|
|
|
48 |
}
|
|
|
49 |
} else if ($nbreRessources == 2) {
|
|
|
50 |
if ($this->etreRessourceIdentifiants(0) && $this->etreRessourceLegende(1)) {
|
|
|
51 |
$this->sousService = 'Legende';
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private function etreRessourceIdentifiants($position) {
|
|
|
57 |
$ok = true;
|
|
|
58 |
if (isset($this->ressources[$position])) {
|
|
|
59 |
$ids = $this->ressources[$position];
|
|
|
60 |
$projetPattern = '(?:(?:(?:[A-Za-z0-9]+\.)?(?:nn|nt)?:)?(?:[0-9]+,)*[0-9]+)';
|
|
|
61 |
$patternComplet = "/^$projetPattern(?:;$projetPattern)*$/i";
|
|
|
62 |
$ok = preg_match($patternComplet, $ids) ? true : false;
|
|
|
63 |
}
|
|
|
64 |
return $ok;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private function etreRessourceLegende($position) {
|
|
|
68 |
$ok = true;
|
|
|
69 |
if (isset($this->ressources[$position])) {
|
|
|
70 |
$legende = $this->ressources[$position];
|
|
|
71 |
$ok = ($legende == 'legende') ? true : false;
|
|
|
72 |
}
|
|
|
73 |
return $ok;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private function executerSousService() {
|
|
|
77 |
if (isset($this->sousService)) {
|
|
|
78 |
$classe = $this->sousService.'Cartes';
|
|
|
79 |
require_once dirname(__FILE__).DS.'cartes'.DS.$classe.'.php';
|
|
|
80 |
$sousService = new $classe(new Conteneur());
|
|
|
81 |
$resultat = $sousService->consulter($this->ressources, $this->parametres);
|
|
|
82 |
} else {
|
|
|
83 |
$message = "L'analyse des ressources n'a pu aboutir à déterminer le sous service à executer.";
|
|
|
84 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
85 |
throw new Exception($message, $code);
|
|
|
86 |
}
|
|
|
87 |
return $resultat;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
?>
|