Skip to content

Commit

Permalink
ITIS: gestion des cas multiples de réponse par nom scientifique
Browse files Browse the repository at this point in the history
Pour une recherche donnée (ex. "Felis catus" ou "Pentaceraster horridus"), le résultat peut varier : $res['return']['scientificNames'] renvoie un mode associatif ou un array.

Ce correctif permet d'accéder à l'array lorsque le taxon recherché est associé à plusieurs résultats de recherche. Ainsi, "Felis catus" renvoie désormais "Felis catus" même s'il trouve "Felis catus" et "Felis catus domestica".
  • Loading branch information
LDWP committed Nov 16, 2023
1 parent ed26ae6 commit 95d8ba4
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions modules/mod_itis.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ function itis_cherche_regne($regne) {
'Domain' => 'domaine',
'Superdomain' => 'super-domaine',
'Empire' => 'empire',
'Kingdom' => 'royaume',
'Subkingdom' => 'sous-royaume',
];
// Étaient définis deux fois (volontaire ?)
//'Kingdom' => 'royaume',
// 'Subkingdom' => 'sous-royaume',

// retourne le rang de ITIS
function itis_cherche_rang($rang) {
global $itis_wp;
Expand Down Expand Up @@ -180,34 +182,32 @@ function m_itis_infos(&$struct, $classif) {
}
$res = json_decode(json_encode($_res), true);

if (!isset($res['return']['scientificNames'])) {
logs("ITIS: taxon non trouvé");
return false;
}

// si on trouve le KINGDOM et qu'on est classification on le fixe tout de suite
if ($classif and isset($res['return']['scientificNames']['kingdom'])) {
$struct['regne'] = itis_cherche_regne($res['return']['scientificNames']['kingdom']);
$r = $res['return']['scientificNames'];

if (!isset($r)) {
logs("ITIS: taxon non trouvé");
return false;
}

$ok = false;
foreach($res['return']['scientificNames'] as $r) {
if (isset($r['combinedName']) and $r['combinedName'] == $taxon) {
$ok = true;
break;
if (count($r) > 1) {
// Si scientificNames contient plusieurs éléments, on choisit le taxon renseigné
foreach ($r as $sn) {
if (isset($sn['combinedName']) && $sn['combinedName'] == $taxon) {
$r = $sn;
break;
}
}
}
if (!$ok) {
logs("ITIS: taxon non trouvé (2)");
return false;

// Règne si classif
if ($classif && isset($r['kingdom'])) {
$kingdom = $r['kingdom'];
$struct['regne'] = itis_cherche_regne($kingdom);
}

// ID, nom, auteur
$struct['liens']['itis']['id'] = $r['tsn'];
if (isset($r['combinedName'])) {
$struct['liens']['itis']['nom'] = $r['combinedName'];
} else {
$struct['liens']['itis']['nom'] = $taxon;
}
$struct['liens']['itis']['nom'] = isset($r['combinedName']) ? $r['combinedName'] : $taxon;
if (isset($r['author']) and !empty($r['author'])) {
$struct['liens']['itis']['auteur'] = $r['author'];
}
Expand Down

0 comments on commit 95d8ba4

Please sign in to comment.