Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
854 raphael 1
<?php
2
/*
3
 * @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
4
 * @author Raphaël Droz <raphael@tela-botanica.org>
5
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
6
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
7
 *
859 raphael 8
 * pattern: /service:eflore:0.1/coste/textes/bdtfx.nn:182,631
854 raphael 9
 * params: txt.format=(htm|txt) ,  retour.champs=(titre,texte,...) , retour.format=(min|max), ...
10
 *
11
 * Ce webservice est censé pouvoir:
859 raphael 12
 * 1) retourner des informations (choisies) à propos d'un ou plusieurs taxon(s) donné(s)
13
 *	  (à partir de son numéro nomenclatural
14
 * 2) retourner des informations (choisies) à propos de taxons recherchés
15
 *	  (à partir de divers critères)
854 raphael 16
 *
17
 * TODO: masque.titre => masque.tag
859 raphael 18
 * TODO: clarifier l'attribut "tag" retourné (tag de la description ou des clefs de détermination)
854 raphael 19
 *
20
 */
21
 
858 raphael 22
// affecte le nombre d'ids autorisés dans le dernier segment d'URL
23
// *et* la valeur maximale autorisée pour navigation.limite.
24
define('_COSTE_TEXTE_MAX_RESULT_LIMIT', 500);
25
 
859 raphael 26
// simplifie et accélère la sanitization de l'input:
27
// SELECT MAX(num_nom) FROM coste_v2_00;
861 raphael 28
define('_COSTE_TEXTE_MAX_COSTE_NN', 7015 + 1000);
862 raphael 29
// SELECT MAX(page) FROM coste_v2_00;
30
define('_COSTE_TEXTE_MAX_COSTE_PAGE', 4126);
31
// SELECT MAX(tome) FROM coste_v2_00;
32
define('_COSTE_TEXTE_MAX_COSTE_TOME', 3);
33
// SELECT MAX(num_taxonomique) FROM coste_v2_00;
34
define('_COSTE_TEXTE_MAX_BDTFX_NT', 37809);
861 raphael 35
// SELECT MAX(num_nom) FROM bdtfx_v1_02;
36
define('_COSTE_TEXTE_MAX_BDTFX_NN', 103386 + 10000);
859 raphael 37
 
863 raphael 38
/* restore_error_handler();
39
   error_reporting(E_ALL); */
