Skip to content

Commit

Permalink
pkp#8885 Retrieve review assignments associated with submissions list
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Jan 12, 2024
1 parent 7d59a9e commit 0b389e1
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use APP\core\Application;
use APP\facades\Repo;
use APP\submission\Submission;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Illuminate\Support\LazyCollection;
use PKP\db\DAORegistry;
Expand Down Expand Up @@ -46,6 +47,9 @@ class Schema extends \PKP\core\maps\Schema
/** @var Genre[] The file genres in this context. */
public array $genres;

/** @var Enumerable The review assignments' data associated with the submission . */
public Enumerable $reviewAssignments;

/**
* Get extra property names used in the submissions list
*
Expand Down Expand Up @@ -91,10 +95,11 @@ protected function getSubmissionsListProps(): array
* @param LazyCollection<int,UserGroup> $userGroups The user groups in this context
* @param Genre[] $genres The file genres in this context
*/
public function map(Submission $item, LazyCollection $userGroups, array $genres): array
public function map(Submission $item, LazyCollection $userGroups, array $genres, ?Enumerable $reviewAssignments = null): array
{
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
return $this->mapByProperties($this->getProps(), $item);
}

Expand All @@ -106,10 +111,11 @@ public function map(Submission $item, LazyCollection $userGroups, array $genres)
* @param LazyCollection<int,UserGroup> $userGroups The user groups in this context
* @param Genre[] $genres The file genres in this context
*/
public function summarize(Submission $item, LazyCollection $userGroups, array $genres): array
public function summarize(Submission $item, LazyCollection $userGroups, array $genres, ?Enumerable $reviewAssignments = null): array
{
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
return $this->mapByProperties($this->getSummaryProps(), $item);
}

Expand All @@ -126,8 +132,12 @@ public function mapMany(Enumerable $collection, LazyCollection $userGroups, arra
$this->collection = $collection;
$this->userGroups = $userGroups;
$this->genres = $genres;
return $collection->map(function ($item) {
return $this->map($item, $this->userGroups, $this->genres);
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds($collection->keys()->toArray())->getMany()->remember();
$associatedReviewAssignments = $this->reviewAssignments->groupBy(function (ReviewAssignment $reviewAssignment, int $key) {
return $reviewAssignment->getData('submissionId');
});
return $collection->map(function ($item) use ($associatedReviewAssignments) {
return $this->map($item, $this->userGroups, $this->genres, $associatedReviewAssignments->get($item->getId()));
});
}

Expand All @@ -144,8 +154,12 @@ public function summarizeMany(Enumerable $collection, LazyCollection $userGroups
$this->collection = $collection;
$this->userGroups = $userGroups;
$this->genres = $genres;
return $collection->map(function ($item) {
return $this->summarize($item, $this->userGroups, $this->genres);
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds($collection->keys()->toArray())->getMany()->remember();
$associatedReviewAssignments = $this->reviewAssignments->groupBy(function (ReviewAssignment $reviewAssignment, int $key) {
return $reviewAssignment->getData('submissionId');
});
return $collection->map(function ($item) use ($associatedReviewAssignments) {
return $this->summarize($item, $this->userGroups, $this->genres, $associatedReviewAssignments->get($item->getId()));
});
}

Expand All @@ -154,11 +168,13 @@ public function summarizeMany(Enumerable $collection, LazyCollection $userGroups
*
* @param LazyCollection<int,UserGroup> $userGroups The user groups in this context
* @param Genre[] $genres The file genres in this context
* @param Collection $reviewAssignments review assignments associated with a submission
*/
public function mapToSubmissionsList(Submission $item, LazyCollection $userGroups, array $genres): array
public function mapToSubmissionsList(Submission $item, LazyCollection $userGroups, array $genres, ?Enumerable $reviewAssignments = null): array
{
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
return $this->mapByProperties($this->getSubmissionsListProps(), $item);
}

Expand All @@ -175,8 +191,12 @@ public function mapManyToSubmissionsList(Enumerable $collection, LazyCollection
$this->collection = $collection;
$this->userGroups = $userGroups;
$this->genres = $genres;
return $collection->map(function ($item) {
return $this->mapToSubmissionsList($item, $this->userGroups, $this->genres);
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds($collection->keys()->toArray())->getMany()->remember();
$associatedReviewAssignments = $this->reviewAssignments->groupBy(function (ReviewAssignment $reviewAssignment, int $key) {
return $reviewAssignment->getData('submissionId');
});
return $collection->map(function ($item) use ($associatedReviewAssignments) {
return $this->mapToSubmissionsList($item, $this->userGroups, $this->genres, $associatedReviewAssignments->get($item->getId()));
});
}

Expand Down Expand Up @@ -209,6 +229,7 @@ public function summarizeWithoutPublication(Submission $item): array
$props = array_filter($this->getSummaryProps(), function ($prop) {
return $prop !== 'publications';
});
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
return $this->mapByProperties($props, $item);
}

Expand Down Expand Up @@ -239,7 +260,7 @@ protected function mapByProperties(array $props, Submission $submission): array
->summarizeMany($submission->getData('publications'), $anonymize)->values();
break;
case 'reviewAssignments':
$output[$prop] = $this->getPropertyReviewAssignments($submission);
$output[$prop] = $this->getPropertyReviewAssignments($this->reviewAssignments);
break;
case 'reviewRounds':
$output[$prop] = $this->getPropertyReviewRounds($submission);
Expand Down Expand Up @@ -277,10 +298,8 @@ protected function mapByProperties(array $props, Submission $submission): array
/**
* Get details about the review assignments for a submission
*/
protected function getPropertyReviewAssignments(Submission $submission): array
protected function getPropertyReviewAssignments(Enumerable $reviewAssignments): array
{
$reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$submission->getId()])->getMany();

$reviews = [];
foreach ($reviewAssignments as $reviewAssignment) {
// @todo for now, only show reviews that haven't been
Expand All @@ -291,7 +310,6 @@ protected function getPropertyReviewAssignments(Submission $submission): array

$request = Application::get()->getRequest();
$currentUser = $request->getUser();
$context = $request->getContext();
$due = is_null($reviewAssignment->getDateDue()) ? null : date('Y-m-d', strtotime($reviewAssignment->getDateDue()));
$responseDue = is_null($reviewAssignment->getDateResponseDue()) ? null : date('Y-m-d', strtotime($reviewAssignment->getDateResponseDue()));

Expand Down

0 comments on commit 0b389e1

Please sign in to comment.