public function processForm() { $tmpPath = sfConfig::get('sf_upload_dir') . '/tmp'; // Upload files $i = 0; foreach ($this->form->getValue('files') as $file) { if (0 == strlen($file['infoObjectTitle'] || 0 == strlen($file['tmpName']))) { continue; } $i++; // Create an information object for this digital object $informationObject = new QubitInformationObject(); $informationObject->parentId = $this->resource->id; if (0 < strlen($title = $file['infoObjectTitle'])) { $informationObject->title = $title; } if (0 != intval($levelOfDescriptionId = $this->form->getValue('level_of_description_id'))) { $informationObject->levelOfDescriptionId = $levelOfDescriptionId; } $informationObject->setStatus(array('typeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID, 'statusId' => sfConfig::get('app_defaultPubStatus'))); // Save description $informationObject->save(); if (file_exists("{$tmpPath}/{$file['tmpName']}")) { // Upload asset and create digital object $digitalObject = new QubitDigitalObject(); $digitalObject->informationObject = $informationObject; $digitalObject->usageId = QubitTerm::MASTER_ID; $digitalObject->assets[] = new QubitAsset($file['name'], file_get_contents("{$tmpPath}/{$file['tmpName']}")); $digitalObject->save(); } $thumbnailIsGeneric = (bool) strstr($file['thumb'], 'generic-icons'); // Clean up temp files if (file_exists("{$tmpPath}/{$file['tmpName']}")) { unlink("{$tmpPath}/{$file['tmpName']}"); } if (!$thumbnailIsGeneric && file_exists("{$tmpPath}/{$file['thumb']}")) { unlink("{$tmpPath}/{$file['thumb']}"); } } $this->redirect(array($this->resource, 'module' => 'informationobject')); }
/** * @see sfTask */ public function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $conn = $databaseManager->getDatabase('propel')->getConnection(); sfConfig::set('app_upload_dir', self::getUploadDir($conn)); if (false === ($fh = fopen($arguments['filename'], 'rb'))) { throw new sfException('You must specify a valid filename'); } $this->logSection("Load digital objects from {$arguments['filename']}..."); // Get header (first) row $header = fgetcsv($fh, 1000); if (!in_array('information_object_id', $header) || !in_array('filename', $header)) { throw new sfException('Import file must contain an \'information_object_id\' and \'filename\' column'); } $idKey = array_search('information_object_id', $header); $fileKey = array_search('filename', $header); // Build hash on information_object.id, with array value if information // object has multiple digital objects attached while ($item = fgetcsv($fh, 1000)) { if (!isset($digitalObjects[$item[$idKey]])) { $digitalObjects[$item[$idKey]] = $item[$fileKey]; } else { if (!is_array($digitalObjects[$item[$idKey]])) { $digitalObjects[$item[$idKey]] = array($digitalObjects[$item[$idKey]], $item[$fileKey]); } else { $digitalObjects[$item[$idKey]][] = $item[$fileKey]; } } } // Loop through $digitalObject hash and add digital objects to db foreach ($digitalObjects as $key => $item) { if (null === ($informationObject = QubitInformationObject::getById($key))) { $this->log("Invalid information_object id {$key}"); continue; } if (!is_array($item)) { self::addDigitalObject($informationObject, $item, $conn); } else { // If more than one digital object linked to this information object for ($i = 0; $i < count($item); $i++) { // Create new information objects, to maintain one-to-one // relationship with digital objects $informationObject = new QubitInformationObject(); $informationObject->parent = QubitInformationObject::getById($key); $informationObject->title = basename($item[$i]); $informationObject->save($conn); self::addDigitalObject($informationObject, $item[$i], $conn); } } } $this->logSection('Successfully Loaded ' . self::$count . ' digital objects.'); }
<?php include dirname(__FILE__) . '/../../bootstrap/functional.php'; $browser = new sfTestFunctional(new sfBrowser()); $informationObject = new QubitInformationObject(); $informationObject->save(); $browser->post(';digitalobject/create', array('file' => sfConfig::get('sf_test_dir') . '/fixtures/echo.jpg', 'informationObject' => $informationObject->id . ';isad'))->with('request')->begin()->isParameter('module', 'digitalobject')->isParameter('action', 'edit')->end()->with('response')->begin()->isStatusCode(200)->checkElement('body', '/Untitled/')->end();
public function parse($doc) { require_once sfConfig::get('sf_root_dir') . '/vendor/FluentDOM/FluentDOM.php'; $fd = FluentDOM($doc)->namespaces(array('eac' => 'urn:isbn:1-931666-33-4')); $this->resource->sourceStandard = 'http://eac.staatsbibliothek-berlin.de/schema/cpf.xsd'; $this->resource->descriptionIdentifier = $fd->find('eac:control/eac:recordId')->text(); //$fd->find('eac:control/eac:otherRecordId'); $this->maintenanceStatus = $fd->find('eac:control/eac:maintenanceStatus')->text(); $this->publicationStatus = $fd->find('eac:control/eac:publicationStatus')->text(); // TODO <descriptiveNote/>, <otherAgencyCode/> $this->resource->institutionResponsibleIdentifier = $fd->find('eac:control/eac:maintenanceAgency/eac:agencyName')->text(); // TODO <descriptiveNote/> foreach ($fd->find('eac:control/eac:languageDeclaration/eac:language/@languageCode') as $node) { $this->resource->language[] = $node->textContent; } foreach ($fd->find('eac:control/eac:languageDeclaration/eac:script/@scriptCode') as $node) { $this->resource->script[] = $node->textContent; } // conventionDeclaration/abbreviation is an identifier, referenced by e.g. // <authorizedForm/> and <alternativeForm/> // // TODO <descriptiveNote/> $this->resource->rules = $fd->find('eac:control/eac:conventionDeclaration/eac:citation')->text(); // TODO <abbreviation/>, <descriptiveNote/> //$fd->find('eac:control/eac:localTypeDeclaration'); // TODO <date/>, <dateRange/>, <term/> //$this->resource->descriptionDetail = $fd->find('eac:control/eac:localControl')->text(); $this->maintenanceHistory = $fd->find('eac:control/eac:maintenanceHistory'); // TODO <descriptiveNote/>, @lastDateTimeVerified $this->resource->sources = $fd->find('eac:control/eac:sources/eac:source/eac:sourceEntry')->text(); // TODO eac:cpfDescription/eac:identity/@identityType $this->resource->corporateBodyIdentifiers = $fd->find('eac:cpfDescription/eac:identity/eac:entityId')->text(); $this->entityType = $fd->find('eac:cpfDescription/eac:identity/eac:entityType')->text(); // TODO <nameEntryParallel/>, <useDates/> $this->resource->authorizedFormOfName = $fd->find('eac:cpfDescription/eac:identity/eac:nameEntry[eac:authorizedForm]/eac:part')->text(); foreach ($fd->find('eac:cpfDescription/eac:identity/eac:nameEntry[not(eac:authorizedForm)]') as $node) { $item = new QubitOtherName(); $item->name = $fd->spawn()->add($node)->find('eac:part')->text(); $item->typeId = QubitTerm::OTHER_FORM_OF_NAME_ID; $this->resource->otherNames[] = $item; } //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:authorizedForm'); //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:alternativeForm'); //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:preferredForm'); // TODO eac:cpfDescription/eac:identity/eac:descriptiveNote $this->existDates = $fd->find('eac:cpfDescription/eac:description/eac:existDates'); // TODO <address/>, <addressLine/>, <date/>, <dateRange/>, <dateSet/>, // <descriptiveNote/>, <placeRole/>, <term/>, @accuracy, @altitude, // @countryCode, @latitude, @longitude, @vocabularySource $this->resource->places = $fd->find('eac:cpfDescription/eac:description/eac:place/eac:placeEntry|eac:cpfDescription/eac:description/eac:places/eac:place/eac:placeEntry')->text(); // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>, // <placeEntry/>, <term/> //$fd->find('eac:cpfDescription/eac:description/eac:localDescription'); //$fd->find('eac:cpfDescription/eac:description/eac:localDescriptions'); // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>, // <placeEntry/> $this->resource->legalStatus = $fd->find('eac:cpfDescription/eac:description/eac:legalStatus/eac:term|eac:cpfDescription/eac:description/eac:legalStatuses/eac:legalStatus/eac:term')->text(); // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>, // <placeEntry/> $this->resource->functions = $fd->find('eac:cpfDescription/eac:description/eac:function/eac:term|eac:cpfDescription/eac:description/eac:functions/eac:function/eac:term|eac:cpfDescription/eac:description/eac:occupation/eac:term|eac:cpfDescription/eac:description/eac:occupations/eac:occupation/eac:term')->text(); //$fd->find('eac:cpfDescription/eac:description/eac:languageUsed'); // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>, // <placeEntry/> $this->resource->mandates = $fd->find('eac:cpfDescription/eac:description/eac:mandate/eac:term|eac:cpfDescription/eac:description/eac:mandates/eac:mandate/eac:term')->text(); $this->internalStructures = $fd->find('eac:cpfDescription/eac:description/eac:structureOrGenealogy'); $this->generalContext = $fd->find('eac:cpfDescription/eac:description/eac:generalContext'); // TODO <abstract/>, <chronList/> $this->biogHist = $fd->find('eac:cpfDescription/eac:description/eac:biogHist'); // TODO @lastDateTimeVerified, <date/>, <dateRange/>, <dateSet/>, // <descriptiveNote/>, <placeEntry/> foreach ($fd->find('eac:cpfDescription/eac:relations/eac:cpfRelation') as $node) { $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count); // @href is one of our resources if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) { $params = sfContext::getInstance()->routing->parse($url); $item = $params['_sf_route']->resource; } else { $item = new QubitActor(); $item->authorizedFormOfName = $fd->spawn()->add($node)->find('eac:relationEntry')->text(); // TODO Cascade save through QubitEvent $item->save(); } $relation = new QubitRelation(); $relation->object = $item; $relation->typeId = self::fromCpfRelationType($node->getAttribute('cpfRelationType')); if (0 < count($date = self::parseDates($node))) { $relation->startDate = $date[0][0]; $relation->endDate = $date[count($date) - 1][1]; } // Multiple, non-contiguous dates if (1 < count($date)) { foreach ($date as $key => $value) { $date[$key] = Qubit::renderDate($value[0]) . ' - ' . Qubit::renderDate($value[1]); } $note = new QubitNote(); $note->typeId = QubitTerm::RELATION_NOTE_DATE_ID; $note->scope = 'QubitRelation'; $note->content = implode(', ', $date); $relation->notes[] = $note; } $this->resource->relationsRelatedBysubjectId[] = $relation; } // TODO @lastDateTimeVerified, <date/>, <dateRange/>, <dateSet/>, // <descriptiveNote/>, <placeEntry/> foreach ($fd->find('eac:cpfDescription/eac:relations/eac:resourceRelation') as $node) { $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count); // @href is one of our resources if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) { $params = sfContext::getInstance()->routing->parse($url); $item = $params['_sf_route']->resource; } else { $item = new QubitInformationObject(); $item->parentId = QubitInformationObject::ROOT_ID; $item->title = $fd->spawn()->add($node)->find('eac:relationEntry')->text(); // TODO Cascade save through QubitEvent $item->save(); } $event = new QubitEvent(); $event->informationObject = $item; $event->typeId = self::fromResourceRelationType($node->getAttribute('resourceRelationType')); if (0 < count($date = self::parseDates($node))) { $event->startDate = $date[0][0]; $event->endDate = $date[count($date) - 1][1]; } // Multiple, non-contiguous dates if (1 < count($date)) { foreach ($date as $key => $value) { $date[$key] = Qubit::renderDate($value[0]) . ' - ' . Qubit::renderDate($value[1]); } $event->date = implode(', ', $date); } $this->resource->events[] = $event; } // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>, // <placeEntry/>, @lastDateTimeVerified foreach ($fd->find('eac:cpfDescription/eac:relations/eac:functionRelation') as $node) { $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count); // @href is one of our resources if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) { $params = sfContext::getInstance()->routing->parse($url); $item = $params['_sf_route']->resource; } else { $item = new QubitFunction(); $item->authorizedFormOfName = $fd->spawn()->add($node)->find('eac:relationEntry')->text(); // TODO Cascade save through QubitEvent $item->save(); } $relation = new QubitRelation(); $relation->subject = $item; // TODO Set $relation->type by mapping to controlled vocabulary $this->resource->relationsRelatedByobjectId[] = $relation; } // TODO <alternativeSet/> return $this; }
/** * Create an info and digital object tree for multi-page assets * * For digital objects that describe a multi-page digital asset (e.g. a * multi-page tif image), create a derived asset for each page, create a child * information object and linked child digital object and move the derived * asset to the appropriate directory for the new (child) info object * * NOTE: Requires the Imagemagick library for creating derivative assets * * @return QubitDigitalObject this object */ public function createCompoundChildren() { // Bail out if the imagemagick library is not installed if (false === self::hasImageMagick()) { return $this; } $pages = $this->explodeMultiPageAsset(); foreach ($pages as $i => $filepath) { // Create a new information object $newInfoObject = new QubitInformationObject(); $newInfoObject->parentId = $this->getInformationObject()->id; $newInfoObject->setTitle($this->getInformationObject()->getTitle() . ' (' . ($i + 1) . ')'); $newInfoObject->save(); // Create and link a new digital object $newDigiObject = new QubitDigitalObject(); $newDigiObject->parentId = $this->id; $newDigiObject->setInformationObjectId($newInfoObject->id); $newDigiObject->save(); // Derive new file path based on newInfoObject $assetPath = $newDigiObject->getAssetPath(); $createPath = ''; foreach (explode('/', $assetPath) as $d) { $createPath .= '/' . $d; if (!is_dir(sfConfig::get('sf_web_dir') . $createPath)) { mkdir(sfConfig::get('sf_web_dir') . $createPath, 0755); } chmod(sfConfig::get('sf_web_dir') . $createPath, 0755); } // Derive new name for file based on original file name + newDigitalObject // id $filename = basename($filepath); $newFilepath = sfConfig::get('sf_web_dir') . $assetPath . '/' . $filename; // Move asset to new name and path rename($filepath, $newFilepath); chmod($newFilepath, 0644); // Save new file information $newDigiObject->setPath("{$assetPath}/"); $newDigiObject->setName($filename); $newDigiObject->setByteSize(filesize($newFilepath)); $newDigiObject->usageId = QubitTerm::MASTER_ID; $newDigiObject->setMimeType(QubitDigitalObject::deriveMimeType($filename)); $newDigiObject->mediaTypeId = $this->mediaTypeId; $newDigiObject->setPageCount(); $newDigiObject->setSequence($i + 1); $newDigiObject->save(); // And finally create reference and thumb images for child asssets $newDigiObject->createRepresentations($newDigiObject->getUsageId(), $connection); } return $this; }
public static function loadData() { $object = new QubitInformationObject(); $object->id = QubitInformationObject::ROOT_ID; $object->save(); $object = new QubitActor(); $object->id = QubitActor::ROOT_ID; $object->save(); $object = new QubitSetting(); $object->name = 'plugins'; $object->value = serialize(array('sfCaribouPlugin', 'sfEhriThemePlugin', 'sfDcPlugin', 'sfEacPlugin', 'sfEadPlugin', 'sfIsaarPlugin', 'sfIsadPlugin', 'sfEhriIsadPlugin', 'sfIsdfPlugin', 'sfIsdiahPlugin', 'sfEhriIsdiahPlugin', 'sfModsPlugin', 'sfRadPlugin', 'sfSkosPlugin')); $object->save(); $dispatcher = sfContext::getInstance()->getEventDispatcher(); $formatter = new sfAnsiColorFormatter(); chdir(sfConfig::get('sf_root_dir')); $loadData = new sfPropelDataLoadTask($dispatcher, $formatter); $loadData->run(); }
public function execute($request) { $this->form = new sfForm(); $this->resource = $this->getRoute()->resource; if (!QubitAcl::check(QubitInformationObject::getRoot(), 'update')) { QubitAcl::forwardUnauthorized(); } // Create new information object $informationObject = new QubitInformationObject(); $informationObject->setRoot(); // Populate fields $informationObject->title = $this->resource->title; $informationObject->physicalCharacteristics = $this->resource->physicalCharacteristics; $informationObject->scopeAndContent = $this->resource->scopeAndContent; $informationObject->archivalHistory = $this->resource->archivalHistory; // Copy (not link) rights foreach (QubitRelation::getRelationsBySubjectId($this->resource->id, array('typeId' => QubitTerm::RIGHT_ID)) as $item) { $sourceRight = $item->object; $right = new QubitRights(); $right->act = $sourceRight->act; $right->startDate = $sourceRight->startDate; $right->endDate = $sourceRight->endDate; $right->basis = $sourceRight->basis; $right->restriction = $sourceRight->restriction; $right->copyrightStatus = $sourceRight->copyrightStatus; $right->copyrightStatusDate = $sourceRight->copyrightStatusDate; $right->copyrightJurisdiction = $sourceRight->copyrightJurisdiction; $right->statuteNote = $sourceRight->statuteNote; // Right holder if (isset($sourceRight->rightsHolder)) { $right->rightsHolder = $sourceRight->rightsHolder; } // I18n $right->rightsNote = $sourceRight->rightsNote; $right->copyrightNote = $sourceRight->copyrightNote; $right->licenseIdentifier = $sourceRight->licenseIdentifier; $right->licenseTerms = $sourceRight->licenseTerms; $right->licenseNote = $sourceRight->licenseNote; $right->statuteJurisdiction = $sourceRight->statuteJurisdiction; $right->statuteCitation = $sourceRight->statuteCitation; $right->statuteDeterminationDate = $sourceRight->statuteDeterminationDate; foreach ($sourceRight->rightsI18ns as $sourceRightI18n) { if ($this->context->user->getCulture() == $sourceRightI18n->culture) { continue; } $rightI18n = new QubitRightsI18n(); $rightI18n->rightNote = $sourceRightI18n->rightNote; $rightI18n->copyrightNote = $sourceRightI18n->copyrightNote; $rightI18n->licenseIdentifier = $sourceRightI18n->licenseIdentifier; $rightI18n->licenseTerms = $sourceRightI18n->licenseTerms; $rightI18n->licenseNote = $sourceRightI18n->licenseNote; $rightI18n->statuteJurisdiction = $sourceRightI18n->statuteJurisdiction; $rightI18n->statuteCitation = $sourceRightI18n->statuteCitation; $rightI18n->statuteNote = $sourceRightI18n->statuteNote; $rightI18n->culture = $sourceRightI18n->culture; $right->rightsI18ns[] = $rightI18n; } $right->save(); $relation = new QubitRelation(); $relation->object = $right; $relation->typeId = QubitTerm::RIGHT_ID; $informationObject->relationsRelatedBysubjectId[] = $relation; } // Populate creators (from QubitRelation to QubitEvent) foreach (QubitRelation::getRelationsByObjectId($this->resource->id, array('typeId' => QubitTerm::CREATION_ID)) as $item) { $event = new QubitEvent(); $event->actor = $item->subject; $event->typeId = QubitTerm::CREATION_ID; $informationObject->events[] = $event; } // Relationship between the information object and accession record $relation = new QubitRelation(); $relation->object = $this->resource; $relation->typeId = QubitTerm::ACCESSION_ID; $informationObject->relationsRelatedBysubjectId[] = $relation; // Set publication status $informationObject->setPublicationStatus(sfConfig::get('app_defaultPubStatus', QubitTerm::PUBLICATION_STATUS_DRAFT_ID)); $informationObject->save(); $this->redirect(array($informationObject, 'module' => 'informationobject')); }