856 raphael 40
class Textes {
854 raphael 41
	// paramètres autorisés
42
	static $allow_params = array(
863 raphael 43
		'txt.format', 'retour.format', 'retour.champs', 'retour.indexBy',
854 raphael 44
		'recherche',
862 raphael 45
		'masque.ns', 'masque.txt', 'masque.page', 'masque.tome', 'masque.famille', 'masque.nt',
854 raphael 46
		'masque.titre', // masque sur titre de la page wiki correspondante (page "clef" OR page "description")
47
		'navigation.depart', 'navigation.limite');
48
	// et valeurs par défaut
863 raphael 49
	static $default_params = array('txt.format' => 'txt', 'retour.format' => 'max', 'retour.indexBy' => 'coste',
50
								   'recherche' => 'stricte',
854 raphael 51
								   'retour.champs' => 'titre,texte,determination,tag',
52
								   'navigation.depart' => 0, 'navigation.limite' => 50);
53
 
54
	// les champs de base de coste_v2_00
55
	// mysql -N tb_eflore<<<"SHOW FIELDS FROM coste_v2_00"|egrep -v 'page_'|awk '{print $1}'|xargs -i -n1 printf "'%s' => 'c.%s',\n" {} {}
56
	static $allow_champs = array(
861 raphael 57
		'coste:nn' => 'c.num_nom',
58
		'bdtfx:nn' => 'IF(c.flore_bdtfx_nn = "",NULL,c.flore_bdtfx_nn)',
59
		'bdtfx:nt' => 'c.flore_bdtfx_nt',
854 raphael 60
		'num_nom' => 'c.num_nom',
61
		'num_nom_retenu' => 'c.num_nom_retenu',
62
		'num_tax_sup' => 'c.num_tax_sup',
63
		'rang' => 'c.rang',
64
		'nom_sci' => 'c.nom_sci',
65
		'nom_supra_generique' => 'c.nom_supra_generique',
66
		'genre' => 'c.genre',
67
		'epithete_infra_generique' => 'c.epithete_infra_generique',
68
		'epithete_sp' => 'c.epithete_sp',
69
		'type_epithete' => 'c.type_epithete',
70
		'epithete_infra_sp' => 'c.epithete_infra_sp',
71
		'cultivar_groupe' => 'c.cultivar_groupe',
72
		'cultivar' => 'c.cultivar',
73
		'nom_commercial' => 'c.nom_commercial',
74
		'auteur' => 'c.auteur',
75
		'annee' => 'c.annee',
76
		'biblio_origine' => 'c.biblio_origine',
77
		'notes' => 'c.notes',
78
		'nom_addendum' => 'c.nom_addendum',
79
		'nom_francais' => 'c.nom_francais',
80
		'nom_coste' => 'c.nom_coste',
81
		'auteur_coste' => 'c.auteur_coste',
82
		'biblio_coste' => 'c.biblio_coste',
83
		'num_nom_coste' => 'c.num_nom_coste',
84
		'num_nom_retenu_coste' => 'c.num_nom_retenu_coste',
85
		'num_tax_sup_coste' => 'c.num_tax_sup_coste',
86
		'synonymie_coste' => 'c.synonymie_coste',
87
		'tome' => 'c.tome',
88
		'page' => 'c.page',
89
		'nbre_taxons' => 'c.nbre_taxons',
90
		'flore_bdtfx_nn' => 'c.flore_bdtfx_nn',
91
		'flore_bdtfx_nt' => 'c.flore_bdtfx_nt',
92
		'image' => 'c.image',
93
		'image_auteur' => 'c.image_auteur',
94
		'nom_sci_html' => 'c.nom_sci_html',
95
 
96
		// handly duplicate (redirigé vers nom_sci ou nom_sci_html selon que txt.format vaut "txt" ou "htm"
97
		'titre' => 'c.nom_sci',
98
 
99
		// champs spécifiques (et étrangères)
100
		'texte' => 'dsc.body',
101
		'determination' => 'cle.body',
102
		'tag' => 'dsc.tag',
103
		'famille' => 'b.famille', // cf sqlAddJoins()
104
		'*' => 'XXX' // spécial
105
	);
106
 
107
	// les champs suivants disparaissent de la liste utilisée pour former la requête SQL
861 raphael 108
	// (ils sont exclue lorsque '*' est utilisée, ce sont généralement des synonymes)
109
	static $special_champs = array('nom_sci_html', 'nom_sci', '*', 'flore_bdtfx_nn', 'flore_bdtfx_nt', 'num_nom');
110
 
111
	// ces champs sont toujours dans les résultats (cf sqlSelectFields()
112
	static $champs_obligatoires = array('coste:nn', 'bdtfx:nn');
113
 
114
 
854 raphael 115
	// le pattern utilisé pour la recherche dite "floue"
116
	static $soundex_scheme = '(%1$s LIKE %2$s OR SOUNDEX(%1$s) = SOUNDEX(%2$s) OR SOUNDEX(REVERSE(%1$s)) = SOUNDEX(REVERSE(%2$s)))';
117
 
118
	// contrainte du point d'entrée d'API webservice Tela lors d'un GET
119
	public function consulter($ressources, $parametres, $db = NULL) {
918 jpm 120
		if (!$db) {
854 raphael 121
			// http_response_code(500);
122
			throw new Exception('no DB', 500);
123
		}
124
 
125
		// parser la requête et filtrer les paramètres valides
126
		// en cas d'accès HTTP
918 jpm 127
		if (array_key_exists('QUERY_STRING', $_SERVER)) {
854 raphael 128
			self::requestParse($uri, $params);
918 jpm 129
		} else {// en cas d'accès phpunit
854 raphael 130
			$uri = $ressources;
131
		}
132
 
133
		// renvoie du plain/text d'aide (cf fin de programme)
918 jpm 134
		if (count($uri) == 1 && $uri[0] == 'aide') {
135
			return self::aide();
136
		}
854 raphael 137
 
138
 
918 jpm 139
		if (is_null($parametres)) {
140
			$parametres = Array();
141
		}
858 raphael 142
		$params = self::requestFilterParams($parametres);
143
		// les contraintes liées aux ids (passés comme composants d'URL)
144
		// sont ajoutées aux params [sans être accepté comme paramètre d'URL]
145
		$params['_ids'] = self::requestFilterIds($uri);
854 raphael 146
 
858 raphael 147
		// XXX: temporaires, passage de $db aux fonctions
148
		// de toolkits
149
		$req = self::getCosteInfo($params, $db);
150
 
854 raphael 151
		$res = $db->recupererTous($req);
152
		$err = mysql_error();
918 jpm 153
		if (!$res && $err) {
854 raphael 154
			// http_response_code(400);
155
			// if(defined('DEBUG') && DEBUG) header("X-Debug: $req");
156
			throw new Exception('not found', 400);
157
		}
158
 
159
		// rapide formatage des résultats:
160
		$matches = 0;
161
 
918 jpm 162
		if ($res) {
854 raphael 163
			// nombre de matches (sans LIMIT) utilisé pour l'en-tête
164
			$matches = $db->recuperer('SELECT FOUND_ROWS() AS total');
165
			$matches = intval($matches['total']);
166
		}
167
 
863 raphael 168
		// reformate les résultats pour les indexer par coste:nn par défaut
169
		// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
170
		$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
854 raphael 171
		$res2 = array();
918 jpm 172
		foreach ($res as $v) {
173
			if (!$v[$clef_index]) {
174
				throw new Exception('format error: index NULL, use retour.indexBy=coste', 409);
175
			}
863 raphael 176
			$res2[$v[$clef_index]] = $v;
854 raphael 177
		}
178
 
179
		// l'appelant s'occupera du json_encode()
180
		// même si ça démange d'exit'er ici
181
		header("Content-Type: application/json; charset=utf-8");
918 jpm 182
		return array('entete' => array(
183
			'depart' => $params['navigation.depart'],
184
			'limite' => $params['navigation.limite'],
185
			'total' => count($res2),
186
			'match' => $matches),
187
			'resultats' => $res2);
854 raphael 188
 
189
	}
190
 
191
 
861 raphael 192
	// la fonction centrale: récupère les infos à partir de paramètres
193
	// et une optionnelle contrainte sur coste:nn ou bdtfx:nn
858 raphael 194
	static function getCosteInfo(array $params, $db) {
854 raphael 195
		// contraintes (WHERE):
858 raphael 196
		$constraints = self::sqlAddConstraint($params, $db);
197
		// XXX: que faire en l'absence de contrainte ? pour l'instant : "WHERE 1"
854 raphael 198
 
199
		// champs:
200
		$champs_valides_non_formattes = NULL;
201
		$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
202
 
203
		// joins:
204
		$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
918 jpm 205
		$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS  %s".
206
			"FROM tb_eflore.coste_v2_00 c ".
207
			"	LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
208
			"	LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
209
			" %s ".
210
			"WHERE %s ORDER BY c.num_nom LIMIT %u, %u -- %s ";
211
		$req = sprintf($requete_tpl,
212
			$champs_valides, // dans le SELECT (parmi champs coste_v2_00)
213
			// autre join, si nécessaire
214
			$other_join ? $other_join : '',
854 raphael 215
 
918 jpm 216
			// where
217
			$constraints ? implode(' AND ', $constraints) : '1',
218
 
219
			// limit
220
			$params['navigation.depart'],
221
			$params['navigation.limite'],
222
			__FILE__ . ':' . __LINE__);
223
 
854 raphael 224
		return $req;
225
	}
226
 
227
	// SQL helpers
228
	// le préfix de coste_v2_00 est "c"
229
	// le préfix de florecoste_pages sur la description est est "dsc"
230
	// le préfix de florecoste_pages sur la clef de détermination est est "cle"
858 raphael 231
	static function sqlAddConstraint($params, $db) {
854 raphael 232
		$stack = array();
918 jpm 233
		if (!empty($params['masque.ns'])) {
234
			if ($params['recherche'] == 'etendue') {
235
				$stack[] = 'c.nom_sci LIKE '.$db->proteger('%' . trim($params['masque.ns']).'%');
236
			} elseif($params['recherche'] == 'floue') {
854 raphael 237
				$stack[] = sprintf(self::$soundex_scheme,
918 jpm 238
					'c.nom_sci',
239
					$db->proteger('%'.trim($params['masque.ns']).'%'));
240
			} else {
241
				$stack[] = 'c.nom_sci = '.$db->proteger(trim($params['masque.ns']));
242
			}
854 raphael 243
		}
244
 
245
		// le masque sur texte est toujours un LIKE() "étendue", sauf si "floue" spécifié
246
		if(!empty($params['masque.txt'])) {
247
			if($params['recherche'] == 'floue') {
248
				$stack[] = sprintf(self::$soundex_scheme,
918 jpm 249
					'dsc.body',
250
					$db->proteger('%'.trim($params['masque.txt']).'%'));
854 raphael 251
			}
252
			else {
918 jpm 253
				$stack[] = 'dsc.body LIKE '.$db->proteger('%'.trim($params['masque.txt']).'%');
854 raphael 254
			}
255
		}
256
 
257
		if(!empty($params['masque.titre'])) {
258
			if($params['recherche'] == 'stricte') {
259
				$stack[] = sprintf('(dsc.tag = %1$s OR cle.tag = %1$s)',
918 jpm 260
					$db->proteger(trim($params['masque.titre'])));
854 raphael 261
			}
262
			else {
263
				$stack[] = sprintf('(dsc.tag LIKE %1$s OR cle.tag LIKE %1$s)',
918 jpm 264
					$db->proteger('%'.trim($params['masque.titre']).'%'));
854 raphael 265
			}
266
		}
267
 
268
		if(array_key_exists('masque.famille', $params)) {
918 jpm 269
			$stack[] = 'b.famille LIKE '.$db->proteger(trim($params['masque.famille']));
854 raphael 270
		}
271
 
272
		if(array_key_exists('masque.page', $params)) {
918 jpm 273
			$stack[] = 'c.page = '.intval($params['masque.page']);
854 raphael 274
		}
275
 
276
		if(array_key_exists('masque.tome', $params)) {
918 jpm 277
			$stack[] = 'c.tome = '.intval($params['masque.tome']);
854 raphael 278
		}
279
 
862 raphael 280
		if(array_key_exists('masque.nt', $params)) {
918 jpm 281
			$stack[] = 'c.flore_bdtfx_nt = '.intval($params['masque.nt']);
862 raphael 282
		}
283
 
861 raphael 284
		// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
858 raphael 285
		// comportant un #id existe, cf self::requestFilterIds()
861 raphael 286
		$o_stack = array();
918 jpm 287
		if (array_key_exists('_ids', $params) && $params['_ids']) {
288
			if ($params['_ids']['coste']) {
861 raphael 289
				$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste']));
290
			}
918 jpm 291
			if ($params['_ids']['bdtfx']) {
861 raphael 292
				$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx']));
293
			}
858 raphael 294
		}
918 jpm 295
		if ($o_stack) {
296
			$stack[] = '(' . implode(' OR ', $o_stack) . ')';
297
		}
858 raphael 298
 
854 raphael 299
		return $stack;
300
	}
301
 
302
 
303
	// $unmerged contient la même liste de champs que celle renvoyée
304
	// à la différence que celle-ci n'est pas reformatée et s'avère donc
305
	// utilisable plus aisément dans sqlAddJoins() qui peut en avoir besoin
306
	static function sqlSelectFields($params, &$unmerged) {
307
		$champs = $params['retour.champs'];
308
		// champs coste_v2_00
861 raphael 309
		$c = self::addSQLToFieldSynonym(explode(',', $champs));
918 jpm 310
		if (isset($c['*'])) {
854 raphael 311
			$t = array_diff_key(self::$allow_champs, array_flip(self::$special_champs));
918 jpm 312
		} else {
854 raphael 313
			// just loop below
314
			$t = $c;
315
		}
316
 
317
		// si aucun des champs fournis n'est valide
318
		// on se rappelle nous-même après avoir réinitialisé retour.champs
319
		// avec les champs par défaut
320
		if(!$t) {
321
			$params['retour.champs'] = self::$default_params['retour.champs'];
322
			return self::sqlSelectFields($params);
323
		}
324
 
325
		if(array_key_exists('titre', $t))
326
			$t['titre'] = $params['txt.format'] == 'txt' ? 'c.nom_sci' : 'c.nom_sci_html';
327
 
861 raphael 328
		// champs obligatoires:
329
		$t = array_merge($t, self::addSQLToFieldSynonym(self::$champs_obligatoires));
854 raphael 330
		$unmerged = $t;
331
 
332
		// XXX: PHP-5.3
333
		$ret = array();
334
		foreach($t as $k => $v) {
918 jpm 335
			if (strpos($k, ':') !== FALSE) {
861 raphael 336
				$ret[] = "$v AS \"$k\"";
337
			} else {
338
				$ret[] = "$v AS $k";
339
			}
854 raphael 340
		}
341
		return implode(',',$ret);
342
	}
343
 
344
	static function sqlAddJoins($params, $champs) {
345
		$j = '';
346
		// ces tests doivent correspondre aux champs générés par sqlSelectFields()
347
		// ou contraintes générées par sqlAddConstraint()
348
		if(array_key_exists('masque.famille', $params) ||
349
		   array_key_exists('famille', $champs)) {
861 raphael 350
			$j .= 'LEFT JOIN tb_eflore.bdtfx_v1_02 b ON c.flore_bdtfx_nn = b.num_nom';
854 raphael 351
		}
352
 
353
		return $j;
354
	}
355
 
861 raphael 356
	// d'un tableau de type array("coste:nn", "type_epithete")
357
	// retourne
358
	// un tableau de type array("coste:nn" => "c.num_nom", "type_epithete" => "c.type_epithete")
359
	// basé sur self::$allow_champs
360
	static function addSQLToFieldSynonym(Array $syno) {
361
		return array_intersect_key(self::$allow_champs, array_flip($syno));
362
	}
363
 
854 raphael 364
	// request handler
365
	static function requestParse(&$ressource, &$params) {
366
		$uri = explode('/', $_SERVER['REDIRECT_URL']);
367
		if(!empty($_SERVER['QUERY_STRING']))
368
			parse_str($_SERVER['REDIRECT_QUERY_STRING'], $params);
856 raphael 369
		$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
854 raphael 370
	}
371
 
372
	// supprime l'index du tableau des paramètres si sa valeur ne correspond pas
373
	// au spectre passé par $values.
374
	static function unsetIfInvalid(&$var, $index, $values) {
375
		if(array_key_exists($index, $var) && !in_array($var[$index], $values))
376
			unset($var[$index]);
377
	}
378
 
379
	static function requestFilterParams(Array $params) {
380
		$p = array_intersect_key($params, array_flip(self::$allow_params));
381
		self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
382
		self::unsetIfInvalid($p, 'retour.format', array('min','max'));
863 raphael 383
		self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
854 raphael 384
		self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
385
 
386
		if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);
387
		if(isset($params['masque.texte'])) $p['masque.texte'] = trim($params['masque.texte']);
388
 
389
		if(isset($params['masque.famille'])) {
390
			// mysql -N<<<"SELECT DISTINCT famille FROM bdtfx_v1_02;"|sed -r "s/(.)/\1\n/g"|sort -u|tr -d "\n"
391
			$p['masque.famille'] = preg_replace('/[^a-zA-Z %_]/', '', iconv("UTF-8",
392
																			"ASCII//TRANSLIT",
393
																			$params['masque.famille']));
394
		}
395
 
396
		// TODO: use filter_input(INPUT_GET);
397
		// renvoie FALSE ou NULL si absent ou invalide
398
		$p['navigation.limite'] = filter_var(@$params['navigation.limite'],
918 jpm 399
			FILTER_VALIDATE_INT,
400
			array('options' => array(
401
				'default' => NULL,
402
				'min_range' => 1,
403
				'max_range' => _COSTE_TEXTE_MAX_RESULT_LIMIT)));
854 raphael 404
		$p['navigation.depart'] = filter_var(@$params['navigation.depart'],
918 jpm 405
			FILTER_VALIDATE_INT,
406
			array('options' => array(
407
				'default' => NULL,
408
				'min_range' => 0,
409
				'max_range' => _COSTE_TEXTE_MAX_COSTE_NN)));
862 raphael 410
		$p['masque.page'] = filter_var(@$params['masque.page'],
918 jpm 411
			FILTER_VALIDATE_INT,
412
			array('options' => array(
413
				'default' => NULL,
414
				'min_range' => 0,
415
				'max_range' => _COSTE_TEXTE_MAX_COSTE_PAGE)));
862 raphael 416
		$p['masque.tome'] = filter_var(@$params['masque.tome'],
918 jpm 417
			FILTER_VALIDATE_INT,
418
			array('options' => array(
419
				'default' => NULL,
420
				'min_range' => 0,
421
				'max_range' => _COSTE_TEXTE_MAX_COSTE_TOME)));
862 raphael 422
		$p['masque.nt'] = filter_var(@$params['masque.nt'],
918 jpm 423
			FILTER_VALIDATE_INT,
424
			array('options' => array(
425
				'default' => NULL,
426
				'min_range' => 0,
427
				'max_range' => _COSTE_TEXTE_MAX_BDTFX_NT)));
854 raphael 428
 
429
		// on filtre les NULL, FALSE et '', mais pas les 0, d'où le callback()
430
		// TODO: PHP-5.3
431
		$p = array_filter($p, create_function('$a','return !in_array($a, array("",false,null),true);'));
432
		$p = array_merge(self::$default_params, $p);
433
 
434
		return $p;
435
	}
