コード例 #1
0
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = $this->getRoute()->resource;
     // Check that this isn't the root
     if (!isset($this->resource->parent)) {
         $this->forward404();
     }
     $query = QubitSearch::getInstance()->addTerm($this->resource->id, 'parentId');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $query = QubitAcl::searchFilterByRepository($query, 'read');
     $query = QubitAcl::searchFilterDrafts($query);
     $this->pager = new QubitArrayPager();
     $this->pager->hits = QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitInformationObject::ID, $ids, Criteria::IN);
     $this->informationObjects = QubitInformationObject::get($criteria);
 }
コード例 #2
0
 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'));
 }
コード例 #3
0
 public function execute($request)
 {
     if (null === ($this->resource = $this->getRoute()->resource)) {
         return $this->generateResponse(404, 'error/ErrorBadRequest', array('summary' => $this->context->i18n->__('Not found')));
     }
     $this->user = $request->getAttribute('user');
     if ($request->isMethod('post')) {
         if (QubitAcl::check(QubitInformationObject::getRoot(), 'create')) {
             return $this->generateResponse(403, 'error/ErrorBadRequest', array('summary' => $this->context->i18n->__('Forbidden')));
         }
         $this->packageFormat = $request->getHttpHeader('X-Packaging');
         $this->packageContentType = $request->getContentType();
         // Check if the packaging format is supported
         if (!in_array($this->packageFormat, qtSwordPluginConfiguration::$packaging)) {
             return $this->generateResponse(415, 'error/ErrorContent', array('summary' => $this->context->i18n->__('The supplied format is not supported by this server')));
         }
         // Check if the content type is supported
         if (!in_array($this->packageContentType, qtSwordPluginConfiguration::$mediaRanges)) {
             return $this->generateResponse(415, 'error/ErrorContent', array('summary' => $this->context->i18n->__('The supplied content type is not supported by this server')));
         }
         // Save the file temporary
         $filename = qtSwordPlugin::saveRequestContent();
         // Package name
         if (null !== $request->getHttpHeader('Content-Disposition')) {
             $this->packageName = substr($request->getHttpHeader('Content-Disposition'), 9);
         }
         // TODO see [RFC2183]
         $this->packageName = $filename;
         // Calculated MD5 check does not match the value provided by the client
         if (md5(file_get_contents($filename)) != $request->getHttpHeader('Content-MD5')) {
             return $this->generateResponse(412, 'error/ErrorChecksumMismatchSuccess', array('summary' => $this->context->i18n->__('Checksum sent does not match the calculated checksum')));
         }
         try {
             $extractor = qtPackageExtractorFactory::build($this->packageFormat, array('filename' => $filename, 'name' => $this->packageName, 'format' => $this->packageFormat, 'resource' => $this->resource, 'type' => $this->packageContentType));
         } catch (Exception $e) {
             return $this->generateResponse(415, 'error/ErrorContent', array('summary' => $e->getMessage()));
         }
         // Open package and XML document
         $extractor->extract();
         // Parse and create objects
         $extractor->process();
         $this->informationObject = $extractor->informationObject;
         // Remove temporary files
         $extractor->clean();
         return $this->generateResponse(201, 'deposit', array('headers' => array('Location' => $this->context->routing->generate(null, array($this->informationObject, 'module' => 'informationobject')))));
     } else {
         if ($request->isMethod('put') || $request->isMethod('delete')) {
             return $this->generateResponse(501, 'error/ErrorNotImplemented', array('summary' => $this->context->i18n->__('Not implemented')));
         } else {
             return $this->generateResponse(400, 'error/ErrorBadRequest', array('summary' => $this->context->i18n->__('Bad request')));
         }
     }
 }
コード例 #4
0
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = $this->getRoute()->resource;
     $criteria = new Criteria();
     $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
     $criteria->add(QubitRelation::TYPE_ID, QubitTerm::HAS_PHYSICAL_OBJECT_ID);
     $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
     $this->informationObjects = QubitInformationObject::get($criteria);
     $c2 = clone $criteria;
     $this->foundcount = BasePeer::doCount($c2)->fetchColumn(0);
 }
