Esempio n. 1
0
    /* Get most viewed list for this subset of laureates */
    $popularityList = new Toplist\WikipediaPopularityList($wpNames);
    $orderedList = $popularityList->getOrdered();
    usort($list, function ($a, $b) use($orderedList) {
        $ida = $a['dbPedia'];
        $idb = $b['dbPedia'];
        $posa = array_search($ida, $orderedList);
        $posb = array_search($idb, $orderedList);
        return $posa > $posb ? 1 : -1;
    });
    /* Truncate list to max length */
    global $maxListItems;
    $maxListLength = @$parameters['length'] ?: $maxListItems;
    $list = array_values(array_slice($list, 0, $maxListLength));
} else {
    $popularityList = new Toplist\OnsitePopularityList();
    $orderedList = $popularityList->getOrdered();
    usort($list, function ($a, $b) use($orderedList) {
        $ida = $a['id'];
        $idb = $b['id'];
        $posa = array_search($ida, $orderedList);
        $posb = array_search($idb, $orderedList);
        return $posa < $posb ? 1 : -1;
    });
    /* Truncate list to max length */
    global $maxListItems;
    $maxListLength = @$parameters['length'] ?: $maxListItems;
    $list = array_values(array_slice($list, 0, $maxListLength));
}
$api->write_headers();
$api->write_json($list);