Skip to content

Commit adccf9e

Browse files
ajnygabozana
authored andcommitted
pkp/pkp-lib#7165 Issue datePublished can be set when adding an issue
1 parent 8a4ae79 commit adccf9e

File tree

6 files changed

+79
-31
lines changed

6 files changed

+79
-31
lines changed

classes/controllers/grid/issues/IssueGridHandler.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @defgroup controllers_grid_issues Issues Grid
45
* The Issues Grid implements the management interface allowing editors to
@@ -560,7 +561,11 @@ public function publishIssue($args, $request)
560561
}
561562

562563
$issue->setPublished(1);
563-
$issue->setDatePublished(Core::getCurrentDate());
564+
565+
// If no datePublished was given, use current date
566+
if (!$issue->getData('datePublished')) {
567+
$issue->setDatePublished(Core::getCurrentDate());
568+
}
564569

565570
// If subscriptions with delayed open access are enabled then
566571
// update open access date according to open access delay policy
@@ -602,6 +607,9 @@ public function publishIssue($args, $request)
602607

603608
foreach ($publications as $publication) { /** @var Publication $publication */
604609
if ($publication->getData('status') === Submission::STATUS_SCHEDULED && $publication->getData('issueId') === (int) $issue->getId()) {
610+
if (!$publication->getData('datePublished')) {
611+
$publication->setData('datePublished', $issue->getData('datePublished'));
612+
}
605613
Repo::publication()->publish($publication);
606614
}
607615
}
@@ -676,11 +684,8 @@ public function unpublishIssue($args, $request)
676684
return new JSONMessage(false);
677685
}
678686

679-
// NB: Data set via params because setData('datePublished', null)
680-
// removes the entry into _data rather than updating 'datePublished' to null.
681687
$updateParams = [
682-
'published' => 0,
683-
'datePublished' => null
688+
'published' => 0
684689
];
685690

686691
Hook::call('IssueGridHandler::unpublishIssue', [&$issue]);

classes/publication/Repository.php

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @file classes/publication/Repository.php
45
*
@@ -151,24 +152,33 @@ public function version(Publication $publication): int
151152
return $newId;
152153
}
153154

154-
/** @copydoc \PKP\publication\Repository::setStatusOnPublish() */
155+
/**
156+
* Set the publication status and datePublished on publish
157+
*
158+
* When an issue is published, any attached publications inherit the
159+
* issue's `datePublished` in IssueGridHandler if they do not already
160+
* have a specific publication date set.
161+
*
162+
* - If the issue is **not published**, the publication status is set to `STATUS_SCHEDULED`.
163+
* - If the issue is **published** or there is no issue, the status is set to `STATUS_PUBLISHED`.
164+
* - If the publication does not have a `datePublished`, it is set to the current date.
165+
*/
155166
protected function setStatusOnPublish(Publication $publication)
156167
{
157-
// A publication may be scheduled in a future issue. In such cases,
158-
// the `datePublished` should remain empty and the status should be set to
159-
// scheduled.
160-
//
161-
// If there is no assigned issue, the journal may be using a continuous
162-
// publishing model in which articles are published right away.
163168
$issue = Repo::issue()->get($publication->getData('issueId'));
169+
170+
// If issue is not published just set publication status to STATUS_SCHEDULED
164171
if ($issue && !$issue->getData('published')) {
165-
$publication->setData('datePublished', null);
166172
$publication->setData('status', Submission::STATUS_SCHEDULED);
167-
} else {
168-
$publication->setData('status', Submission::STATUS_PUBLISHED);
169-
if (!$publication->getData('datePublished')) {
170-
$publication->setData('datePublished', Core::getCurrentDate());
171-
}
173+
return;
174+
}
175+
176+
// If issue is published or no issue, set publication status to STATUS_PUBLISHED
177+
$publication->setData('status', Submission::STATUS_PUBLISHED);
178+
179+
// If no predefined datePublished available for the publication, use current date
180+
if (!$publication->getData('datePublished')) {
181+
$publication->setData('datePublished', Core::getCurrentDate());
172182
}
173183
}
174184

controllers/grid/issues/IssueGridRow.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ public function initialize($request, $template = null)
6363
$dispatcher = $request->getDispatcher();
6464
$this->addAction(
6565
new LinkAction(
66-
$issue->getDatePublished() ? 'viewIssue' : 'previewIssue',
66+
$issue->getPublished() ? 'viewIssue' : 'previewIssue',
6767
new OpenWindowAction(
6868
$dispatcher->url($request, PKPApplication::ROUTE_PAGE, null, 'issue', 'view', [$issueId])
6969
),
70-
__($issue->getDatePublished() ? 'grid.action.viewIssue' : 'grid.action.previewIssue'),
70+
__($issue->getPublished() ? 'grid.action.viewIssue' : 'grid.action.previewIssue'),
7171
'information'
7272
)
7373
);
7474

