1617 |
mathias |
1 |
<?php
|
1820 |
jpm |
2 |
// declare(encoding='UTF-8');
|
1617 |
mathias |
3 |
/**
|
1818 |
jpm |
4 |
* Accès aux sous-services de statistiques pour Identiplante / Pictoflora
|
1795 |
jpm |
5 |
*
|
1818 |
jpm |
6 |
* @see Documentation : <http://www.tela-botanica.org/wikini/DevInformatiques/wakka.php?wiki=AppliDelStats>
|
1795 |
jpm |
7 |
*
|
|
|
8 |
* @category DEL
|
|
|
9 |
* @package Services
|
|
|
10 |
* @subpackage Statistiques
|
|
|
11 |
* @version 0.1
|
|
|
12 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
13 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
14 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
15 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
16 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
17 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
|
|
18 |
*/
|
1617 |
mathias |
19 |
class Statistiques extends RestService {
|
|
|
20 |
|
1818 |
jpm |
21 |
private $parametres = array();
|
|
|
22 |
private $ressources = array();
|
|
|
23 |
private $methode = null;
|
|
|
24 |
private $serviceNom = 'statistiques';
|
|
|
25 |
private $sousServiceNom = null;
|
|
|
26 |
private $cheminCourant = null;
|
1617 |
mathias |
27 |
|
1818 |
jpm |
28 |
private $conteneur;
|
|
|
29 |
|
|
|
30 |
/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
|
|
|
31 |
protected $utilisationParametresBruts = true;
|
|
|
32 |
|
1617 |
mathias |
33 |
public function __construct() {
|
1818 |
jpm |
34 |
$this->cheminCourant = dirname(__FILE__).DS;
|
1617 |
mathias |
35 |
}
|
|
|
36 |
|
|
|
37 |
public function consulter($ressources, $parametres) {
|
1818 |
jpm |
38 |
$this->methode = 'consulter';
|
|
|
39 |
$this->initialiserRessourcesEtParametres($ressources, $parametres);
|
|
|
40 |
return $this->executerService();
|
|
|
41 |
}
|
1617 |
mathias |
42 |
|
1818 |
jpm |
43 |
private function initialiserRessourcesEtParametres($ressources, $parametres = array()) {
|
|
|
44 |
$this->ressources = $ressources;
|
|
|
45 |
$this->parametres = $parametres;
|
|
|
46 |
}
|
1617 |
mathias |
47 |
|
1818 |
jpm |
48 |
private function executerService() {
|
|
|
49 |
$reponseHttp = new ReponseHttp();
|
|
|
50 |
try {
|
|
|
51 |
$this->conteneur = new Conteneur($this->parametres);
|
|
|
52 |
$resultat = $this->traiterRessources();
|
|
|
53 |
$reponseHttp->setResultatService($resultat);
|
|
|
54 |
} catch (Exception $e) {
|
|
|
55 |
$reponseHttp->ajouterErreur($e);
|
1617 |
mathias |
56 |
}
|
|
|
57 |
$reponseHttp->emettreLesEntetes();
|
|
|
58 |
$corps = $reponseHttp->getCorps();
|
|
|
59 |
return $corps;
|
|
|
60 |
}
|
|
|
61 |
|
1818 |
jpm |
62 |
private function traiterRessources() {
|
|
|
63 |
$this->analyserRessources();
|
|
|
64 |
$retour = $this->initialiserService();
|
|
|
65 |
return $retour;
|
1617 |
mathias |
66 |
}
|
|
|
67 |
|
1818 |
jpm |
68 |
private function analyserRessources() {
|
|
|
69 |
if ($this->methode == 'consulter') {
|
|
|
70 |
$this->sousServiceNom = 'statistiques-par-annee';
|
|
|
71 |
}
|
|
|
72 |
if ($this->sousServiceNom == null) {
|
|
|
73 |
$this->lancerMessageErreurRessource();
|
|
|
74 |
}
|
1617 |
mathias |
75 |
}
|
|
|
76 |
|
1818 |
jpm |
77 |
private function lancerMessageErreurRessource() {
|
|
|
78 |
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
|
|
|
79 |
$message = "La ressource demandée '$ressource' ".
|
|
|
80 |
"n'est pas disponible pour le service {$this->serviceNom} !\n".
|
|
|
81 |
self::getDoc();
|
|
|
82 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
83 |
throw new Exception($message, $code);
|
1788 |
mathias |
84 |
}
|
|
|
85 |
|
1818 |
jpm |
86 |
public static function getDoc() {
|
|
|
87 |
return "Les URLs disponibles pour ce service sont :\n".
|
|
|
88 |
" * en GET :\n".
|
|
|
89 |
" - statistiques/tout\n".
|
|
|
90 |
" - statistiques/moyenneObsSansNomParMois\n".
|
|
|
91 |
" - statistiques/moyenneObsIdentifieesParMois\n".
|
|
|
92 |
" - statistiques/pourcentageObsIdentifieesEnFinDAnnee\n".
|
|
|
93 |
" - statistiques/pourcentageObsIdentifieesEnFinDAnneePlusPlus\n".
|
|
|
94 |
" - statistiques/moyenneActionsParJour\n".
|
|
|
95 |
" - statistiques/personnesEnvoyantUnePropositionParMois\n";
|
1617 |
mathias |
96 |
}
|
|
|
97 |
|
1818 |
jpm |
98 |
private function initialiserService() {
|
|
|
99 |
$classe = $this->obtenirNomClasseService($this->sousServiceNom);
|
|
|
100 |
$chemins = array();
|
|
|
101 |
$chemins[] = $this->cheminCourant.$this->serviceNom.DS.$classe.'.php';
|
|
|
102 |
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
|
|
|
103 |
$retour = '';
|
|
|
104 |
$service = null;
|
1788 |
mathias |
105 |
|
1818 |
jpm |
106 |
foreach ($chemins as $chemin) {
|
|
|
107 |
if (file_exists($chemin)) {
|
|
|
108 |
require_once $chemin;
|
|
|
109 |
$service = new $classe($this->conteneur);
|
|
|
110 |
if ($this->methode == 'consulter') {
|
|
|
111 |
$retour = $service->consulter();
|
|
|
112 |
} else {
|
|
|
113 |
$message = "Le sous-service '{$this->sousServiceNom}' du service '{$this->serviceNom}' ".
|
|
|
114 |
"ne possède pas de méthode '{$this->methode}' !";
|
|
|
115 |
$code = RestServeur::HTTP_NON_IMPLEMENTE;
|
|
|
116 |
throw new Exception($message, $code);
|
|
|
117 |
}
|
1788 |
mathias |
118 |
}
|
|
|
119 |
}
|
1624 |
mathias |
120 |
|
1818 |
jpm |
121 |
if (is_null($service)) {
|
|
|
122 |
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
|
|
|
123 |
$message = "Le classe '$classe' correspondant à la ressource '$ressource' ".
|
|
|
124 |
"est introuvable par le service '{$this->serviceNom}' !";
|
|
|
125 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
126 |
throw new Exception($message, $code);
|
1788 |
mathias |
127 |
}
|
1818 |
jpm |
128 |
return $retour;
|
1624 |
mathias |
129 |
}
|
|
|
130 |
|
1818 |
jpm |
131 |
private function obtenirNomClasseService($mot) {
|
|
|
132 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
133 |
return $classeNom;
|
1617 |
mathias |
134 |
}
|
1795 |
jpm |
135 |
}
|