Line 187... |
Line 187... |
187 |
public function assemblerLaRequete() {
|
187 |
public function assemblerLaRequete() {
|
188 |
$requete = ' SELECT '.$this->formerRequeteChamp().
|
188 |
$requete = ' SELECT '.$this->formerRequeteChamp().
|
189 |
' FROM '.$this->table
|
189 |
' FROM '.$this->table
|
190 |
.$this->formerRequeteCondition()
|
190 |
.$this->formerRequeteCondition()
|
191 |
.$this->formerRequeteLimite();
|
191 |
.$this->formerRequeteLimite();
|
192 |
|
- |
|
193 |
return $requete;
|
192 |
return $requete;
|
194 |
}
|
193 |
}
|
Line 195... |
Line 194... |
195 |
|
194 |
|
196 |
public function formerRequeteChamp() {
|
195 |
public function formerRequeteChamp() {
|
Line 333... |
Line 332... |
333 |
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
|
332 |
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
|
334 |
}
|
333 |
}
|
335 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
334 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
336 |
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
|
335 |
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
|
337 |
}
|
336 |
}
|
338 |
|
337 |
|
339 |
foreach ($resultat as $tab) {
|
338 |
foreach ($resultat as &$tab) {
|
340 |
$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
|
339 |
$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
|
341 |
$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
|
340 |
$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
|
342 |
$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
|
341 |
$resultat_json[$tab['num_nom_vernaculaire']]['code_langue'] = $tab['code_langue'];
|
343 |
$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
|
342 |
$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
|
344 |
if ($this->retour_format == 'max') {
|
343 |
if ($this->retour_format == 'max') {
|
345 |
$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
|
344 |
$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
|
346 |
$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
|
345 |
$resultat_json[$tab['num_nom_vernaculaire']]['nom_retenu.code'] = $tab['num_taxon'];
|
347 |
$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
|
346 |
$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins
|
348 |
$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
|
347 |
$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
|
- |
|
348 |
$resultat_json[$tab['num_nom_vernaculaire']] = $this->ajouterChampsOntologieLigneResultat($tab);
|
349 |
}
|
349 |
}
|
- |
|
350 |
}
|
350 |
|
351 |
|
351 |
if($this->retour_format == 'max') {
|
352 |
if ($this->retour_format == 'max') {
|
352 |
//TODO: la fonction afficherTaxonsAttributions itere sur tout le tableau de résultats alors qu'elle ne devrait
|
353 |
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
|
353 |
// traiter qu'une ligne à la fois (i.e.: la ligne en cours dans $tab), ce qui serait bien plus rapide
|
354 |
// fois et les attribuer aux noms car c'est beaucoup plus rapide
|
354 |
$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
|
355 |
$noms_sci = $this->recupererNomTaxons();
|
- |
|
356 |
foreach ($resultat_json as &$tab) {
|
355 |
$resultat_json[$tab['num_nom_vernaculaire']] = $this->afficherChampsSupplementairesOntologie($tab);
|
357 |
$tab = $this->ajouterTaxonsAttributionsLigneResultat(&$resultat_json[$tab['num_nom_vernaculaire']], &$noms_sci);
|
356 |
}
|
358 |
}
|
357 |
}
|
359 |
}
|
- |
|
360 |
|
358 |
uasort($resultat_json, array($this,'trierLigneTableau'));
|
361 |
uasort($resultat_json, array($this,'trierLigneTableau'));
|
359 |
$table_retour_json['resultat'] = $resultat_json;
|
362 |
$table_retour_json['resultat'] = $resultat_json;
|
360 |
return $table_retour_json;
|
363 |
return $table_retour_json;
|
361 |
}
|
364 |
}
|
Line 362... |
Line 365... |
362 |
|
365 |
|
- |
|
366 |
public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
|
- |
|
367 |
|
363 |
public function afficherChampsSupplementairesOntologie($ligne_resultat) {
|
368 |
$intitule = '';
|
364 |
foreach($this->champ_infos as $cle => $champs_supplementaires) {
|
369 |
foreach($this->champ_infos as $cle => $champs_supplementaires) {
|
365 |
extract($champs_supplementaires);
|
370 |
extract($champs_supplementaires);
|
366 |
$valeur_recherche = '';
|
371 |
$valeur_recherche = '';
|
367 |
switch($cle) {
|
372 |
switch($cle) {
|
368 |
case 'taxon':
|
373 |
case 'taxon':
|
- |
|
374 |
$valeur_recherche = $ligne_resultat['num_taxon'];
|
369 |
$valeur_recherche = $ligne_resultat['num_taxon'];
|
375 |
$intitule = 'taxon.code';
|
370 |
break;
|
376 |
break;
|
371 |
case 'genre':
|
377 |
case 'genre':
|
- |
|
378 |
$valeur_recherche = $ligne_resultat['num_genre'];
|
372 |
$valeur_recherche = $ligne_resultat['num_genre'];
|
379 |
$intitule = 'genre';
|
373 |
break;
|
380 |
break;
|
374 |
case 'conseil_emploi':
|
381 |
case 'conseil_emploi':
|
- |
|
382 |
$valeur_recherche = $ligne_resultat['num_statut'];
|
375 |
$valeur_recherche = $ligne_resultat['num_statut'];
|
383 |
$intitule = 'conseil_emploi';
|
376 |
break;
|
384 |
break;
|
377 |
}
|
385 |
}
|
378 |
$code_valeur = '';
|
386 |
$code_valeur = '';
|
379 |
if(trim($valeur_recherche) != '') {
|
387 |
if(trim($valeur_recherche) != '') {
|
380 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
388 |
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
|
381 |
$code_valeur = $this->chercherSignificationCode($url, $nom);
|
389 |
$code_valeur = $this->chercherSignificationCode($url, $nom);
|
382 |
}
|
390 |
}
|
383 |
$ligne_resultat[$cle] = $code_valeur;
|
391 |
$ligne_resultat[$intitule] = $code_valeur;
|
384 |
}
|
392 |
}
|
385 |
return $ligne_resultat;
|
393 |
return $ligne_resultat;
|
Line -... |
Line 394... |
- |
|
394 |
}
|
386 |
}
|
395 |
|
- |
|
396 |
/**
|
387 |
|
397 |
* Fonction qui ajoute les attributions à une ligne de résultats
|
388 |
public function afficherTaxonsAttributions($resultat) {
|
398 |
*
|
- |
|
399 |
* @param array $ligne_tableau_resultat
|
- |
|
400 |
* @param array $ligne_originale
|
- |
|
401 |
* @param array $nom_sci
|
389 |
$nom_sci = $this->recupererNomTaxons();
|
402 |
*/
|
390 |
foreach ($resultat as $num=>$tab) {
|
403 |
public function ajouterTaxonsAttributionsLigneResultat($ligne_tableau_resultat, $noms_sci) {
|
391 |
if (isset($nom_sci[$tab['taxon']])) {
|
404 |
if (isset($nom_sci[$ligne_tableau_resultat['taxon.code']])) {
|
392 |
$resultat[$num]['nom_retenu.code'] = $nom_sci[$tab['taxon']]['id'];
|
- |
|
393 |
$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']]['nom_sci'];
|
405 |
$ligne_tableau_resultat['nom_retenu.code'] = $nom_sci[$ligne_tableau_resultat['taxon']]['id'];
|
394 |
}
|
406 |
$ligne_tableau_resultat['taxon'] = $nom_sci[$ligne_tableau_resultat['taxon']]['nom_sci'];
|
395 |
}
|
407 |
}
|
Line 396... |
Line 408... |
396 |
return $resultat;
|
408 |
return $ligne_tableau_resultat;
|
- |
|
409 |
}
|
- |
|
410 |
|
397 |
}
|
411 |
private function trierLigneTableau($a, $b) {
|
- |
|
412 |
$retour = 0;
|
- |
|
413 |
|
- |
|
414 |
if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
|
- |
|
415 |
$retour = 0;
|
- |
|
416 |
}
|
- |
|
417 |
|
- |
|
418 |
if($this->champ_tri == 'code_langue') {
|
- |
|
419 |
if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
|
- |
|
420 |
$retour = ($this->direction_tri == 'asc') ? -1 : 1;
|
- |
|
421 |
} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
|
- |
|
422 |
$retour = ($this->direction_tri == 'asc') ? 1 : -1;
|
- |
|
423 |
} else {
|
- |
|
424 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
- |
|
425 |
}
|
- |
|
426 |
} else {
|
- |
|
427 |
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
|
- |
|
428 |
}
|
- |
|
429 |
return $retour;
|
398 |
|
430 |
}
|
399 |
private function trierLigneTableau($a, $b) {
|
431 |
|
400 |
if ($a[$this->champ_tri] == $b[$this->champ_tri]) return 0;
|
432 |
private function comparerChaineSelonDirectionTri($a, $b) {
|
401 |
if($this->direction_tri == 'asc') {
|
433 |
if($this->direction_tri == 'asc') {
|
402 |
return ($a[$this->champ_tri] < $b[$this->champ_tri]) ? -1 : 1;
|
434 |
return ($a < $b) ? -1 : 1;
|
403 |
} else {
|
435 |
} else {
|
Line 404... |
Line 436... |
404 |
return ($a[$this->champ_tri] > $b[$this->champ_tri]) ? -1 : 1;
|
436 |
return ($a > $b) ? -1 : 1;
|
405 |
}
|
437 |
}
|
406 |
}
|
438 |
}
|