コード例 #5
0
 public function save($connection = null)
 {
     // TODO: $cleanObject = $this->object->clean;
     $cleanObjectId = $this->__get('objectId', array('clean' => true));
     parent::save($connection);
     if ($this->indexOnSave()) {
         if ($this->objectId != $cleanObjectId && null !== QubitInformationObject::getById($cleanObjectId)) {
             QubitSearch::updateInformationObject(QubitInformationObject::getById($cleanObjectId));
         }
         if ($this->object instanceof QubitInformationObject) {
             QubitSearch::updateInformationObject($this->object);
         }
     }
     return $this;
 }
コード例 #6
0
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
     $criteria = new Criteria();
     $criteria->add(QubitSlug::SLUG, $arguments['slug']);
     $criteria->addJoin(QubitSlug::OBJECT_ID, QubitObject::ID);
     $resource = QubitInformationObject::get($criteria)->__get(0);
     $publicationStatus = QubitTerm::getById($arguments['publicationStatusId']);
     // Check if the resource exists
     if (!isset($resource)) {
         throw new sfException('Resource not found');
     }
     // Check if the given status is correct and exists
     if (!isset($publicationStatus)) {
         throw new sfException('Publication status not found');
     }
     if (QubitTaxonomy::PUBLICATION_STATUS_ID != $publicationStatus->taxonomyId) {
         throw new sfException('Given term is not part of the publication status taxonomy');
     }
     // Final confirmation
     if (!$options['no-confirm']) {
         if (!$this->askConfirmation(array('Please, confirm that you want to change', 'the publication status of "' . $resource . '"', 'to "' . $publicationStatus . '" (y/N)'), 'QUESTION_LARGE', false)) {
             $this->logSection('tools', 'Bye!');
             return 1;
         }
     }
     // Start work
     $resource->setPublicationStatus($publicationStatus->id);
     $resource->save();
     echo '+';
     // Update pub status of descendants
     if (!$options['ignore-descendants']) {
         foreach ($resource->descendants as $descendant) {
             if (null === ($descendantPubStatus = $descendant->getPublicationStatus())) {
                 $descendantPubStatus = new QubitStatus();
                 $descendantPubStatus->typeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
                 $descendantPubStatus->objectId = $descendant->id;
             }
             if ($options['force'] || $publicationStatus->id != $descendantPubStatus->statusId) {
                 $descendantPubStatus->statusId = $publicationStatus->id;
                 $descendantPubStatus->save();
                 echo '^';
             }
         }
     }
     echo "\n";
 }
コード例 #7
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
 }
コード例 #8
0
 public function execute($request)
 {
     $this->resource = $request->getAttribute('sf_route')->resource;
     // Get tree (limit 10 siblings and children)
     $this->treeViewObjects = $this->resource->getFullYuiTree(10);
     // Check if tree view worth it
     if (1 > count($this->treeViewObjects)) {
         return sfView::NONE;
     }
     $this->treeViewExpands = array();
     foreach ($this->resource->ancestors->andSelf()->orderBy('lft') as $item) {
         $this->treeViewExpands[$item->id] = $item->id;
     }
     // Is it draggable?
     $this->treeViewDraggable = json_encode(QubitAcl::check(QubitInformationObject::getRoot(), 'update'));
 }
