Skip to content

Commit

Permalink
#43 AddKeyword support type and lang
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Sep 7, 2023
1 parent 9d21aec commit bbea378
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Rules/AddKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@
use Opus\Common\Subject;
use Opus\Common\SubjectInterface;

use function is_array;

/**
* TODO logging, error handling
* TODO allow configuring type and language
*/
class AddKeyword extends AbstractImportRule
{
/** @var SubjectInterface */
private $subject;

/** @var string */
private $subjectType = Subject::TYPE_UNCONTROLLED;

/** @var string */
private $language = 'deu';

/**
* @param array $options
*/
Expand All @@ -51,10 +60,23 @@ public function setOptions($options)
parent::setOptions($options);

if (isset($options['keyword'])) {
$subject = Subject::new();
$subject->setValue($options['keyword']);
$subject->setType(Subject::TYPE_UNCONTROLLED);
$this->subject = $subject;
$config = $options['keyword'];

if (is_array($config)) {
$keyword = $config['value'] ?? null;
$this->subjectType = $config['type'] ?? Subject::TYPE_UNCONTROLLED;
$this->language = $config['lang'] ?? 'deu';
} else {
$keyword = $config;
}

if (! empty($keyword)) {
$subject = Subject::new();
$subject->setValue($keyword);
$subject->setType($this->subjectType);
$subject->setLanguage($this->language);
$this->subject = $subject;
}
}
}

Expand Down

0 comments on commit bbea378

Please sign in to comment.