| Line 54... |
Line 54... |
| 54 |
// les champs de base de coste_v2_00
|
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" {} {}
|
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(
|
56 |
static $allow_champs = array(
|
| 57 |
'coste:nn' => 'c.num_nom',
|
57 |
'coste:nn' => 'c.num_nom',
|
| 58 |
'bdtfx:nn' => 'IF(c.flore_bdtfx_nn = "",NULL,c.flore_bdtfx_nn)',
|
58 |
'bdtfx:nn' => 'IF(c.flore_bdtfx_nn = "",NULL,c.flore_bdtfx_nn)',
|
| 59 |
'bdtfx:nt' => 'c.flore_bdtfx_nt',
|
59 |
'bdtfx:nt' => 'IF(c.flore_bdtfx_nt = "",NULL,c.flore_bdtfx_nt)',
|
| 60 |
'num_nom' => 'c.num_nom',
|
60 |
'num_nom' => 'c.num_nom',
|
| 61 |
'num_nom_retenu' => 'c.num_nom_retenu',
|
61 |
'num_nom_retenu' => 'c.num_nom_retenu',
|
| 62 |
'num_tax_sup' => 'c.num_tax_sup',
|
62 |
'num_tax_sup' => 'c.num_tax_sup',
|
| 63 |
'rang' => 'c.rang',
|
63 |
'rang' => 'c.rang',
|
| 64 |
'nom_sci' => 'c.nom_sci',
|
64 |
'nom_sci' => 'c.nom_sci',
|
| Line 107... |
Line 107... |
| 107 |
// les champs suivants disparaissent de la liste utilisée pour former la requête SQL
|
107 |
// les champs suivants disparaissent de la liste utilisée pour former la requête SQL
|
| 108 |
// (ils sont exclue lorsque '*' est utilisée, ce sont généralement des synonymes)
|
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');
|
109 |
static $special_champs = array('nom_sci_html', 'nom_sci', '*', 'flore_bdtfx_nn', 'flore_bdtfx_nt', 'num_nom');
|
| Line 110... |
Line 110... |
| 110 |
|
110 |
|
| 111 |
// ces champs sont toujours dans les résultats (cf sqlSelectFields()
|
111 |
// ces champs sont toujours dans les résultats (cf sqlSelectFields()
|
| Line 112... |
Line 112... |
| 112 |
static $champs_obligatoires = array('coste:nn', 'bdtfx:nn');
|
112 |
static $champs_obligatoires = array('coste:nn', 'bdtfx:nn', 'bdtfx:nt');
|
| 113 |
|
113 |
|
| Line 144... |
Line 144... |
| 144 |
$params['_ids'] = self::requestFilterIds($uri);
|
144 |
$params['_ids'] = self::requestFilterIds($uri);
|
| Line 145... |
Line 145... |
| 145 |
|
145 |
|
| 146 |
// XXX: temporaires, passage de $db aux fonctions
|
146 |
// XXX: temporaires, passage de $db aux fonctions
|
| 147 |
// de toolkits
|
147 |
// de toolkits
|
| 148 |
$req = self::getCosteInfo($params, $db);
|
- |
|
| 149 |
|
148 |
$req = self::getCosteInfo($params, $db);
|
| 150 |
$res = $db->recupererTous($req);
|
149 |
$res = $db->recupererTous($req);
|
| 151 |
$err = mysql_error();
|
150 |
$err = mysql_error();
|
| 152 |
if (!$res && $err) {
|
151 |
if (!$res && $err) {
|
| 153 |
// http_response_code(400);
|
152 |
// http_response_code(400);
|
| Line 181... |
Line 180... |
| 181 |
return array('entete' => array(
|
180 |
return array('entete' => array(
|
| 182 |
'depart' => $params['navigation.depart'],
|
181 |
'depart' => $params['navigation.depart'],
|
| 183 |
'limite' => $params['navigation.limite'],
|
182 |
'limite' => $params['navigation.limite'],
|
| 184 |
'total' => count($res2),
|
183 |
'total' => count($res2),
|
| 185 |
'match' => $matches),
|
184 |
'match' => $matches),
|
| 186 |
'resultats' => $res2);
|
185 |
'resultats' => $res2);
|
| 187 |
}
|
186 |
}
|
| Line 188... |
Line 187... |
| 188 |
|
187 |
|
| 189 |
|
188 |
|
| Line 198... |
Line 197... |
| 198 |
$champs_valides_non_formattes = NULL;
|
197 |
$champs_valides_non_formattes = NULL;
|
| 199 |
$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
|
198 |
$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
|
| Line 200... |
Line 199... |
| 200 |
|
199 |
|
| 201 |
// joins:
|
200 |
// joins:
|
| 202 |
$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
|
201 |
$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
|
| 203 |
$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS %s".
|
202 |
$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS %s ".
|
| 204 |
"FROM tb_eflore.coste_v2_00 c ".
|
203 |
"FROM tb_eflore.coste_v2_00 c ".
|
| 205 |
" LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
|
204 |
" LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
|
| 206 |
" LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
|
205 |
" LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
|
| 207 |
" %s ".
|
206 |
" %s ".
|
| Line 281... |
Line 280... |
| 281 |
|
280 |
|
| 282 |
// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
|
281 |
// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
|
| 283 |
// comportant un #id existe, cf self::requestFilterIds()
|
282 |
// comportant un #id existe, cf self::requestFilterIds()
|
| 284 |
$o_stack = array();
|
283 |
$o_stack = array();
|
| 285 |
if (array_key_exists('_ids', $params) && $params['_ids']) {
|
284 |
if (array_key_exists('_ids', $params) && $params['_ids']) {
|
| 286 |
if ($params['_ids']['coste']) {
|
285 |
if ($params['_ids']['coste.nn']) {
|
| - |
|
286 |
$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste.nn']));
|
| - |
|
287 |
}
|
| - |
|
288 |
if ($params['_ids']['bdtfx.nn']) {
|
| 287 |
$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste']));
|
289 |
$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx.nn']));
|
| 288 |
}
|
290 |
}
|
| 289 |
if ($params['_ids']['bdtfx']) {
|
291 |
if ($params['_ids']['bdtfx.nt']) {
|
| 290 |
$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx']));
|
292 |
$o_stack[] = sprintf("c.flore_bdtfx_nt IN (%s)", implode(',', $params['_ids']['bdtfx.nt']));
|
| 291 |
}
|
293 |
}
|
| 292 |
}
|
294 |
}
|
| 293 |
if ($o_stack) {
|
295 |
if ($o_stack) {
|
| 294 |
$stack[] = '(' . implode(' OR ', $o_stack) . ')';
|
296 |
$stack[] = '(' . implode(' OR ', $o_stack) . ')';
|
| Line 360... |
Line 362... |
| 360 |
}
|
362 |
}
|
| Line 361... |
Line 363... |
| 361 |
|
363 |
|
| 362 |
// request handler
|
364 |
// request handler
|
| 363 |
static function requestParse(&$ressource, &$params) {
|
365 |
static function requestParse(&$ressource, &$params) {
|
| 364 |
if (isset($_SERVER['REDIRECT_URL'])) {
|
366 |
if (isset($_SERVER['REDIRECT_URL'])) {
|
| 365 |
$uri = explode('/', $_SERVER['REDIRECT_URL']);
|
367 |
$uri = explode('/', $_SERVER['REDIRECT_URL']);
|
| 366 |
} else {
|
368 |
} else {
|
| 367 |
$uri = explode('/', $_SERVER['REQUEST_URI']);
|
369 |
$uri = explode('/', $_SERVER['REQUEST_URI']);
|
| 368 |
}
|
370 |
}
|
| 369 |
if(!empty($_SERVER['QUERY_STRING']))
|
371 |
if (!empty($_SERVER['QUERY_STRING'])) {
|
| - |
|
372 |
parse_str($_SERVER['QUERY_STRING'], $params);
|
| 370 |
parse_str($_SERVER['QUERY_STRING'], $params);
|
373 |
}
|
| 371 |
$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
|
374 |
$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
|
| Line 372... |
Line 375... |
| 372 |
}
|
375 |
}
|
| 373 |
|
376 |
|
| Line 441... |
Line 444... |
| 441 |
|
444 |
|
| 442 |
// getNN* renvoient le num_nom passé comme segment d'URI:
|
445 |
// getNN* renvoient le num_nom passé comme segment d'URI:
|
| 443 |
// - soit un id selon coste (num_nom dans coste_v2_00)
|
446 |
// - soit un id selon coste (num_nom dans coste_v2_00)
|
| 444 |
// - soit un id selon bdtfx (num_nom dans bdtfx_v2_00)
|
447 |
// - soit un id selon bdtfx (num_nom dans bdtfx_v2_00)
|
| 445 |
// ou bien l'extrait du pattern bdtfx.nn:(#id)
|
448 |
// ou bien l'extrait du pattern bdtfx.nn:(#id)
|
| 446 |
$ids_coste = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
|
449 |
$ids_coste_nn = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
|
| - |
|
450 |
$ids_bdtfx_nn = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
|
| Line 447... |
Line 451... |
| 447 |
$ids_bdtfx = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
|
451 |
$ids_bdtfx_nt = array_filter(array_map(array(__CLASS__, 'getNTBdtfx'), explode(',', $uri[0])));
|
| 448 |
|
452 |
|
| 449 |
// en cas d'échec (tous les id sont invalides), bail-out
|
453 |
// en cas d'échec (tous les id sont invalides), bail-out
|
| 450 |
if(!$ids_bdtfx && !$ids_coste) {
|
454 |
if(!$ids_bdtfx_nt && !$ids_bdtfx_nn && !$ids_coste_nn) {
|
| 451 |
// http_response_code(500);
|
455 |
// http_response_code(500);
|
| Line 452... |
Line 456... |
| 452 |
throw new Exception('not supported', 500);
|
456 |
throw new Exception('not supported', 500);
|
| 453 |
}
|
457 |
}
|
| - |
|
458 |
|
| 454 |
|
459 |
return array(
|
| 455 |
return array(
|
460 |
'coste.nn' => array_slice($ids_coste_nn, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
|
| 456 |
'coste' => array_slice($ids_coste, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
|
461 |
'bdtfx.nn' => array_slice($ids_bdtfx_nn, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
|
| Line 457... |
Line 462... |
| 457 |
'bdtfx' => array_slice($ids_bdtfx, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
|
462 |
'bdtfx.nt' => array_slice($ids_bdtfx_nt, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
|
| 458 |
);
|
463 |
);
|
| Line 510... |
Line 515... |
| 510 |
if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
|
515 |
if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
|
| 511 |
$t = intval(str_replace('bdtfx.nn:', '', $refnn));
|
516 |
$t = intval(str_replace('bdtfx.nn:', '', $refnn));
|
| 512 |
if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
|
517 |
if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
|
| 513 |
return FALSE;
|
518 |
return FALSE;
|
| 514 |
}
|
519 |
}
|
| - |
|
520 |
|
| - |
|
521 |
static function getNTBdtfx($refnt) {
|
| - |
|
522 |
if(strpos($refnt, 'bdtfx.nt:') !== 0) return FALSE;
|
| - |
|
523 |
$t = intval(str_replace('bdtfx.nt:', '', $refnt));
|
| - |
|
524 |
if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NT) return $t;
|
| - |
|
525 |
return FALSE;
|
| - |
|
526 |
}
|
| 515 |
}
|
527 |
}
|