コード例 #9
0
 public function execute($request)
 {
     $this->requestname = $request;
     $request->setRequestFormat('xml');
     $this->date = gmdate('Y-m-d\\TH:i:s\\Z');
     $this->attributes = $request->getGetParameters();
     /*
      * If limit dates are not supplied, define them as ''
      */
     if (!isset($request->from)) {
         $this->from = '';
     } else {
         $this->from = $request->from;
     }
     if (!isset($request->until)) {
         $this->until = '';
     } else {
         $this->until = $request->until;
     }
     $this->collectionsTable = QubitOai::getCollectionArray();
     /*
      * If set is not supplied, define it as ''
      */
     if (!isset($request->set)) {
         $collection = '';
     } else {
         $collection = QubitOai::getCollectionInfo($request->set, $this->collectionsTable);
     }
     //Get the records according to the limit dates and collection
     $this->records = QubitInformationObject::getUpdatedRecords($this->from, $this->until, $collection);
     $this->publishedRecords = array();
     foreach ($this->records as $record) {
         if ($record->getPublicationStatus()->statusId == QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID) {
             $this->publishedRecords[] = $record;
         }
     }
     $this->recordsCount = count($this->publishedRecords);
     $this->path = $request->getUriPrefix() . $request->getPathInfo();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
 }
コード例 #10
0
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $oai_local_identifier_value = $request->identifier;
     //TODO: strip the trailing integer value from the full OAI Identifier to get the OaiLocalIdentifier
     $oai_local_identifier_id = QubitOai::getOaiIdNumber($oai_local_identifier_value);
     $this->informationObject = QubitInformationObject::getRecordByOaiID($oai_local_identifier_id);
     $request->setAttribute('informationObject', $this->informationObject);
     // just cut-and-paste from OaiIdentify action for now
     $this->date = gmdate('Y-m-d\\TH:i:s\\Z');
     $this->collectionsTable = QubitOai::getCollectionArray();
     $this->path = $request->getUriPrefix() . $request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
 }
コード例 #11
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     $request->setRequestFormat('xml');
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
     if (isset($this->request->verb)) {
         switch ($this->request->verb) {
             case 'Identify':
                 $this->verb = 'identify';
                 break;
             case 'ListMetadataFormats':
                 $this->verb = 'listMetadataFormats';
                 break;
             case 'ListSets':
                 $this->verb = 'listSets';
                 break;
             case 'ListRecords':
                 $this->verb = 'listRecords';
                 break;
             case 'ListIdentifiers':
                 $this->verb = 'listIdentifiers';
                 break;
             case 'GetRecord':
                 $this->verb = 'getRecord';
                 break;
             default:
                 $this->verb = 'badVerb';
         }
     } else {
         $this->verb = 'badVerb';
     }
 }
コード例 #12
0
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     $criteria = new Criteria();
     $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
     $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
     $this->informationObjects = QubitInformationObject::get($criteria);
     $this->form->setValidator('next', new sfValidatorString());
     $this->form->setWidget('next', new sfWidgetFormInputHidden());
     if ($request->isMethod('delete')) {
         $this->form->bind($request->getPostParameters());
         $this->resource->delete();
         $next = $this->form->getValue('next');
         if (isset($next)) {
             $this->redirect($next);
         }
         $this->redirect('@homepage');
     }
 }
コード例 #13
0
 public function execute($request)
 {
     parent::execute($request);
     $this->addFields();
     $this->title = $this->context->i18n->__('Global search/replace');
     if ($request->isMethod('post')) {
         // Make sure we have required information for search/replace
         if (empty($request->pattern) || empty($request->replacement)) {
             $this->error = $this->context->i18n->__('Both source and replacement fields are required.');
             return;
         } else {
             if (!isset($request->confirm)) {
                 $this->title = $this->context->i18n->__('Are you sure you want to replace "%1%" with "%2%" in %3%?', array('%1%' => $request->pattern, '%2%' => $request->replacement, '%3%' => sfInflector::humanize(sfInflector::underscore($request->column))));
                 return;
             }
         }
         // Process replacement on each IO
         // NB: could this be made faster by reading a batch of IDs?
         foreach ($this->pager->hits as $hit) {
             $io = QubitInformationObject::getById($hit->getDocument()->id);
             if (isset($request->allowRegex)) {
                 $pattern = '/' . strtr($request->pattern, array('/' => '\\/')) . '/';
                 if (!isset($request->caseSensitive)) {
                     $pattern .= 'i';
                 }
                 $replacement = strtr($request->replacement, array('/' => '\\/'));
                 $replaced = preg_replace($pattern, $replacement, $io->__get($request->column));
             } elseif (isset($request->caseSensitive)) {
                 $replaced = str_replace($request->pattern, $request->replacement, $io->__get($request->column));
             } else {
                 $replaced = str_ireplace($request->pattern, $request->replacement, $io->__get($request->column));
             }
             $io->__set($request->column, $replaced);
             $io->save();
         }
         // force refresh of index to keep sync
         QubitSearch::getInstance()->optimize();
         // When complete, redirect to GSR home
         $this->redirect(array('module' => 'search', 'action' => 'globalReplace'));
     }
 }
