Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 255 | Rev 268 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 260
Line 16... Line 16...
16
class TaxonsCartes {
16
class TaxonsCartes {
Line 17... Line 17...
17
 
17
 
18
	private $parametres = array();
18
	private $parametres = array();
Line 19... Line 19...
19
	private $ressources = array();
19
	private $ressources = array();
20
 
20
 
21
		const CODE_REFTAX_DEFAUT = 'bdtfx';
21
	const CODE_REFTAX_DEFAUT = 'bdtfx';
22
	const TYPE_ID_DEFAUT = 'nn';
22
	const TYPE_ID_DEFAUT = 'nn';
-
 
23
	const CARTE_DEFAUT = 'france_02';
23
	const CARTE_DEFAUT = 'france_02';
24
	const FORMAT_DEFAUT = '550';
24
	const FORMAT_DEFAUT = '550';
25
	const VERSION_DEFAUT = '+';
25
	const MIME_SVG = 'image/svg+xml';
26
	const MIME_SVG = 'image/svg+xml';
Line 26... Line 27...
26
	const MIME_PNG = 'image/png';
27
	const MIME_PNG = 'image/png';
27
	const PRESENCE_CHOROLOGIE = '1';
28
	const PRESENCE_CHOROLOGIE = '1';
28
 
29
 
-
 
30
	private $config = array();
29
	private $config = array();
31
	private $cheminCartesBase = '';
30
	private $cheminCartesBase = '';
32
	private $formatsSupportes = array(self::MIME_SVG, self::MIME_PNG);
31
	private $formats_supportes = array(self::MIME_SVG, self::MIME_PNG);
33
	private $reftaxSupportes = array(self::CODE_REFTAX_DEFAUT);
32
	private $UrlNavigation = null;
34
	private $UrlNavigation = null;
33
	private $taxonsDemandes = array();
35
	private $taxonsDemandes = array();
Line 48... Line 50...
48
		$this->Bdd = $conteneur->getBdd();
50
		$this->Bdd = $conteneur->getBdd();
49
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
51
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
50
		$this->config = $conteneur->getParametre('Cartes');
52
		$this->config = $conteneur->getParametre('Cartes');
51
		$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
53
		$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
52
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
54
		$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
53
		$this->chargerMetadonneesDerniereVersion();
-
 
54
		$this->version = $this->metadonnees['version'];
-
 
55
		$this->tableChorodep = 'chorodep_v'.str_replace('.', '_', $this->version);
-
 
56
		$this->chargerOntologies();
-
 
57
		$this->chargerLegende();
-
 
58
		$this->chargerPrioritesLegende();
-
 
59
		$this->cheminCartesBase = $this->config['chemin'];
55
		$this->cheminCartesBase = $this->config['chemin'];
60
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
56
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
61
					'stockage_chemin' => $this->config['cache']['stockageChemin'],
57
					'stockage_chemin' => $this->config['cache']['stockageChemin'],
62
					'duree_de_vie' => $this->config['cache']['dureeDeVie']);
58
					'duree_de_vie' => $this->config['cache']['dureeDeVie']);
63
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
59
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
Line 80... Line 76...
80
			$this->parametres['retour'] = self::MIME_SVG;
76
			$this->parametres['retour'] = self::MIME_SVG;
81
		}
77
		}
82
		if (isset($this->parametres['retour.format']) == false) {
78
		if (isset($this->parametres['retour.format']) == false) {
83
			$this->parametres['retour.format'] = self::FORMAT_DEFAUT;
79
			$this->parametres['retour.format'] = self::FORMAT_DEFAUT;
84
		}
80
		}
-
 
81
		if (isset($this->parametres['version.projet']) == false) {
-
 
82
			$this->parametres['version.projet'] = self::VERSION_DEFAUT;
-
 
83
		}
85
	}
84
	}
Line 86... Line 85...
86
 
85
 
