Пример #1
0
    public function testCollectionAndTags()
    {
        $templateJsonString = <<<'EOD'
{"itemType":"journalArticle","title":"","creators":[{"creatorType":"author","firstName":"","lastName":""}],"abstractNote":"","publicationTitle":"","volume":"","issue":"","pages":"","date":"","series":"","seriesTitle":"","seriesText":"","journalAbbreviation":"","language":"","DOI":"","ISSN":"","shortTitle":"","url":"","accessDate":"","archive":"","archiveLocation":"","libraryCatalog":"","callNumber":"","rights":"","extra":"","tags":[],"collections":[],"relations":{}}
EOD;
        $templateArray = json_decode($templateJsonString, true);
        $item = new Zotero_Item();
        $item->initItemFromTemplate($templateArray);
        $item->addToCollection("ASDF1234");
        $item->addToCollection("FDSA4321");
        $item->addTag("Green");
        $item->addTag("purple", 1);
        $item->addTag("Red");
        $itemCollections = $item->get('collections');
        $this->assertEquals(count($itemCollections), 2, 'right number of collections');
        $this->assertEquals($itemCollections[0], "ASDF1234", "first col match");
        $this->assertEquals($itemCollections[1], "FDSA4321", "Second col match");
        $itemTags = $item->get('tags');
        $this->assertEquals(count($itemTags), 3);
        $this->assertEquals($itemTags[0], "Green");
        $this->assertEquals($itemTags[1]['tag'], "purple");
        $this->assertEquals($itemTags[1]['type'], 1);
        $this->assertEquals($itemTags[2], "Red");
        //test removal
        $item->removeFromCollection('OIUSDGAS');
        $item->removeFromCollection("ASDF1234");
        $item->removeTag("Red");
        $item->removeTag("Green");
        $itemCollections = $item->get('collections');
        $this->assertEquals(count($itemCollections), 1, 'right number of collections');
        $this->assertEquals($itemCollections[0], "FDSA4321", "first col match");
        $itemTags = $item->get('tags');
        $this->assertEquals(count($itemTags), 1);
        $this->assertEquals($itemTags[0]['tag'], "purple");
        $this->assertEquals($itemTags[0]['type'], 1);
    }
Пример #2
0
 /**
  * Add child notes to a parent item
  *
  * @param Zotero_Item $parentItem the item the notes are to be children of
  * @param Zotero_Item|array $noteItem the note item or items
  * @return array of Zotero_Item
  */
 public function addNotes($parentItem, $noteItem)
 {
     $aparams = array('target' => 'items');
     $reqUrl = $this->apiRequestString($aparams);
     $noteWriteItems = array();
     if (!is_array($noteItem)) {
         if (get_class($noteItem) == "Zotero_Item") {
             $noteWriteItems[] = $noteItem;
         } else {
             throw new Exception("Unexpected note item type");
         }
     } else {
         foreach ($noteItem as $nitem) {
             $noteWriteItems[] = $nitem;
         }
     }
     //set parentItem for all notes
     $parentItemKey = $parentItem->get("itemKey");
     foreach ($noteWriteItems as $nitem) {
         $nitem->set("parentItem", $parentItemKey);
     }
     return $this->items->writeItems($noteWriteItems);
 }