コード例 #14
0
 public function execute($request)
 {
     $this->version = '1.3';
     $this->verbose = 'false';
     $this->noOp = 'false';
     $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize() / 1024;
     // From bytes to kilobytes
     $this->mediation = 'false';
     // Should be based in auth + X-On-Behalf-Of
     if (isset($request->getAttribute('sf_route')->resource)) {
         $this->resource = $this->getRoute()->resource;
         $this->title = $this->resource->__toString();
         $this->workspaces = $this->resource->getChildren();
     } else {
         $this->title = sfConfig::get('app_siteTitle');
         $criteria = new Criteria();
         $criteria->add(QubitInformationObject::PARENT_ID, QubitInformationObject::ROOT_ID, Criteria::IN);
         $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
         $this->workspaces = QubitInformationObject::get($criteria);
     }
     $this->response->setHttpHeader('Content-Type', 'application/atom+xml; charset="utf-8"');
     $request->setRequestFormat('xml');
 }
コード例 #15
0
 public function generateReport($request)
 {
     // Get "file" term in "level of description" taxonomy
     $c2 = new Criteria();
     $c2->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN);
     $c2->add(QubitTermI18n::NAME, 'file');
     $c2->add(QubitTermI18n::CULTURE, 'en');
     $c2->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID);
     $lod = QubitTermI18n::getOne($c2);
     if (null === $lod) {
         throw new sfException('Can\'t find "file" level of description in term table');
     }
     $criteria = new Criteria();
     $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_EQUAL);
     $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_EQUAL);
     $criteria->addAscendingOrderByColumn(QubitInformationObject::LFT);
     // Filter drafts
     $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
     $this->results = array();
     $this->resultCount = 0;
     $informationObjects = QubitInformationObject::get($criteria);
     foreach ($informationObjects as $item) {
         if ($lod->id == $item->levelOfDescriptionId) {
             $parentIsad = new sfIsadPlugin($item->parent);
             $isad = new sfIsadPlugin($item);
             $creationDates = self::getCreationDates($item);
             $this->results[$parentIsad->__toString()][] = array('resource' => $item, 'referenceCode' => $isad->referenceCode, 'title' => $item->getTitle(array('cultureFallback' => true)), 'dates' => isset($creationDates) ? Qubit::renderDateStartEnd($creationDates->getDate(array('cultureFallback' => true)), $creationDates->startDate, $creationDates->endDate) : '&nbsp;', 'startDate' => isset($creationDates) ? $creationDates->startDate : null, 'accessConditions' => $item->getAccessConditions(array('cultureFallback' => true)), 'locations' => self::getLocationString($item));
             $this->resultCount++;
         }
     }
     // Sort items by selected criteria
     $sortBy = $this->form->getValue('sortBy');
     foreach ($this->results as $key => &$items) {
         uasort($items, function ($a, $b) use($sortBy) {
             return strnatcasecmp($a[$sortBy], $b[$sortBy]);
         });
     }
 }
コード例 #16
0
 public static function getinformationObjectsRelatedByparentIdById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addinformationObjectsRelatedByparentIdCriteriaById($criteria, $id);
     return QubitInformationObject::get($criteria, $options);
 }
コード例 #17
0
 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;
 }
