Skip to content

Commit

Permalink
Merge pull request #23 from OPUS4/4.6.3
Browse files Browse the repository at this point in the history
Merge 4.6.3 changes into master
  • Loading branch information
j3nsch authored Apr 11, 2018
2 parents f9d0d93 + 1e0d41e commit b38fb11
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 139 deletions.
61 changes: 61 additions & 0 deletions library/Opus/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -1298,4 +1298,65 @@ public function isOpenAccess()
}
}

/**
* @param null $key Index or key name
* @return mixed|null
* @throws Opus_Model_Exception
* @throws Opus_Security_Exception
*/
public function getEnrichment($key = null)
{
if (is_null($key) || is_numeric($key)) {
return $this->__call('getEnrichment', [$key]);
} else {
$enrichments = $this->__call('getEnrichment', []);

$matches = array_filter($enrichments, function ($enrichment) use ($key) {
return $enrichment->getKeyName() == $key;
});

switch (count($matches)) {
case 0:
return null;

case 1:
return $matches[0];

default:
return $matches;
}
}
}

/**
* Returns the value of an enrichment key
*
* @param $key Name of enrichment
* @return mixed
* @throws Opus_Model_Exception If the enrichment key does not exist
* @throws Opus_Security_Exception
*/
public function getEnrichmentValue($key)
{
$enrichment = $this->getEnrichment($key);

if (!is_null($enrichment)) {
if (is_array($enrichment)) {
return array_map(function($value) {
return $value->getValue();
}, $enrichment);
} else {
return $enrichment->getValue();
}
}
else {
$enrichmentKey = Opus_EnrichmentKey::fetchByName($key);

if (is_null($enrichmentKey)) {
throw new Opus_Model_Exception('unknown enrichment key');
} else {
return null;
}
}
}
}
17 changes: 12 additions & 5 deletions library/Opus/Enrichment.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Pascal-Nicolas Becker <[email protected]>
* @author Gunar Maiwald <[email protected]>
* @author Jens Schwidder <[email protected]>
* @copyright Copyright (c) 2008-2017, OPUS 4 development team
* @copyright Copyright (c) 2008-2018, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

Expand All @@ -40,8 +40,15 @@
* @category Framework
* @package Opus
* @uses Opus_Model_Abstract
*
* @method setKeyName(string $name)
* @method string getKeyName()
* @method setValue(string $value)
* @method string getValue()
*/
class Opus_Enrichment extends Opus_Model_Dependent_Abstract {
class Opus_Enrichment extends Opus_Model_Dependent_Abstract
{

/**
* Primary key of the parent model.
*
Expand All @@ -63,16 +70,16 @@ class Opus_Enrichment extends Opus_Model_Dependent_Abstract {
*
* @return void
*/
protected function _init() {
protected function _init()
{
$key = new Opus_Model_Field('KeyName');
$key->setMandatory(true)->setValidator(new Zend_Validate_NotEmpty());

$value = new Opus_Model_Field('Value');
$value->setMandatory(true)
->setValidator(new Zend_Validate_NotEmpty());
->setValidator(new Zend_Validate_NotEmpty());

$this->addField($key);
$this->addField($value);
}

}
27 changes: 18 additions & 9 deletions library/Opus/EnrichmentKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @category Framework
* @package Opus
* @author Gunar Maiwald <[email protected]>
* @copyright Copyright (c) 2011, OPUS 4 development team
* @author Jens Schwidder <[email protected]>
* @copyright Copyright (c) 2011-2018, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
* @version $Id$
*/

/**
Expand All @@ -38,8 +38,13 @@
* @category Framework
* @package Opus
* @uses Opus_Model_Abstract
*
* @method setName(string $string)
* @method string getName()
*/
class Opus_EnrichmentKey extends Opus_Model_AbstractDb {
class Opus_EnrichmentKey extends Opus_Model_AbstractDb
{

/**
* Specify the table gateway.
*
Expand All @@ -52,7 +57,8 @@ class Opus_EnrichmentKey extends Opus_Model_AbstractDb {
*
* @return array Array of Opus_EnrichmentKeys objects.
*/
public static function getAll() {
public static function getAll()
{
return self::getAllFrom('Opus_EnrichmentKey', 'Opus_Db_EnrichmentKeys');
}

Expand All @@ -62,7 +68,8 @@ public static function getAll() {
*
* @return void
*/
protected function _init() {
protected function _init()
{
$name = new Opus_Model_Field('Name');
$name->setMandatory(true)
->setValidator(new Zend_Validate_NotEmpty());
Expand All @@ -77,7 +84,8 @@ protected function _init() {
* @param string $name
* @return Opus_EnrichmentKey
*/
public static function fetchByName($name = null) {
public static function fetchByName($name = null)
{
if (false === isset($name)) {
return;
}
Expand All @@ -98,7 +106,8 @@ public static function fetchByName($name = null) {
*
* @see library/Opus/Model/Opus_Model_Abstract#getDisplayName()
*/
public function getDisplayName() {
public function getDisplayName()
{
return $this->getName();
}

Expand All @@ -107,13 +116,13 @@ public function getDisplayName() {
*
* @return array Array of Opus_EnrichmentKeys objects.
*/
public static function getAllReferenced() {
public static function getAllReferenced()
{
$table = Opus_Db_TableGateway::getInstance('Opus_Db_DocumentEnrichments');
$db = $table->getAdapter();
$select = $db->select()->from(array('document_enrichments'));
$select->reset('columns');
$select->columns("key_name")->distinct(true);
return $db->fetchCol($select);
}

}
4 changes: 2 additions & 2 deletions library/Opus/Validate/Isbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class Opus_Validate_Isbn extends Zend_Validate_Abstract {
* @var array
*/
protected $_messageTemplates = array(
self::MSG_CHECK_DIGIT => "The check digit of '%value%' is not valid",
self::MSG_FORM => "'%value%' is malformed"
self::MSG_CHECK_DIGIT => "The check digit of '%value%' is not valid.",
self::MSG_FORM => "'%value%' is malformed."
);

/**
Expand Down
4 changes: 2 additions & 2 deletions library/Opus/Validate/Issn.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Opus_Validate_Issn extends Zend_Validate_Abstract
* @var array
*/
protected $_messageTemplates = array(
self::MSG_CHECK_DIGIT => "The check digit of '%value%' is not valid",
self::MSG_FORM => "'%value%' is malformed"
self::MSG_CHECK_DIGIT => "The check digit of '%value%' is not valid.",
self::MSG_FORM => "'%value%' is malformed."
);

/**
Expand Down
Loading

0 comments on commit b38fb11

Please sign in to comment.