Skip to content

Commit 18e8526

Browse files
Merge pull request #27 from lepidus/stable-3_3_0
Feature/added work type selection (OMP 3.3.0)
2 parents df5bd1d + c99ab95 commit 18e8526

14 files changed

Lines changed: 110 additions & 24 deletions

File tree

classes/api/ThothEndpoint.inc.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ public function register($slimRequest, $response, $args)
5151
$submission = $handler->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
5252
$params = $slimRequest->getParsedBody();
5353

54-
if (empty($params['imprint'])) {
55-
return $response->withStatus(400)->withJson(['imprint' => [__('plugins.generic.thoth.imprint.required')]]);
54+
$thothImprintId = $params['thothImprintId'];
55+
if (!$thothImprintId) {
56+
return $response->withStatus(400)->withJson(
57+
['thothImprintId' => [__('plugins.generic.thoth.imprint.required')]]
58+
);
5659
}
5760

5861
if (!$submission) {
@@ -86,9 +89,9 @@ public function register($slimRequest, $response, $args)
8689

8790
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
8891

89-
$disableNotification = $params['disableNotification'];
92+
$disableNotification = $params['disableNotification'] ?? false;
9093
try {
91-
$thothBookId = ThothService::book()->register($publication, $params['imprint']);
94+
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
9295
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
9396
$this->handleNotification($request, $submission, true, $disableNotification);
9497
} catch (QueryException $e) {

classes/components/forms/RegisterForm.inc.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
use PKP\components\forms\FieldHTML;
2121
use PKP\components\forms\FieldSelect;
2222
use PKP\components\forms\FormComponent;
23+
use ThothApi\GraphQL\Models\Work as ThothWork;
2324

2425
class RegisterForm extends FormComponent
2526
{
2627
public $id = 'register';
2728

2829
public $method = 'PUT';
2930

30-
public function __construct($action, $imprints, $errors)
31+
public function __construct($action, $imprints, $workType, $errors)
3132
{
3233
$this->action = $action;
3334

@@ -80,13 +81,32 @@ public function __construct($action, $imprints, $errors)
8081
'description' => $msg,
8182
'groupId' => 'default',
8283
]))
83-
->addField(new FieldSelect('imprint', [
84+
->addField(new FieldSelect('thothImprintId', [
8485
'label' => __('plugins.generic.thoth.imprint'),
8586
'options' => $imprintOptions,
8687
'required' => true,
8788
'groupId' => 'default',
8889
'value' => $imprintOptions[0]['value'] ?? null
8990
]));
91+
92+
$workTypeOptions = [
93+
[
94+
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
95+
'label' => __('plugins.generic.thoth.workType.monograph')
96+
],
97+
[
98+
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
99+
'label' => __('plugins.generic.thoth.workType.textbook')
100+
],
101+
];
102+
103+
$this->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
104+
'label' => __('plugins.generic.thoth.workType'),
105+
'options' => $workTypeOptions,
106+
'required' => true,
107+
'groupId' => 'default',
108+
'value' => $workTypeOptions[0]['value'] ?? null
109+
]));
90110
}
91111

92112
public function getOptions($list)

classes/components/forms/config/PublishFormConfig.inc.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @brief Thoth config for publish form
1414
*/
1515

16+
use ThothApi\GraphQL\Models\Work as ThothWork;
17+
1618
import('plugins.generic.thoth.classes.facades.ThothService');
1719
import('plugins.generic.thoth.classes.facades.ThothRepo');
1820

@@ -48,12 +50,12 @@ public function addConfig($hookName, $form)
4850
return false;
4951
}
5052

51-
$this->addFields($form, $imprints);
53+
$this->addFields($form, $imprints, $submission->getData('workType'));
5254

5355
return false;
5456
}
5557

56-
private function addFields($form, $imprints)
58+
private function addFields($form, $imprints, $workType)
5759
{
5860
$imprintOptions = [];
5961
foreach ($imprints as $imprint) {
@@ -71,14 +73,38 @@ private function addFields($form, $imprints)
7173
'value' => false,
7274
'groupId' => 'default',
7375
]))
74-
->addField(new \PKP\components\forms\FieldSelect('imprint', [
76+
->addField(new \PKP\components\forms\FieldSelect('thothImprintId', [
7577
'label' => __('plugins.generic.thoth.imprint'),
7678
'options' => $imprintOptions,
7779
'required' => true,
7880
'showWhen' => 'registerConfirmation',
7981
'groupId' => 'default',
8082
'value' => $imprintOptions[0]['value'] ?? null
8183
]));
84+
85+
if ($workType !== WORK_TYPE_AUTHORED_WORK) {
86+
return;
87+
}
88+
89+
$workTypeOptions = [
90+
[
91+
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
92+
'label' => __('plugins.generic.thoth.workType.monograph')
93+
],
94+
[
95+
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
96+
'label' => __('plugins.generic.thoth.workType.textbook')
97+
],
98+
];
99+
100+
$form->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
101+
'label' => __('plugins.generic.thoth.workType'),
102+
'options' => $workTypeOptions,
103+
'required' => true,
104+
'showWhen' => 'registerConfirmation',
105+
'groupId' => 'default',
106+
'value' => $workTypeOptions[0]['value'] ?? null
107+
]));
82108
}
83109