コード例 #18
0
 /**
  * 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;
 }
コード例 #19
0
 public static function renderYuiNodes($tree, $options = array())
 {
     ProjectConfiguration::getActive()->loadHelpers(array('Qubit', 'Text', 'Escaping'));
     $yuiTree = array();
     foreach ($tree as $key => $item) {
         $node = array();
         if ($item instanceof QubitInformationObject) {
             $label = render_title(new sfIsadPlugin($item));
             $node['label'] = truncate_text($label, 50);
             if (50 < strlen($label)) {
                 $node['title'] = esc_specialchars($label);
             }
             $node['href'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'informationobject'));
             $node['id'] = $item->id;
             $node['parentId'] = $item->parentId;
             $node['isLeaf'] = (string) (!$item->hasChildren());
             $node['moveUrl'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'default', 'action' => 'move'));
             $node['expandUrl'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'informationobject', 'action' => 'treeView'));
             if (isset($options['currentNode']) && $options['currentNode'] === $item) {
                 $node['style'] = 'ygtvlabel currentTextNode';
             }
         } else {
             $count = intval($item['total']) - intval($item['limit']);
             $node['label'] = sfContext::getInstance()->i18n->__('+%1% ...', array('%1%' => $count));
             $node['parentId'] = $item['parentId'];
             $node['href'] = sfContext::getInstance()->routing->generate(null, array(QubitInformationObject::getById($item['parentId']), 'module' => 'informationobject', 'action' => 'browse'));
             $node['isLeaf'] = 'true';
             $node['style'] = 'seeAllNode';
         }
         $yuiTree[] = $node;
     }
     return $yuiTree;
 }
コード例 #20
0
 public function getResourceRelations()
 {
     $criteria = new Criteria();
     $criteria->addJoin(QubitInformationObject::ID, QubitEvent::INFORMATION_OBJECT_ID);
     $criteria->addGroupByColumn(QubitInformationObject::ID);
     $criteria->add(QubitEvent::ACTOR_ID, $this->id);
     return QubitInformationObject::get($criteria);
 }
コード例 #21
0
  <fieldset class="collapsible collapsed" id="informationObjectArea">

    <legend><?php 
echo __('Permissions by %1%', array('%1%' => sfConfig::get('app_ui_label_informationobject')));
?>
</legend>

    <?php 
if (0 < count($informationObjects)) {
    ?>
      <?php 
    foreach ($informationObjects as $informationObjectId => $permissions) {
        ?>
        <div class="form-item">
          <?php 
        echo get_component('aclGroup', 'aclTable', array('object' => QubitInformationObject::getById($informationObjectId), 'permissions' => $permissions, 'actions' => $basicActions));
        ?>
        </div>
      <?php 
    }
    ?>
    <?php 
}
?>

    <?php 
// Build dialog for adding new table
$tableTemplate = '<div class="form-item">';
$tableTemplate .= '<table id="acl_{objectId}">';
$tableTemplate .= '<caption/>';
$tableTemplate .= '<thead>';
コード例 #22
0
ファイル: dcTest.php プロジェクト: nurfiantara/ehri-ica-atom
$browser = new sfTestFunctional(new sfBrowser());
$email = rand() . '@example.com';
$password = rand();
$user = new QubitUser();
$user->email = $email;
$user->setPassword($password);
$user->save();
$relation = new QubitUserRoleRelation();
$relation->userId = $user->id;
$relation->roleId = QubitRole::ADMINISTRATOR_ID;
$relation->save();
$browser->post(';user/login', array('login' => array('email' => $email, 'password' => $password)));
$scopeAndContent = rand();
$identifier = rand();
$title = rand();
$informationObject = new QubitInformationObject();
$informationObject->parentId = QubitInformationObject::ROOT_ID;
$informationObject->scopeAndContent = $scopeAndContent;
$informationObject->identifier = $identifier;
$informationObject->title = $title;
$informationObject->save();
$browser->get('/' . $informationObject->id . ';dc?sf_format=xml');
$user->delete();
$informationObject->delete();
$doc = new DOMDocument();
$doc->loadXML($browser->getResponse()->getContent());
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
$browser->test()->is($xpath->evaluate('string(/*/dc:description)', $doc->documentElement), $scopeAndContent, 'description');
$browser->test()->is($xpath->evaluate('string(/*/dc:identifier)', $doc->documentElement), $identifier, 'identifier');
$browser->test()->is($xpath->evaluate('string(/*/dc:title)', $doc->documentElement), $title, 'title');
コード例 #23
0
 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();
 }