436
 
858 raphael 437
	static function requestFilterIds($uri) {
438
		if(count($uri) != 1) return NULL;
439
 
861 raphael 440
		// getNN* renvoient le num_nom passé comme segment d'URI:
441
		// - soit un id selon coste (num_nom dans coste_v2_00)
442
		// - soit un id selon bdtfx (num_nom dans bdtfx_v1_02)
858 raphael 443
		// ou bien l'extrait du pattern bdtfx.nn:(#id)
861 raphael 444
		$ids_coste = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
445
		$ids_bdtfx = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
858 raphael 446
 
447
		// en cas d'échec (tous les id sont invalides), bail-out
861 raphael 448
		if(!$ids_bdtfx && !$ids_coste) {
858 raphael 449
			// http_response_code(500);
450
			throw new Exception('not supported', 500);
451
		}
452
 
861 raphael 453
		return array(
918 jpm 454
			'coste' => array_slice($ids_coste, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
455
			'bdtfx' => array_slice($ids_bdtfx, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
861 raphael 456
		);
858 raphael 457
	}
458
 
854 raphael 459
	static function aide() {
460
		header("Content-Type: text/plain; charset=utf-8");
461
		return sprintf("
462
Service coste/textes:
463
Retourne des informations (choisies) à propos d'un taxon donné (à partir de son numéro nomenclatural
464
Retourne des informations (choisies) à propos de taxons recherchés (à partir de divers critères)
861 raphael 465
Les résultats sont indexés. La clef par défaut est le num_nom d'après coste (attribut \"coste:nn\")
854 raphael 466
Usage:
858 raphael 467
			coste/textes/<liste-num_nom>?<params>
861 raphael 468
* <liste-num_nom> étant une liste de numéros nomenclaturaux de taxons séparés par des virgules au format:
469
 - <#id>: un numéro nomenclatural dans la base coste
470
 - <bdtfx.nn:#id>: un numéro nomenclatural dans la base bdtfx
854 raphael 471
* retour.champs une liste de champs séparés par des virgules parmi *,%s
472
* les paramètres acceptés sont les suivants: %s
473
* les champs retournés par défaut sont les suivants: %s
474
* le paramètre \"recherche\" affecte les masques \"ns\" et \"texte\"
475
* le paramètre \"famille\" est traité via LIKE et accepte les caractères '_' et '%'
476
* le paramètre \"retour.format\" est inutilisé pour l'instant",
918 jpm 477
			implode(',', array_keys(self::$allow_champs)),
478
			implode(',', self::$allow_params),
479
			self::$default_params['retour.champs']
854 raphael 480
		);
481
	}
482
 
861 raphael 483
	static function getNNCoste($refnn) {
918 jpm 484
		if (is_numeric($refnn)) {
859 raphael 485
			$t = intval($refnn);
918 jpm 486
			if ($t >= 1 && $t < _COSTE_TEXTE_MAX_COSTE_NN) return $t;
859 raphael 487
		}
861 raphael 488
		return FALSE;
489
	}
490
 
491
	static function getNNBdtfx($refnn) {
854 raphael 492
		if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
861 raphael 493
		$t = intval(str_replace('bdtfx.nn:', '', $refnn));
494
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
495
		return FALSE;
854 raphael 496
	}
497
}