87
	private function verifierParametres() {
86
	private function verifierParametres() {
Line 96... Line 95...
96
		if (isset($this->parametres['retour.format']) == false) {
95
		if (isset($this->parametres['retour.format']) == false) {
97
			$erreurs[] = "Le paramètre de format de retour 'retour.format' est obligatoire.";
96
			$erreurs[] = "Le paramètre de format de retour 'retour.format' est obligatoire.";
98
		}
97
		}
99
		if ($this->verifierValeurParametreFormat() == false) {
98
		if ($this->verifierValeurParametreFormat() == false) {
100
			$erreurs[] = "Le type de format '{$this->parametres['retour.format']}' n'est pas supporté.".
99
			$erreurs[] = "Le type de format '{$this->parametres['retour.format']}' n'est pas supporté.".
101
					"Veuillez indiquer un nombre entier correspondant à la largeur désirée pour la carte.";
100
				"Veuillez indiquer un nombre entier correspondant à la largeur désirée pour la carte.";
-
 
101
		}
-
 
102
		if ($this->verifierValeurParametreVersionProjet() == false) {
-
 
103
			$erreurs[] = "Le format de version.projet '{$this->parametres['version.projet']}' n'est pas supporté.".
-
 
104
				"Veuillez indiquer le code '+' (=dernière version) ou une année sur 4 chiffres séparé d'un mois ".
-
 
105
				"sur deux chiffres par un point. Ex. : 2012.01";
102
		}
106
		}
Line 103... Line 107...
103
 
107
 
104
		if (count($erreurs) > 0) {
108
		if (count($erreurs) > 0) {
105
			$message = implode('<br />', $erreurs);
109
			$message = implode('<br />', $erreurs);
106
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
110
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
107
			throw new Exception($message, $code);
111
			throw new Exception($message, $code);
108
		}
112
		}
Line 109... Line 113...
109
	}
113
	}
110
 
114
 
111
	private function verifierValeurParametreRetour() {
115
	private function verifierValeurParametreRetour() {
Line 112... Line 116...
112
		return in_array($this->parametres['retour'], $this->formats_supportes);
116
		return in_array($this->parametres['retour'], $this->formatsSupportes);
113
	}
117
	}
114
 
118
 
Line 119... Line 123...
119
			$this->imgLargeur = $match[1];
123
			$this->imgLargeur = $match[1];
120
			$this->imgHauteur = $match[2];
124
			$this->imgHauteur = $match[2];
121
		}
125
		}
122
		return $ok;
126
		return $ok;
123
	}
127
	}
-
 
128
	private function verifierValeurParametreVersionProjet() {
-
 
129
		$ok = (preg_match('/^(?:[+]|[0-9]{4}\.[0-9]{2})$/', $this->parametres['version.projet']) == 0) ? false : true;
-
 
130
		return $ok;
-
 
131
	}
Line 124... Line 132...
124
 
132
 
125
	private function obtenirResultat() {
133
	private function obtenirResultat() {
-
 
134
		$this->analyserIdentifiants();
Line -... Line 135...
-
 
135
		$this->verifierIdentifiants();
-
 
136
 
-
 
137
		$this->chargerMetadonnees();
-
 
138
		$this->definirVersion();
-
 
139
		$this->tableChorodep = 'chorodep_v'.str_replace('.', '_', $this->version);
-
 
140
		$this->chargerOntologies();
126
		$this->analyserIdentifiants();
141
		$this->chargerLegende();
127
 
142
		$this->chargerPrioritesLegende();
128
		$this->chargerDonnees();
143
		$this->chargerDonnees();
Line 129... Line 144...
129
		$svg = $this->genererSVG();
144
		$svg = $this->genererSVG();
Line 145... Line 160...
145
			$projetsListeEtNumNoms = explode(';', $ids);
160
			$projetsListeEtNumNoms = explode(';', $ids);
146
			if (count($projetsListeEtNumNoms) > 0) {
161
			if (count($projetsListeEtNumNoms) > 0) {
147
				foreach ($projetsListeEtNumNoms as $projetEtNumNoms) {
162
				foreach ($projetsListeEtNumNoms as $projetEtNumNoms) {
148
					$projetEtNumNoms = (strpos($projetEtNumNoms, ':')) ? $projetEtNumNoms : self::CODE_REFTAX_DEFAUT.'.nn:'.$projetEtNumNoms;
163
					$projetEtNumNoms = (strpos($projetEtNumNoms, ':')) ? $projetEtNumNoms : self::CODE_REFTAX_DEFAUT.'.nn:'.$projetEtNumNoms;
149
					list($projetEtType, $numNoms) = explode(':', $projetEtNumNoms);
164
					list($projetEtType, $numNoms) = explode(':', $projetEtNumNoms);
-
 
165
 
-
 
166
					$projetEtType = (strpos($projetEtType, '.')) ? $projetEtType : self::CODE_REFTAX_DEFAUT.'.'.$projetEtType;
150
					list($projet, $type) = explode('.', $projetEtType);
167
					list($projet, $type) = explode('.', $projetEtType);
-
 
168
 
151
					$this->taxonsDemandes[$projet][$type] = explode(',', $numNoms);
169
					$this->taxonsDemandes[$projet][$type] = explode(',', $numNoms);
152
				}
170
				}
153
			}
171
			}
154
		}
172
		}