コード例 #24
0
<?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();
コード例 #25
0
 /**
  * Get a new criterion to filter a SQL query by ACL rules
  *
  * @param Criteria $criteria
  * @param mixed $root - root object for list
  * @return Criterion
  */
 public static function getFilterCriterion($criteria, $root, $action)
 {
     $user = sfContext::getInstance()->user;
     $rootClass = get_class($root);
     if ('createTerm' != $action) {
         $permissions = self::getUserPermissionsByAction($user, $rootClass, $action);
     } else {
         $permissions = self::getUserPermissionsByAction($user, 'QubitTerm', 'create');
     }
     // Build access control list
     $allows = $bans = $ids = array();
     $forceBan = false;
     if (0 < count($permissions)) {
         foreach ($permissions as $permission) {
             switch ($action) {
                 case 'createTerm':
                     if (null === ($id = $permission->getConstants(array('name' => 'taxonomyId')))) {
                         $ids[] = QubitTaxonomy::ROOT_ID;
                     }
                     break;
                 case 'viewDraft':
                     if (null !== ($repoId = $permission->getConstants(array('name' => 'repositoryId')))) {
                         $criteria2 = new Criteria();
                         $criteria2->add(QubitInformationObject::REPOSITORY_ID, $repoId);
                         if (0 < count($results = QubitInformationObject::get($criteria2))) {
                             foreach ($results as $item) {
                                 $ids[] = $item->id;
                             }
                             // Special case because isAllowed() on ROOT will return true if
                             // user has grant permission on ANY repository. This will force
                             // showing ONLY resources in allowed repositories
                             $forceBan = true;
                         }
                     }
                     break;
                 default:
                     $ids[] = $permission->objectId;
             }
         }
         foreach ($ids as $id) {
             if (!isset($resourceAccess[$id])) {
                 $resource = call_user_func(array($rootClass, 'getById'), $id);
                 $resourceAccess[$id] = self::isAllowed($user, $resource, $action);
                 if ($resourceAccess[$id]) {
                     $allows[] = $id;
                 } else {
                     $bans[] = $id;
                 }
             }
         }
     }
     // Special cases - avoid adding unnecessary criteria
     if (0 == count($allows) && !QubitAcl::isAllowed($user, $root, $action)) {
         return false;
         // No allows, always false
     } else {
         if (!$forceBan && 0 == count($bans) && QubitAcl::isAllowed($user, $root, $action)) {
             return true;
             // No bans, always true
         }
     }
     // If more allows then bans, then add list of allowed resources
     $criterion = null;
     if (count($allows) >= count($bans)) {
         while ($resourceId = array_shift($allows)) {
             $resource = call_user_func(array($rootClass, 'getById'), $resourceId);
             // If object has no children include it by id
             if (1 == $resource->rgt - $resource->lft) {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::ID"), $resourceId);
             } else {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::LFT"), $resource->lft, Criteria::GREATER_EQUAL);
                 $subCriterion2 = $criteria->getNewCriterion(constant("{$rootClass}::RGT"), $resource->rgt, Criteria::LESS_EQUAL);
                 $subCriterion->addAnd($subCriterion2);
             }
             if (isset($criterion)) {
                 $criterion->addOr($subCriterion);
             } else {
                 $criterion = $subCriterion;
             }
         }
     } else {
         while ($resourceId = array_shift($bans)) {
             $resource = call_user_func(array($rootClass, 'getById'), $resourceId);
             // If object has no children, remove it by id
             if (1 == $resource->rgt - $resource->lft) {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::ID"), $resourceId, Criteria::NOT_EQUAL);
             } else {
                 $subCriterion = $criteria->getNewCriterion(constant("{$rootClass}::LFT"), $resource->lft, Criteria::LESS_THAN);
                 $subCriterion2 = $criteria->getNewCriterion(constant("{$rootClass}::RGT"), $resource->rgt, Criteria::GREATER_THAN);
                 $subCriterion->addOr($subCriterion2);
             }
             if (isset($criterion)) {
                 $criterion->addAnd($subCriterion);
             } else {
                 $criterion = $subCriterion;
             }
         }
     }
     return $criterion;
 }
