public function setUp()
 {
     parent::setUp();
     $document = $this->createTestDocument();
     $document->setServerState('unpublished');
     $document->setPersonReferee(array());
     $document->setEnrichment(array());
     $this->documentId = $document->store();
     $document = new Opus_Document($this->documentId);
     $this->assertEquals(0, count($document->getPersonReferee()));
     $this->assertEquals(0, count($document->getEnrichment()));
 }
Beispiel #2
0
 /**
  * Add the given (key,value) to the documents enrichments.
  *
  * @param mixed $key
  * @param mixed $value
  * @return Matheon_Model_Document Fluent interface.
  */
 public function storeEnrichmentKeyValue($key, $value)
 {
     foreach ($this->_document->getEnrichment() as $e) {
         if ($e->getKeyName() == $key) {
             if ($e->getValue() == $value) {
                 return $this;
             }
         }
     }
     $this->_document->addEnrichment()->setKeyName($key)->setValue($value);
     return $this;
 }
Beispiel #3
0
 public function testStoreEnrichmentKeyValueSkipDuplicate()
 {
     $doc = $this->createTestDocument();
     $docId = $doc->store();
     $this->assertEquals(0, count($doc->getEnrichment()));
     $mmd = new Matheon_Model_Document($docId);
     $mmd->storeEnrichmentKeyValue('reviewer.user_id', 123);
     $mmd->storeEnrichmentKeyValue('reviewer.user_id', 124);
     $mmd->storeEnrichmentKeyValue('reviewer.user_id', 123);
     $mmd->store();
     $doc = new Opus_Document($docId);
     $this->assertEquals(2, count($doc->getEnrichment()));
 }
Beispiel #4
0
 public function getSubmitter()
 {
     $return = array();
     foreach ($this->document->getEnrichment() as $e) {
         if ($e->getKeyName() != 'submitter.user_id') {
             continue;
         }
         $user_id = $e->getValue();
         $account = new Opus_Account($user_id);
         $return[$account->getId()] = strtolower($account->getLogin());
     }
     return $return;
 }
 public function testGetModel()
 {
     $form = new Admin_Form_Document_Enrichment();
     $document = new Opus_Document(146);
     $enrichments = $document->getEnrichment();
     $enrichment = $enrichments[0];
     $keyNames = $enrichment->getField('KeyName')->getDefault();
     $keyName = $keyNames[1]->getName();
     // Geht davon aus, dass mindestens 2 Enrichment Keys existieren
     $form->getElement('Id')->setValue($enrichment->getId());
     $form->getElement('KeyName')->setValue($keyName);
     $form->getElement('Value')->setValue('Test Enrichment Value');
     $model = $form->getModel();
     $this->assertEquals($enrichment->getId(), $model->getId());
     $this->assertEquals($keyName, $model->getKeyName());
     $this->assertEquals('Test Enrichment Value', $model->getValue());
 }
 public function testRejectDocumentWoPerson()
 {
     $helper = new Review_Model_ClearDocumentsHelper();
     $helper->reject(array($this->documentId), 23);
     $document = new Opus_Document($this->documentId);
     $this->assertNotEquals('published', $document->getServerState());
     $this->assertEquals(0, count($document->getPersonReferee()));
     $enrichments = $document->getEnrichment();
     $this->assertEquals(1, count($enrichments));
     $this->assertEquals(23, $enrichments[0]->getValue());
 }
    exit;
} else {
    $enrichmentField = $options['enrichment'];
}
$getType = 'getTitle' . ucfirst(strtolower($options['type']));
$addType = 'addTitle' . ucfirst(strtolower($options['type']));
if ($dryrun) {
    _log("TEST RUN: NO DATA WILL BE MODIFIED");
}
$docFinder = new Opus_DocumentFinder();
$docIds = $docFinder->setEnrichmentKeyExists($enrichmentField)->ids();
_log(count($docIds) . " documents found");
foreach ($docIds as $docId) {
    $doc = new Opus_Document($docId);
    if ($doc->getType() == $doctype || $doctype == '') {
        $enrichments = $doc->getEnrichment();
        foreach ($enrichments as $enrichment) {
            $enrichmentArray = $enrichment->toArray();
            if ($enrichmentArray['KeyName'] == $enrichmentField) {
                $titles = $doc->{$getType}();
                if (count($titles) > 0) {
                    _log('Title ' . ucfirst(strtolower($options['type'])) . ' already exists for Document #' . $docId . '. Skipping.. ');
                } else {
                    $title = $doc->{$addType}();
                    $title->setValue($enrichmentArray['Value']);
                    if (!$dryrun) {
                        $doc->store();
                    }
                    _log('Document #' . $docId . ' updated');
                }
            }