Skip to content

Commit

Permalink
#9825 Submission data in review assignment schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed May 6, 2024
1 parent 57e718f commit 199ee9a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 19 deletions.
32 changes: 31 additions & 1 deletion classes/submission/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class Collector implements CollectorInterface, ViewsCount
public ?bool $reviewsSubmitted = null;
public ?bool $revisionsRequested = null;
public ?bool $revisionsSubmitted = null;
public ?array $reviewIds = null;

public function __construct(DAO $dao)
{
Expand Down Expand Up @@ -272,6 +273,17 @@ public function isReviewedBy(int|array|null $isReviewedBy): AppCollector
return $this;
}

/**
* Limit results by submissions with specific review assignment IDs
*
* @param array|null $reviewIds An array of review assignment IDs
*/
public function filterByReviewIds(?array $reviewIds): AppCollector
{
$this->reviewIds = $reviewIds;
return $this;
}

/**
* Limit results to submissions matching this search query
*/
Expand Down Expand Up @@ -626,6 +638,17 @@ public function getQueryBuilder(): Builder
// Filter out excluded submission IDs
$q->when($this->excludeIds !== null, fn (Builder $q) => $q->whereNotIn('s.submission_id', $this->excludeIds));

$q->when(
$this->reviewIds !== null,
fn (Builder $q) => $q
->whereExists(
fn (Builder $q) => $q
->from('review_assignments AS ra')
->whereColumn('s.submission_id', 'ra.submission_id')
->whereIn('ra.review_id', $this->reviewIds)
)
);

// Limit and offset results for pagination
if (isset($this->count)) {
$q->limit($this->count);
Expand All @@ -645,7 +668,14 @@ public function getQueryBuilder(): Builder
*/
protected function buildReviewStageQueries(Builder $q): Builder
{
$reviewFilters = collect([$this->isReviewedBy, $this->reviewersNumber, $this->awaitingReviews, $this->reviewsSubmitted, $this->revisionsRequested, $this->revisionsSubmitted])->filter();
$reviewFilters = collect([
$this->isReviewedBy,
$this->reviewersNumber,
$this->awaitingReviews,
$this->reviewsSubmitted,
$this->revisionsRequested,
$this->revisionsSubmitted
])->filter();
if ($reviewFilters->isEmpty()) {
return $q;
}
Expand Down
64 changes: 46 additions & 18 deletions classes/submission/reviewAssignment/maps/Schema.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php
/**
* @file classes/announcement/maps/Schema.php
* @file classes/reviewAssignment/maps/Schema.php
*
* Copyright (c) 2014-2023 Simon Fraser University
* Copyright (c) 2000-2023 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Schema
*
* @brief Map announcements to the properties defined in the announcement schema
* @brief Map review assignments to the properties defined in the review assignment schema
*/

namespace PKP\submission\reviewAssignment\maps;

use APP\facades\Repo;
use APP\submission\Submission;
use Illuminate\Support\Enumerable;
use PKP\services\PKPSchemaService;
use PKP\submission\reviewAssignment\ReviewAssignment;
Expand All @@ -25,23 +26,23 @@ class Schema extends \PKP\core\maps\Schema
public string $schema = PKPSchemaService::SCHEMA_REVIEW_ASSIGNMENT;

/**
* Map an announcement
* Map the Review Assignment
*
* Includes all properties in the review assignment schema.
*/
public function map(ReviewAssignment $item): array
public function map(ReviewAssignment $item, Submission $submission): array
{
return $this->mapByProperties($this->getProps(), $item);
return $this->mapByProperties($this->getProps(), $item, $submission);
}

/**
* Summarize an announcement
* Summarize the Review Assignment
*
* Includes properties with the apiSummary flag in the review assignment schema.
*/
public function summarize(ReviewAssignment $item): array
public function summarize(ReviewAssignment $item, Submission $submission): array
{
return $this->mapByProperties($this->getSummaryProps(), $item);
return $this->mapByProperties($this->getSummaryProps(), $item, $submission);
}

/**
Expand All @@ -52,9 +53,21 @@ public function summarize(ReviewAssignment $item): array
public function mapMany(Enumerable $collection): Enumerable
{
$this->collection = $collection;
return $collection->map(function ($item) {
return $this->map($item);
});
$submissions = Repo::submission()->getCollector()
->filterByContextIds([$this->context->getId()])
->filterByReviewIds($collection->keys()->toArray())
->getMany()
->remember();

$associatedSubmissions = $this->collection->map(
fn (ReviewAssignment $reviewAssignment) =>
$reviewAssignment->getData('submissionId')
);

return $collection->map(
fn ($item) =>
$this->map($item, $submissions->get($associatedSubmissions->get($item->getId())))
);
}

/**
Expand All @@ -65,19 +78,34 @@ public function mapMany(Enumerable $collection): Enumerable
public function summarizeMany(Enumerable $collection): Enumerable
{
$this->collection = $collection;
return $collection->map(function ($item) {
return $this->summarize($item);
});
$submissions = Repo::submission()->getCollector()
->filterByContextIds([$this->context->getId()])
->filterByReviewIds($collection->keys()->toArray())
->getMany()
->remember();

$associatedSubmissions = $this->collection->map(
fn (ReviewAssignment $reviewAssignment) =>
$reviewAssignment->getData('submissionId')
);

return $collection->map(
fn ($item) =>
$this->summarize($item, $submissions->get($associatedSubmissions->get($item->getId())))
);
}

/**
* Map schema properties of an Announcement to an assoc array
* Map schema properties of the Review Assignment to an assoc array
*/
protected function mapByProperties(array $props, ReviewAssignment $item): array
protected function mapByProperties(array $props, ReviewAssignment $item, Submission $submission): array
{
$output = [];
foreach ($props as $prop) {
switch ($prop) {
case 'publicationTitle':
$output[$prop] = $submission->getCurrentPublication()->getFullTitles('html');
break;
case '_href':
$output[$prop] = $this->getApiUrl('_submissions/reviewAssignments/' . $item->getId());
break;
Expand Down
6 changes: 6 additions & 0 deletions schemas/reviewAssignment.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@
"type": "integer",
"description": "The ID of the submission associated with the assignment",
"apiSummary": true
},
"publicationTitle": {
"type": "string",
"multilingual": true,
"description": "The title of the associated with the current publication",
"readOnly": true
}
}
}

0 comments on commit 199ee9a

Please sign in to comment.