コード例 #26
0
                ?>
                  <em><?php 
                echo __('All %1%', array('%1%' => sfConfig::get('app_ui_label_informationobject')));
                ?>
</em>
                <?php 
            } elseif ('' != $repoId) {
                ?>
                  <?php 
                echo sfConfig::get('app_ui_label_repository') . ': ' . render_title(QubitRepository::getById($repoId));
                ?>
                <?php 
            } else {
                ?>
                  <?php 
                echo render_title(QubitInformationObject::getById($objectId));
                ?>
                <?php 
            }
            ?>
              </strong></td>
            </tr>
            <?php 
            $row = 0;
            ?>
            <?php 
            foreach ($actions as $action => $groupPermission) {
                ?>
              <tr class="<?php 
                echo 0 == @++$row % 2 ? 'even' : 'odd';
                ?>
コード例 #27
0
 public function execute($request)
 {
     // Default items per page
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     // Check that the object exists and that it is not the root
     if (!isset($this->resource) || !isset($this->resource->parent)) {
         $this->forward404();
     }
     // Check authorization
     if (!QubitAcl::check($this->resource, 'update')) {
         QubitAcl::forwardUnauthorized();
     }
     // "parent" form field
     $this->form->setValidator('parent', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('parent', new sfWidgetFormInputHidden());
     // Root is default parent
     if ($this->resource instanceof QubitInformationObject) {
         $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitInformationObject::getById(QubitInformationObject::ROOT_ID), 'module' => 'informationobject'))));
     } else {
         if ($this->resource instanceof QubitTerm) {
             $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitTerm::getById(QubitTerm::ROOT_ID), 'module' => 'term'))));
         }
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
             // In term treeview, root node links (href) to taxonomy, but it represents the term root object
             if ($this->resource instanceof QubitTerm && QubitObject::getById($params['_sf_route']->resource->id) instanceof QubitTaxonomy) {
                 $this->resource->parentId = QubitTerm::ROOT_ID;
             } else {
                 $this->resource->parentId = $params['_sf_route']->resource->id;
             }
             $this->resource->save();
             if ($request->isXmlHttpRequest()) {
                 return $this->renderText('');
             } else {
                 if ($this->resource instanceof QubitInformationObject) {
                     $this->redirect(array($this->resource, 'module' => 'informationobject'));
                 } else {
                     if ($this->resource instanceof QubitTerm) {
                         $this->redirect(array($this->resource, 'module' => 'term'));
                     }
                 }
             }
         }
     }
     $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
     $this->parent = QubitObject::getById($params['_sf_route']->resource->id);
     $query = QubitSearch::getInstance()->addTerm($this->parent->slug, 'parent');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $this->pager = new QubitArrayPager();
     $this->pager->hits = QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitObject::ID, $ids, Criteria::IN);
     $this->results = QubitObject::get($criteria);
 }
コード例 #28
0
 protected function updateChildLevels()
 {
     if (is_array($updateChildLevels = $this->request->updateChildLevels) && count($updateChildLevels)) {
         foreach ($updateChildLevels as $item) {
             $childLevel = new QubitInformationObject();
             $childLevel->identifier = $item['identifier'];
             $childLevel->title = $item['title'];
             if (null != ($pubStatus = $this->resource->getPublicationStatus())) {
                 $childLevel->setPublicationStatus($pubStatus->statusId);
             }
             if (0 < strlen($item['levelOfDescription']) && null !== QubitTerm::getById($item['levelOfDescription'])) {
                 $childLevel->levelOfDescriptionId = $item['levelOfDescription'];
             }
             if (0 < strlen($item['levelOfDescription']) || 0 < strlen($item['identifier']) || 0 < strlen($item['title'])) {
                 $this->resource->informationObjectsRelatedByparentId[] = $childLevel;
             }
         }
     }
 }