75-
if ($issue->getDatePublished()) {
75+
if ($issue->getPublished()) {
7676
$this->addAction(
7777
new LinkAction(
7878
'unpublish',
@@ -110,7 +110,7 @@ public function initialize($request, $template = null)
110110

111111
$currentIssue = Repo::issue()->getCurrent($issue->getJournalId());
112112
$isCurrentIssue = $currentIssue != null && $issue->getId() == $currentIssue->getId();
113-
if ($issue->getDatePublished() && !$isCurrentIssue) {
113+
if ($issue->getPublished() && !$isCurrentIssue) {
114114
$this->addAction(
115115
new LinkAction(
116116
'setCurrentIssue',

controllers/grid/issues/form/IssueForm.php

+27-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use PKP\linkAction\LinkAction;
3131
use PKP\linkAction\request\RemoteActionConfirmationModal;
3232
use PKP\plugins\Hook;
33+
use PKP\validation\ValidatorFactory;
3334

3435
class IssueForm extends Form
3536
{
@@ -60,6 +61,7 @@ public function __construct($issue = null)
6061
return !$showTitle || implode('', $form->getData('title')) != '' ? true : false;
6162
}));
6263
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));
64+
6365
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
6466
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
6567
$this->issue = $issue;
@@ -143,6 +145,27 @@ public function validate($callHooks = true)
143145
}
144146
}
145147

148+
// Note! The following datePublished validation is not triggered
149+
// when JQuery DatePicker is enabled in the datePublished field.
150+
// The datePicker will convert any invalid date into a valid yyyy-mm-dd
151+
// date before the form data is submitted.
152+
153+
if ($this->getData('datePublished')) {
154+
$validator = ValidatorFactory::make(
155+
['value' => $this->getData('datePublished')],
156+
['value' => ['required', 'date_format:Y-m-d']]
157+
);
158+
159+
if (!$validator->passes()) {
160+
$this->addError('datePublished', __('editor.issues.datePublished.invalid'));
161+
$this->addErrorField('datePublished');
162+
}
163+
} elseif ($this->issue?->getPublished()) {
164+
// A published issue must have a published date
165+
$this->addError('datePublished', __('editor.issues.datePublished.requiredWhenPublished'));
166+
$this->addErrorField('datePublished');
167+
}
168+
146169
return parent::validate($callHooks);
147170
}
148171

@@ -243,9 +266,10 @@ public function execute(...$functionArgs)
243266
$issue->setVolume(empty($volume) ? null : $volume);
244267
$issue->setNumber(empty($number) ? null : $number);
245268
$issue->setYear(empty($year) ? null : $year);
246-
if (!$isNewIssue) {
247-
$issue->setDatePublished($this->getData('datePublished'));
248-
}
269+
270+
// If issue is not published, allow empty datePublished
271+
$issue->setDatePublished(!$this->getData('datePublished') && !$issue->getPublished() ? null : $this->getData('datePublished'));
272+
249273
$issue->setDescription($this->getData('description'), null); // Localized
250274
$issue->setShowVolume((int) $this->getData('showVolume'));
251275
$issue->setShowNumber((int) $this->getData('showNumber'));

locale/en/editor.po

+9
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ msgstr "Unpublished"
120120
msgid "editor.issues.datePublished"
121121
msgstr "Date Published"
122122

123+
msgid "editor.issues.datePublished.notPublished.description"
124+
msgstr "If left empty, the date will be set automatically when the issue is published."
125+
126+
msgid "editor.issues.datePublished.invalid"
127+
msgstr "Date Published is not valid. The date must be in the format YYYY-MM-DD."
128+
129+
msgid "editor.issues.datePublished.requiredWhenPublished"
130+
msgstr "Date Published is required when the issue is published."
131+
123132
msgid "editor.issues.volumeRequired"
124133
msgstr "Volume is required and must be a positive, numeric value."
125134

templates/controllers/grid/issues/form/issueForm.tpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
{assign var=issuePublished value=false}
4444
{/if}
4545

46-
{if $issuePublished}
4746
{fbvFormArea id="datePublishedArea" title="editor.issues.datePublished"}
4847
{fbvFormSection}
49-
{if $issuePublished}
50-
{fbvElement type="text" id="datePublished" value=$datePublished size=$fbvStyles.size.SMALL class="datepicker"}
51-
{/if}
48+
{if !$issuePublished}
49+
{assign var=notPublishedDescription value="editor.issues.datePublished.notPublished.description"}
50+
{else}
51+
{assign var=notPublishedDescription value=""}
52+
{/if}
53+
{fbvElement type="text" id="datePublished" value=$datePublished size=$fbvStyles.size.SMALL class="datepicker" autocomplete="off" label=$notPublishedDescription}
5254
{/fbvFormSection}
5355
{/fbvFormArea}
54-
{/if}
55-
5656

5757
{fbvFormArea id="identificationArea" title="editor.issues.identification"}
5858
{fbvFormSection}

0 commit comments

Comments
 (0)