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;
    }
}
Beispiel #2
0
 public function getChildren()
 {
     //short circuit if has item has no children
     if (!$this->numChildren) {
         //} || (this.parentItemKey !== false)){
         return array();
     }
     $config = array('target' => 'children', 'libraryType' => $this->owningLibrary->libraryType, 'libraryID' => $this->owningLibrary->libraryID, 'itemKey' => $this->itemKey, 'content' => 'json');
     $requestUrl = $this->owningLibrary->apiRequestString($config);
     $response = $this->owningLibrary->_request($requestUrl, 'GET');
     //load response into item objects
     $fetchedItems = array();
     if ($response->isError()) {
         return false;
         throw new Exception("Error fetching items");
     }
     $feed = new Zotero_Feed($response->getRawBody());
     $fetchedItems = $this->owningLibrary->items->addItemsFromFeed($feed);
     return $fetchedItems;
 }