public function testAdminCollectionsShow() { $this->_authenticateUser($this->_getDefaultUser()); $metadata = array('name' => 'testcollection'); $collection = insert_collection($metadata); $this->dispatch('/collections/show/id/' . $collection->id); $this->assertQuery('#item_order_admin_collection_show'); }
/** * Insert item type and collection, set POST data. */ public function setUp() { parent::setUp(); // Exhibit: $this->exhibit = $this->_exhibit(); // Item type: $this->type = insert_item_type(array('name' => 'Type')); // Collection: $this->collection = insert_collection(array(), array('Dublin Core' => array('Title' => array(array('text' => 'Collection', 'html' => false))))); // Query: $this->query = array('range' => '1-10', 'collection' => $this->collection->id, 'type' => $this->type->id, 'tags' => 'tag1,tag2'); // Set POST data. $this->request->setMethod('POST')->setPost($this->query); }
/** * Insert the collection into the database * */ public function import() { $collectionMetadata = $this->collectionMetadata(); $elementTexts = $this->elementTexts(); if ($this->record && $this->record->exists()) { $collectionMetadata['overwriteElementTexts'] = true; update_collection($this->record, $collectionMetadata, $elementTexts); } else { try { $this->record = insert_collection($collectionMetadata, $elementTexts); } catch (Exception $e) { _log($e); } $this->addOmekaApiImportRecordIdMap(); } }
public function testCanUpdateEmptyCollection() { $oldCollection = insert_collection(); $this->assertInstanceOf('Collection', $oldCollection); $this->assertTrue($oldCollection->exists()); $this->assertEquals(0, $oldCollection->public); $this->assertEquals(0, $oldCollection->featured); $elementTexts = $oldCollection->getAllElementTexts(); $this->assertCount(0, $elementTexts); $titleText = 'foo'; $descriptionTextA = 'bar'; $descriptionTextB = 'soap'; $isHtml = true; $isPublic = true; $isFeatured = true; $metadata = array('public' => $isPublic, 'featured' => $isFeatured); $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $titleText, 'html' => $isHtml)), 'Description' => array(array('text' => $descriptionTextA, 'html' => $isHtml), array('text' => $descriptionTextB, 'html' => $isHtml)))); $updatedCollection = update_collection($oldCollection, $metadata, $elementTexts); $this->assertInstanceOf('Collection', $oldCollection); $this->assertTrue($updatedCollection->exists()); $this->assertEquals($isPublic ? 1 : 0, $oldCollection->public); $this->assertEquals($isFeatured ? 1 : 0, $oldCollection->featured); $titleElementTexts = $oldCollection->getElementTexts('Dublin Core', 'Title'); $this->assertCount(1, $titleElementTexts); $titleElementText = $titleElementTexts[0]; $this->assertEquals($titleText, $titleElementText->text); $this->assertEquals($isHtml ? 1 : 0, $titleElementText->html); $descriptionElementTexts = $oldCollection->getElementTexts('Dublin Core', 'Description'); $this->assertCount(2, $descriptionElementTexts); $descriptionElementTextA = $descriptionElementTexts[0]; $this->assertEquals($descriptionTextA, $descriptionElementTextA->text); $this->assertEquals($isHtml ? 1 : 0, $descriptionElementTextA->html); $descriptionElementTextB = $descriptionElementTexts[1]; $this->assertEquals($descriptionTextB, $descriptionElementTextB->text); $this->assertEquals($isHtml ? 1 : 0, $descriptionElementTextB->html); }
protected function parseNewspaperData($newspaperJson, $newspaperDetailsJson) { //$newspaperJson comes from entry from newspapers.json //fetch second layer of data $lccn = $newspaperJson['lccn']; $newspaper = $this->newspapersTable->findByLccn($lccn); if ($newspaper) { return $newspaper; } //set element set data //need an element set for Newspaper $metadata = array('Dublin Core' => array(), 'Newspaper Metadata' => array()); //switch around hanlding of each data field foreach ($newspaperDetailsJson as $key => $values) { switch ($key) { case 'place_of_publication': case 'lccn': $metadata['Dublin Core']['Identifier'] = array(array('html' => false, 'text' => $values)); case 'start_year': case 'end_year': case 'url': $metadata['Newspaper Metadata'][$key] = array(array('html' => false, 'text' => $values)); break; case 'place': $placesArray = array(); foreach ($values as $value) { $placesArray[] = array('html' => false, 'text' => $value); } $metadata['Newspaper Metadata']['place'] = $placesArray; break; case 'name': // dc:title $metadata['Dublin Core']['Title'] = array(array('html' => false, 'text' => $values)); break; case 'publisher': // dc:publisher $metadata['Dublin Core']['Publisher'] = array(array('html' => false, 'text' => $values)); break; case 'issues': break; case 'subject': $subjectsArray = array(); foreach ($values as $value) { $subjectsArray[] = array('html' => false, 'text' => $value); } $metadata['Dublin Core']['Subject'] = $subjectsArray; break; } } //insert collection $collection = insert_collection(array('public' => true), $metadata); //set NewspapersNewspaper data $newspaper = new NewspapersNewspaper(); //$newspaper->collection_id = $collection->id; $newspaper->collection_id = $collection->id; //$newspaper->ca_import_id = 1; //fake! @todo $newspaper->lccn = $newspaperJson['lccn']; $newspaper->state = $newspaperJson['state']; $newspaper->issues_count = count($newspaperDetailsJson['issues']); $newspaper->save(); return $newspaper; }
/** * Check simultaneous change of identifier and collection of the item. */ protected function _testChangeIdentifierAndCollection() { $elementSetName = 'Dublin Core'; $elementName = 'Identifier'; // Create a new collection. $this->collection = insert_collection(array('public' => true)); // Need to release item and to reload it. $itemId = $this->item->id; release_object($this->item); $this->item = get_record_by_id('Item', $itemId); // Update item. update_item($this->item, array('collection_id' => $this->collection->id, 'overwriteElementTexts' => true), array($elementSetName => array($elementName => array(array('text' => 'my_new_item_identifier', 'html' => false))))); $files = $this->item->getFiles(); foreach ($files as $key => $file) { $this->_checkFile($file); } }
/** * The collection title should be indexed. */ public function testIndexCollection() { // Add collection with a "Title" element. $collection = insert_collection(array(), array('Dublin Core' => array('Title' => array(array('text' => 'collection', 'html' => false))))); // Add an item to the collection. $item = insert_item(array('public' => true, 'collection_id' => $collection->id)); // Get the Solr document for the item. $document = $this->_getRecordDocument($item); // Should index the collection title. $this->assertEquals('collection', $document->collection); }
/** * Insert a collection. * * @see insert_collection() * @param array $metadata * @return Collection */ protected final function _insertCollection($metadata = array()) { // If collection_id is not null, use the existing collection, do not // create a new one. if ($collection_id = $this->_harvest->collection_id) { $collection = get_db()->getTable('Collection')->find($collection_id); } else { // There must be a collection name, so if there is none, like when the // harvest is repository-wide, set it to the base URL. if (!isset($metadata['elementTexts']['Dublin Core']['Title']['text']) || !$metadata['elementTexts']['Dublin Core']['Title']['text']) { ${$metadata}['elementTexts']['Dublin Core']['Title']['text'] = $this->_harvest->base_url; } $collection = insert_collection($metadata['metadata'], $metadata['elementTexts']); // Remember to set the harvest's collection ID once it has been saved. $this->_harvest->collection_id = $collection->id; $this->_harvest->save(); } return $collection; }
/** * Set some records with identifier to test. */ protected function _prepareRecords() { // Remove default records. $this->_deleteAllRecords(); $metadata = array('public' => true); $isHtml = false; $collections = array(); $items = array(); $files = array(); foreach ($this->_recordsByType as $type => $recordsMetadata) { foreach ($recordsMetadata as $recordMetadata) { $identifiers = array(); foreach ($recordMetadata['Identifier'] as $identifier) { $identifiers[] = array('text' => $identifier, 'html' => $isHtml); } $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $recordMetadata['Title'], 'html' => $isHtml)), 'Identifier' => $identifiers)); switch ($type) { case 'Collection': $collections[$recordMetadata['collection_id']] = insert_collection($metadata, $elementTexts); break; case 'Item': $metadataItem = $metadata; if (!empty($recordMetadata['collection_id'])) { $metadataItem['collection_id'] = $collections[$recordMetadata['collection_id']]->id; } $record = insert_item($metadataItem, $elementTexts); if (!empty($recordMetadata['files'])) { $fileUrl = TEST_DIR . '/_files/test.txt'; $files[$recordMetadata['item_id']] = insert_files_for_item($record, 'Filesystem', array_fill(0, $recordMetadata['files'], $fileUrl)); } break; case 'File': $record = $files[$recordMetadata['item_id']][$recordMetadata['file_key']]; $record->addElementTextsByArray($elementTexts); $record->save(); break; } } } }
/** * Insert a new collection into the Omeka database. * * Post data can be added, unlike insert_collection(). * * @see insert_collection() * * @param array $metadata * @param array $elementTexts * @param array $postData * @return Item */ private function _insertCollection($metadata = array(), $elementTexts = array(), $postData = array()) { $record = insert_collection($metadata, $elementTexts); $result = $this->_setExtraData($record, $postData, CsvImport_ColumnMap_Action::ACTION_ADD); return $record; }
/** * Creates an Omeka collection that corresponds to the imported Zotero * library/collection. * * @uses insert_collection() * @param int $libraryId The library ID. * @param string $libraryType The type of library, user or group. * @param int|null $collectionId The collection ID. * @param string $privateKey The Zotero API private key. * @return Collection Omeka collection object. */ protected function _createCollection($libraryId, $libraryType, $collectionId, $privateKey) { require_once 'ZoteroApiClient/Service/Zotero.php'; // Get the collection title from the Zotero API. $z = new ZoteroApiClient_Service_Zotero($privateKey); if ($collectionId) { $method = "{$libraryType}CollectionItemsTop"; $feed = $z->{$method}($libraryId, $collectionId); $name = trim(preg_replace('#.+/.+/.+‘(.+)’$#', '$1', $feed->title())); } else { $method = "{$libraryType}ItemsTop"; $feed = $z->{$method}($libraryId); $name = trim(preg_replace('#.+/(.+)/.+#', '$1', $feed->title())); } $collectionMetadata = array('public' => true); $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $name, 'html' => true)))); return insert_collection($collectionMetadata, $elementTexts); }
/** * Insert a new collection into the Omeka database. * * Post data can be added, unlike insert_collection(). * * @see insert_collection() * * @param array $metadata * @param array $elementTexts * @param array $postData * @return Item */ private function _insertCollection($metadata = array(), $elementTexts = array(), $postData = array()) { $record = insert_collection($metadata, $elementTexts); $result = $this->_setExtraData($record, $postData, ArchiveFolder_Importer::ACTION_ADD); return $record; }
/** * Create collection if it is set to be the name of the repository and if it * is not already created. * * @return integer|null The id of the collection, or null if no collection */ protected function _createCollectionIfNeeded() { $collectionId = $this->getParameter('collection_id'); if (empty($collectionId)) { return null; } // Check if collection exists. if (is_numeric($collectionId)) { $collection = get_record_by_id('Collection', $collectionId); if ($collection) { return (int) $collectionId; } } // Collection doesn't exist, so set it with the name. if ($collectionId != 'default') { return null; } // Prepare collection. $metadata = array('public' => $this->getParameter('records_are_public'), 'featured' => $this->getParameter('records_are_featured')); // The title of the collection is the url of the repository. $repositoryName = $this->uri; $elementTexts = array(); $elementTexts['Dublin Core']['Title'][] = array('text' => $repositoryName, 'html' => false); $elementTexts['Dublin Core']['Identifier'][] = array('text' => $this->uri, 'html' => false); $collection = insert_collection($metadata, $elementTexts); // Save the collection as parameter of the folder. $this->setParameter('collection_id', $collection->id); return $collection->id; }
/** * Tests the insertion of a collection with a single Dublin Core Title element text * * @param boolean $isPublic Whether the collection is public or not * @param boolean $isFeatured Whether the collection is featured or not * @param boolean $isHtml Whether the collection has an HTML title or not */ protected function _testInsertCollection($isPublic, $isFeatured, $isHtml) { $db = $this->db; $titleText = 'foobar'; // Insert an collection $metadata = array('public' => $isPublic, 'featured' => $isFeatured); $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $titleText, 'html' => $isHtml)))); $collection = insert_collection($metadata, $elementTexts); $this->assertInstanceOf('Collection', $collection); $fCollection = $db->getTable('Collection')->find($collection->id); $this->assertInstanceOf('Collection', $fCollection); $this->assertEquals($isPublic ? 1 : 0, $fCollection->public); $this->assertEquals($isFeatured ? 1 : 0, $fCollection->featured); $elementTexts = $fCollection->getElementTexts('Dublin Core', 'Title'); $this->assertCount(1, $elementTexts); $titleElementText = $elementTexts[0]; $this->assertEquals($titleText, $titleElementText->text); $this->assertEquals($isHtml ? 1 : 0, $titleElementText->html); release_object($collection); release_object($fCollection); release_object($elementTexts); }
public function _createCollectionFromFeed($feed) { $metadata = array(); $metadata['name'] = $feed->get_title(); $metadata['description'] = $feed->get_description(); $newCollection = insert_collection($metadata); return $newCollection->id; }
/** * Create a collection. * * @param string $title The collection title. * @return Collection */ protected function _collection($title, $public) { return insert_collection(array('public' => $public), array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false))))); }