Esempio n. 1
0
 /**
  * Write a modified collection object back to the api
  *
  * @param Zotero_Collection $collection to modify
  * @return Zotero_Response
  */
 public function writeUpdatedCollection($collection)
 {
     $json = $collection->collectionJson();
     $aparams = array('target' => 'collection', 'collectionKey' => $collection->collectionKey);
     $reqUrl = $this->apiRequestUrl($aparams) . $this->apiQueryString($aparams);
     $response = $this->_request($reqUrl, 'PUT', $json, array('If-Match' => $collection->etag));
     return $response;
 }
Esempio n. 2
0
 /**
  * Delete a collection from the library
  *
  * @param Zotero_Collection $collection collection object to be deleted
  * @return Zotero_Response
  */
 public function removeCollection($collection)
 {
     $aparams = array('target' => 'collection', 'collectionKey' => $collection->collectionKey);
     $reqUrl = $this->apiRequestString($aparams);
     $response = $this->_request($reqUrl, 'DELETE', null, array('If-Unmodified-Since-Version' => $collection->get('collectionVersion')));
     return $response;
 }
Esempio n. 3
0
 /**
  * Converts a Zotero_Collection object to a SimpleXMLElement item
  *
  * @param	object				$item		Zotero_Collection object
  * @return	SimpleXMLElement					Collection data as SimpleXML element
  */
 public static function convertCollectionToXML(Zotero_Collection $collection)
 {
     $xml = new SimpleXMLElement('<collection/>');
     $xml['libraryID'] = $collection->libraryID;
     $xml['key'] = $collection->key;
     $xml['name'] = $collection->name;
     $xml['dateAdded'] = $collection->dateAdded;
     $xml['dateModified'] = $collection->dateModified;
     if ($collection->parent) {
         $parentCol = self::get($collection->libraryID, $collection->parent);
         $xml['parent'] = $parentCol->key;
     }
     $children = $collection->getChildren();
     if ($children) {
         $keys = array();
         foreach ($children as $child) {
             if ($child['type'] == 'item') {
                 $keys[] = $child['key'];
             }
         }
         if ($keys) {
             $xml->items = implode(' ', $keys);
         }
     }
     return $xml;
 }
 public static function updateFromJSON(Zotero_Collection $collection, $json, $isNew = false)
 {
     self::validateJSONCollection($json);
     Zotero_DB::beginTransaction();
     $timestamp = Zotero_Libraries::updateTimestamps($collection->libraryID);
     Zotero_DB::registerTransactionTimestamp($timestamp);
     $collection->name = $json->name;
     $parentKey = $json->parent;
     if ($parentKey) {
         $collection->parentKey = $parentKey;
     } else {
         $collection->parent = false;
     }
     $collection->save();
     Zotero_DB::commit();
 }