}
                $occurrence->occurrenceID = $attributes['gbifKey'];
                $xpath_query = "to:catalogNumber";
                $nc = $xpath->query($xpath_query, $node);
                foreach ($nc as $n) {
                    $occurrence->catalogueNumber = $n->firstChild->nodeValue;
                }
                $xpath_query = "to:identifiedTo/to:Identification/to:taxon/tc:TaxonConcept/@gbifKey";
                $nc = $xpath->query($xpath_query, $node);
                foreach ($nc as $n) {
                    $occurrence->taxonID = $n->firstChild->nodeValue;
                }
                $xpath_query = "to:identifiedTo/to:Identification/to:taxon/tc:TaxonConcept/tc:hasName/tn:TaxonName/tn:nameComplete";
                $nc = $xpath->query($xpath_query, $node);
                foreach ($nc as $n) {
                    $occurrence->scientificName = $n->firstChild->nodeValue;
                }
            }
            get_lineage($occurrence->taxonID, $occurrence);
            $obj->occurrences[$occurrence->occurrenceID] = $occurrence;
        }
    }
    $js = json_encode($obj);
}
if ($callback != '') {
    echo $callback . '(';
}
echo $js;
if ($callback != '') {
    echo ')';
}
Ejemplo n.º 2
0
/**
 * Given a set of items as an associative array of id/parentid pairs, and an
 * item, returns an array of the item's descendants (including the item)
 *
 * @param array $items Associative array
 *                     (e.g. array(['itemid'] => 'parentid', ['itemid2'] = 'parentid2') )
 * @param integer $itemid ID of the item to build the path for
 *
 * @return An array of IDs, from the first parent right back to the item
 */
function get_lineage($items, $itemid, $pathsofar = array()) {
    // protection against bad items list and circular references
    if (!is_array($items) || in_array($itemid, $pathsofar)) {
        return $pathsofar;
    }

    // add this item to the list
    array_unshift($pathsofar, $itemid);
    if (!isset($items[$itemid]) || empty($items[$itemid])) {
        // finished when an item has no parent
        return $pathsofar;
    } else {
        // keep going
        return get_lineage($items, $items[$itemid], $pathsofar);
    }
}