84110
private function showErrors($form, $errors)

classes/factories/ThothBookFactory.inc.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ public function createFromPublication($publication)
2626
$request = Application::get()->getRequest();
2727
$submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId'));
2828
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
29+
$thothWorkType = $request->getUserVar('thothWorkType');
2930

3031
return new ThothWork([
31-
'workType' => $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
32-
'workStatus' => ThothWork::WORK_STATUS_ACTIVE,
32+
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
33+
'workStatus' => empty($publication->getData('datePublished'))
34+
? ThothWork::WORK_STATUS_FORTHCOMING
35+
: ThothWork::WORK_STATUS_ACTIVE,
3336
'fullTitle' => $publication->getLocalizedFullTitle(),
3437
'title' => $publication->getLocalizedTitle(),
3538
'subtitle' => $publication->getLocalizedData('subtitle'),

classes/factories/ThothChapterFactory.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public function createFromChapter($chapter)
3030

3131
return new ThothWork([
3232
'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER,
33-
'workStatus' => ThothWork::WORK_STATUS_ACTIVE,
33+
'workStatus' => (empty($chapter->getDatePublished()) && empty($publication->getData('datePublished')))
34+
? ThothWork::WORK_STATUS_FORTHCOMING
35+
: ThothWork::WORK_STATUS_ACTIVE,
3436
'fullTitle' => $chapter->getLocalizedFullTitle(),
3537
'title' => $chapter->getLocalizedTitle(),
3638
'subtitle' => $chapter->getLocalizedData('subtitle'),

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function validate($hookName, $args)
2929
return;
3030
}
3131

32-
$imprint = $request->getUserVar('imprint');
33-
if (empty($imprint)) {
34-
$errors['imprint'] = [__('plugins.generic.thoth.imprint.required')];
32+
$thothImprintId = $request->getUserVar('thothImprintId');
33+
if (empty($thothImprintId)) {
34+
$errors['thothImprintId'] = [__('plugins.generic.thoth.imprint.required')];
3535
}
3636
}
3737

@@ -50,10 +50,10 @@ public function registerThothBook($hookName, $args)
5050
return false;
5151
}
5252

53-
$imprint = $request->getUserVar('imprint');
53+
$thothImprintId = $request->getUserVar('thothImprintId');
5454
$thothNotification = new ThothNotification();
5555
try {
56-
$thothBookId = ThothService::book()->register($publication, $imprint);
56+
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
5757
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
5858
$thothNotification->notifySuccess($request, $submission);
5959
} catch (QueryException $e) {

classes/services/ThothBookService.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public function validate($publication)
7777

7878
if ($landingPage = $thothBook->getLandingPage()) {
7979
$retrievedThothBook = $this->repository->find($landingPage);
80-
if ($retrievedThothBook !== null) {
80+
if (
81+
$retrievedThothBook !== null
82+
&& $retrievedThothBook->getLandingPage() === $landingPage
83+
) {
8184
$errors[] = __(
8285
'plugins.generic.thoth.validation.landingPageExists',
8386
['landingPage' => $landingPage]

controllers/modal/RegisterHandler.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function register($args, $request)
8383
);
8484

8585
$imprints = [];
86-
86+
$workType = $this->submission->getData('workType');
8787
try {
8888
$errors = ThothService::book()->validate($this->publication);
8989

@@ -97,7 +97,7 @@ public function register($args, $request)
9797
}
9898

9999
$plugin->import('classes.components.forms.RegisterForm');
100-
$registerForm = new RegisterForm($publicationApiUrl, $imprints, $errors);
100+
$registerForm = new RegisterForm($publicationApiUrl, $imprints, $workType, $errors);
101101

102102
$settingsData = [
103103
'components' => [

js/ui/components/ListPanel/ThothListPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pkp.Vue.component('thoth-list-panel', {
297297
'X-Http-Method-Override': 'PUT',
298298
},
299299
data: {
300-
imprint: this.selectedImprint,
300+
thothImprintId: this.selectedImprint,
301301
disableNotification: true
302302
},
303303
success: (response) => this.updateItem(response),

locale/en_US/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "Your site administrator must set a secret in the config file ('api_key_s
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Thoth credentials not configured."
3333

34+
msgid "plugins.generic.thoth.workType"
35+
msgstr "Work Type"
36+
37+
msgid "plugins.generic.thoth.workType.monograph"
38+
msgstr "Monograph"
39+
40+
msgid "plugins.generic.thoth.workType.textbook"
41+
msgstr "Textbook"
42+
3443
msgid "plugins.generic.thoth.thothBook"
3544
msgstr "Thoth Book: "
3645

0 commit comments

Comments
 (0)