コード例 #29
0
 /**
  * @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.');
 }
コード例 #30
0
 /**
  * Executes action
  *
  * @param sfRequest $request A request object
  */
 public function execute($request)
 {
     // only respond to OAI requests if the feature has been enabled
     if (sfConfig::get('app_oai_oai_enabled') == 0) {
         // the following displays a GUI response, should we return a
         // '503 - Service unavailable' HTTP response (without specifying
         // a 'Retry-After' parameter instead?
         $this->forward('admin', 'oaiDisabled');
     }
     $request->setRequestFormat('xml');
     /*    print_r($this->oaiErrorArray);
         //Check for null and duplicate parameters
         if(QubitOai::hasDuplicateOrNullParameters())
         {
           $request->setParameter('errorCode', 'badArgument');
           $request->setParameter('errorMsg', $this->oaiErrorArray{'badArgument'});
           $this->forward('oai', 'error');
         }*/
     $this->date = QubitOai::getDate();
     $this->path = $this->request->getUriPrefix() . $this->request->getPathInfo();
     $this->attributes = $this->request->getGetParameters();
     $this->attributesKeys = array_keys($this->attributes);
     $this->requestAttributes = '';
     foreach ($this->attributesKeys as $key) {
         $this->requestAttributes .= ' ' . $key . '="' . $this->attributes[$key] . '"';
     }
     $this->sets = array();
     foreach (QubitInformationObject::getCollections() as $el) {
         $this->sets[] = new sfIsadPlugin($el);
     }
     /**
      * Validate that verb is valid
      */
     if (isset($this->request->verb)) {
         if (!in_array($this->request->verb, $this->oaiVerbArr)) {
             $request->setParameter('errorCode', 'badVerb');
             $request->setParameter('errorMsg', 'Value of the verb argument is not a legal OAI-PMH verb, the verb argument is missing, or the verb argument is repeated.');
             $this->forward('oai', 'error');
         }
         /**
          * Validate that attributes are valid
          */
         $allowedKeys = sfConfig::get('mod_oai_' . $this->request->verb . 'Allowed');
         $mandatoryKeys = sfConfig::get('mod_oai_' . $this->request->verb . 'Mandatory');
         if (!QubitOai::checkBadArgument($this->attributesKeys, $allowedKeys, $mandatoryKeys)) {
             $request->setParameter('errorCode', 'badArgument');
             $request->setParameter('errorMsg', 'The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.');
             $this->forward('oai', 'error');
         }
         // For now, if there is a metadataPrefix requested other than oai_dc, fail the request
         $metadataPrefix = $this->request->metadataPrefix;
         if ($metadataPrefix != '' and $metadataPrefix != 'oai_dc') {
             $request->setParameter('errorCode', 'badVerb');
             $request->setParameter('errorMsg', 'The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.');
             $this->forward('oai', 'error');
         }
         switch ($this->request->verb) {
             case 'Identify':
                 $this->verb = 'identify';
                 break;
             case 'ListMetadataFormats':
                 $this->verb = 'listMetadataFormats';
                 break;
             case 'ListSets':
                 $this->verb = 'listSets';
                 break;
             case 'ListRecords':
                 $this->verb = 'listRecords';
                 break;
             case 'ListIdentifiers':
                 $this->verb = 'listIdentifiers';
                 break;
             case 'GetRecord':
                 $this->verb = 'getRecord';
                 break;
             default:
                 $this->verb = 'badVerb';
         }
     } else {
         $this->verb = 'badVerb';
     }
 }