Skip to content

Commit db0a2a3

Browse files
taslangrahamewhanson
authored andcommitted
pkp/pkp-lib#11025 Include issue info on submission API data
1 parent 65a43ac commit db0a2a3

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

classes/submission/maps/Schema.php

+73-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
use APP\decision\types\Accept;
1919
use APP\decision\types\SkipExternalReview;
2020
use APP\facades\Repo;
21+
use APP\issue\Issue;
22+
use APP\publication\Publication;
2123
use APP\submission\Submission;
2224
use Illuminate\Support\Collection;
25+
use Illuminate\Support\Enumerable;
2326
use PKP\db\DAORegistry;
2427
use PKP\decision\DecisionType;
2528
use PKP\decision\types\BackFromCopyediting;
@@ -41,6 +44,9 @@
4144

4245
class Schema extends \PKP\submission\maps\Schema
4346
{
47+
/** Issues associated with submissions. Keyed by submission ID. */
48+
public Enumerable $submissionsIssues;
49+
4450
/**
4551
* @copydoc \PKP\submission\maps\Schema::mapByProperties()
4652
*/
@@ -70,6 +76,10 @@ protected function mapByProperties(array $props, Submission $submission, bool|Co
7076
$locales[] = $primaryLocale;
7177
}
7278

79+
if (in_array('issueToBePublished', $props)) {
80+
$output['issueToBePublished'] = $this->getPropertyIssueToBePublished($submission->getData('publications'));
81+
}
82+
7383
$output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales);
7484

7585
ksort($output);
@@ -81,10 +91,10 @@ protected function appSpecificProps(): array
8191
{
8292
return [
8393
'scheduledIn',
94+
'issueToBePublished'
8495
];
8596
}
8697

87-
8898
/**
8999
* Gets the Editorial decisions available to editors for a given stage of a submission
90100
*
@@ -165,4 +175,66 @@ protected function getAvailableEditorialDecisions(int $stageId, Submission $subm
165175

166176
return $decisionTypes;
167177
}
178+
179+
/**
180+
* Get issues associated with submissions. Results are keyed by submission ID.
181+
*
182+
* @return Enumerable<int, Issue[]>
183+
*/
184+
protected function getSubmissionsIssues(Enumerable $submissions): Enumerable
185+
{
186+
$submissionIds = $submissions->map(fn (Submission $submission) => $submission->getId())->all();
187+
$publications = Repo::publication()->getCollector()->filterBySubmissionIds($submissionIds)->getMany();
188+
$issueIds = $publications->map(fn (Publication $publication) => $publication->getData('issueId'))
189+
->unique()
190+
->all();
191+
192+
$issues = Repo::issue()->getCollector()
193+
->filterByContextIds([$this->context->getId()])
194+
->filterByIssueIds($issueIds)
195+
->getMany();
196+
197+
$issueIdsGroupedBySubmission = $publications->groupBy(fn (Publication $publication) => $publication->getData('submissionId'))
198+
->map(fn ($entry) => $entry->map(fn (Publication $publication) => $publication->getData('issueId')));
199+
200+
return $submissions->mapWithKeys(function ($submission) use (&$issues, $publications, $issueIdsGroupedBySubmission) {
201+
$submissionIssueIds = $issueIdsGroupedBySubmission->get($submission->getId())->all();
202+
return [$submission->getId() => $issues->filter(fn ($issue) => in_array($issue->getId(), $submissionIssueIds))];
203+
});
204+
}
205+
206+
/**
207+
* Get details about the issue a submission will be published in.
208+
*/
209+
protected function getPropertyIssueToBePublished(Enumerable $publications): ?array
210+
{
211+
/** @var Publication $latestScheduledPublication */
212+
$latestScheduledPublication = $publications
213+
->filter(fn ($publication) => $publication->getData('status') === Submission::STATUS_SCHEDULED)
214+
->sortByDesc(fn (Publication $publication) => $publication->getData('version'))
215+
->first();
216+
217+
if ($latestScheduledPublication) {
218+
$submissionId = $latestScheduledPublication->getData('submissionId');
219+
$issueId = $latestScheduledPublication->getData('issueId');
220+
$issue = $this->submissionsIssues->get($submissionId, collect())->get($issueId);
221+
222+
return $issue ? [
223+
'id' => $issueId,
224+
'label' => $issue->getIssueIdentification()
225+
] : null;
226+
}
227+
228+
return null;
229+
}
230+
231+
/**
232+
* Populate class properties specific to OJS.
233+
*/
234+
protected function addAppSpecificData(Enumerable $submissions): void
235+
{
236+
if (empty($this->submissionsIssues)) {
237+
$this->submissionsIssues = $this->getSubmissionsIssues($submissions);
238+
}
239+
}
168240
}

schemas/submission.json

+12
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@
9797
}
9898
}
9999
}
100+
},
101+
"issueToBePublished": {
102+
"type": "object",
103+
"properties": {
104+
"id": {
105+
"type": "integer"
106+
},
107+
"label": {
108+
"type": "string"
109+
}
110+
},
111+
"apiSummary": true
100112
}
101113
}
102114
}

0 commit comments

Comments
 (0)