Skip to content

Commit

Permalink
Merge pull request #15 from thoth-pub/stable-3_4_0
Browse files Browse the repository at this point in the history
Release/v0.2.1.3
  • Loading branch information
thiagolepidus authored Oct 22, 2024
2 parents 3aa5d5e + c64d302 commit faa0c80
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
5 changes: 3 additions & 2 deletions classes/ThothRegister.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function addImprintField($hookName, $form)
$publishers = $thothClient->linkedPublishers();
$imprints = $thothClient->imprints(['publishers' => array_column($publishers, 'publisherId')]);

$imprintOptions = [['value' => '', 'label' => '']];
$imprintOptions = [];
foreach ($imprints as $imprint) {
$imprintOptions[] = [
'value' => $imprint['imprintId'],
Expand All @@ -91,7 +91,8 @@ public function addImprintField($hookName, $form)
'options' => $imprintOptions,
'required' => true,
'showWhen' => 'registerConfirmation',
'groupId' => 'default'
'groupId' => 'default',
'value' => $imprints[0]['imprintId'] ?? null
]));
} catch (ThothException $e) {
$warningIconHtml = '<span class="fa fa-exclamation-triangle pkpIcon--inline"></span>';
Expand Down
5 changes: 3 additions & 2 deletions classes/components/forms/RegisterForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($action, $imprints, $errors)
return;
}

$imprintOptions = [['value' => '', 'label' => '']];
$imprintOptions = [];
foreach ($imprints as $imprint) {
$imprintOptions[] = [
'value' => $imprint['imprintId'],
Expand Down Expand Up @@ -80,7 +80,8 @@ public function __construct($action, $imprints, $errors)
'label' => __('plugins.generic.thoth.imprint'),
'options' => $imprintOptions,
'required' => true,
'groupId' => 'default'
'groupId' => 'default',
'value' => $imprints[0]['imprintId'] ?? null
]));
}

Expand Down
25 changes: 24 additions & 1 deletion classes/services/ThothPublicationService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,33 @@ public function getIsbnByPublicationFormat($publicationFormat)
$identificationCodes = $publicationFormat->getIdentificationCodes()->toArray();
foreach ($identificationCodes as $identificationCode) {
if ($identificationCode->getCode() == '15' || $identificationCode->getCode() == '24') {
return $identificationCode->getValue();
$isbn = $identificationCode->getValue();
return $this->convertToIsbn13($isbn);
}
}

return null;
}

public function convertToIsbn13($isbnString)
{
if (preg_match('/(?=.{17}$)97(?:8|9)([ -])\d{1,5}\1\d{1,7}\1\d{1,6}\1\d$/', $isbnString)) {
return $isbnString;
}

$isbnNumber = preg_replace('/\D/', '', $isbnString);

if (strlen($isbnNumber) != 13) {
return $isbnString;
}

return sprintf(
'%s-%s-%s-%s-%s',
substr($isbnNumber, 0, 3),
substr($isbnNumber, 3, 1),
substr($isbnNumber, 4, 2),
substr($isbnNumber, 6, 6),
substr($isbnNumber, 12, 1)
);
}
}
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<version>
<application>thoth</application>
<type>plugins.generic</type>
<release>0.2.1.2</release>
<date>2024-10-21</date>
<release>0.2.1.3</release>
<date>2024-10-22</date>
<lazy-load>1</lazy-load>
<class>ThothPlugin</class>
</version>

0 comments on commit faa0c80

Please sign in to comment.