Beispiel #1
0
/**
 * Load a single item by itemKey only if it belongs to a specific collection
 *
 * @param Zotero_Library $library
 * @param string $itemKey
 * @param string $collectionKey
 * @return Zotero_Item
 */
function fetchCollectionItem($library, $itemKey, $collectionKey)
{
    $citemKey = $itemKey . ',';
    //hackish way to get a single item by itemKey + collectionKey by forcing itemKey into querystring
    $aparams = array('target' => 'items', 'content' => 'json', 'itemKey' => $itemKey, 'collectionKey' => $collectionKey);
    $reqUrl = $library->apiRequestUrl($aparams) . $library->apiQueryString($aparams);
    $response = $library->_request($reqUrl, 'GET');
    if ($response->isError()) {
        return false;
        throw new Exception("Error fetching items");
    }
    $body = $response->getRawBody();
    $doc = new DOMDocument();
    $doc->loadXml($body);
    $entries = $doc->getElementsByTagName("entry");
    if (!$entries->length) {
        return false;
        throw new Exception("no item with specified key found");
    } else {
        $entry = $entries->item(0);
        $item = new Zotero_Item($entry);
        $library->items->addItem($item);
        return $item;
    }
}