155
	}
173
	}
Line -... Line 174...
-
 
174
 
-
 
175
	private function verifierIdentifiants() {
-
 
176
		foreach (array_keys($this->taxonsDemandes) as $reftax) {
-
 
177
			$ok = in_array($reftax, $this->reftaxSupportes);
-
 
178
			if ($ok == false) {
-
 
179
				$message = "Le reférentiel taxonomique '$reftax' n'est pas pris en compte par ce projet.";
-
 
180
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
181
				throw new Exception($message, $code);
-
 
182
			}
-
 
183
		}
-
 
184
	}
156
 
185
 
157
	private function chargerMetadonneesDerniereVersion() {
186
	private function chargerMetadonnees() {
158
		$requete = 'SELECT * '.
187
		$requete = 'SELECT * '.
159
				"FROM {$this->tableMeta} ".
188
			"FROM {$this->tableMeta} ".
160
				"ORDER BY date_creation DESC ".
-
 
161
				"LIMIT 0,1 ";
189
			"ORDER BY date_creation DESC ";
Line 162... Line 190...
162
		$resultats = $this->Bdd->recuperer($requete);
190
		$resultats = $this->Bdd->recupererTous($requete);
163
 
191
 
164
		if (!is_array($resultats) || count($resultats) <= 0) {
192
		if (!is_array($resultats) || count($resultats) <= 0) {
165
			$message = "Les données de version n'a pu être chargée pour la ressource demandée";
193
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
166
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
194
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
Line 167... Line 195...
167
			throw new Exception($message, $code);
195
			throw new Exception($message, $code);
-
 
196
		}
Line -... Line 197...
-
 
197
 
-
 
198
		$this->metadonnees = $resultats;
-
 
199
	}
-
 
200
 
-
 
201
	private function definirVersion() {
-
 
202
		if ($this->parametres['version.projet'] == '+') {
168
		}
203
			$this->version = $this->metadonnees[0]['version'];
Line 169... Line 204...
169
 
204
		} else {
170
		$this->metadonnees = $resultats;
205
			$this->version = $this->parametres['version.projet'];
171
 
206
		}
172
	}
207
	}
Line 173... Line 208...
173
 
208
 
174
	private function chargerOntologies() {
209
	private function chargerOntologies() {
175
		$requete = 'SELECT * '.
210
		$requete = 'SELECT * '.
Line 338... Line 373...
338
		}
373
		}
339
	}
374
	}
Line 340... Line 375...
340
 
375
 
341
	private function getZonesCouleurs() {
376
	private function getZonesCouleurs() {
-
 
377
		$zones = array();
342
		$zones = array();
378
		ksort($this->zones);
343
		foreach ($this->zones as $zoneId => $codeLegende) {
379
		foreach ($this->zones as $zoneId => $codeLegende) {
344
			if (array_key_exists($codeLegende, $this->legende)) {
380
			if (array_key_exists($codeLegende, $this->legende)) {
345
				$couleur = $this->legende[$codeLegende];
381
				$couleur = $this->legende[$codeLegende];
346
				$zones[$couleur][] = strtolower(".departement$zoneId");
382
				$zones[$couleur][] = strtolower('.departement'.sprintf('%02s', $zoneId));
347
			}
383
			}
348
		}
384
		}
349
		return $zones;
385
		return $zones;