Skip to content

Commit

Permalink
pkp#8885 Code styling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed May 15, 2024
1 parent 3d6f49e commit 4c0c5a7
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ protected function getSubmissionsListProps(): array
'urlPublished',
];

if (!empty($additionalProps = $this->appSpecificProps())) {
$props = array_merge($props, $additionalProps);
}
$props = array_merge($props, $this->appSpecificProps());

Hook::call('Submission::getSubmissionsListProps', [&$props]);

Expand All @@ -119,7 +117,7 @@ public function map(
): array {
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);

return $this->mapByProperties($this->getProps(), $item);
Expand All @@ -144,7 +142,7 @@ public function summarize(
): array {
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);

return $this->mapByProperties($this->getSummaryProps(), $item);
Expand Down Expand Up @@ -236,7 +234,7 @@ public function mapToSubmissionsList(
): array {
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);

return $this->mapByProperties($this->getSubmissionsListProps(), $item);
Expand Down Expand Up @@ -309,7 +307,7 @@ public function summarizeWithoutPublication(Submission $item): array
return $prop !== 'publications';
});

$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany();
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);

return $this->mapByProperties($props, $item);
Expand Down Expand Up @@ -619,17 +617,10 @@ public function getPropertyStages(Submission $submission): array
*/
protected function getPropertyStageAssignments(Enumerable $stageAssignments): bool
{
if ($stageAssignments->isEmpty()) {
return false;
}

foreach ($stageAssignments as $stageAssignment) {
if (!$stageAssignment->recommendOnly) {
return true;
}
}

return false;
return $stageAssignments->isNotEmpty() && $stageAssignments->contains(
fn (StageAssignment $stageAssignment) =>
!$stageAssignment->recommendOnly
);
}

protected function getUserGroup(int $userGroupId): ?UserGroup
Expand All @@ -647,14 +638,14 @@ protected function getUserGroup(int $userGroupId): ?UserGroup
*
* @param Enumerable<Submission> $submissions
*
* @return Collection<StageAssignment> The collection of stage assignments associated with submissions
* @return LazyCollection<StageAssignment> The collection of stage assignments associated with submissions
*/
protected function getStageAssignmentsBySubmissions(Enumerable $submissions, array $roleIds = []): Collection
protected function getStageAssignmentsBySubmissions(Enumerable $submissions, array $roleIds = []): LazyCollection
{
$submissionIds = $submissions->map(fn (Submission $submission) => $submission->getId())->toArray();
return StageAssignment::withSubmissionIds($submissionIds)
->withRoleIds($roleIds)
->get();
->lazy();
}

/**
Expand All @@ -663,12 +654,9 @@ protected function getStageAssignmentsBySubmissions(Enumerable $submissions, arr
protected function getReviewRoundsFromSubmission(Submission $submission): Collection
{
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */
$reviewRounds = collect();
foreach ($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator() as $reviewRound) {
$reviewRounds->put($reviewRound->getData('round'), $reviewRound);
}

return $reviewRounds;
return collect($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator())
->keyBy(fn (ReviewRound $reviewRound) => $reviewRound->getData('round'));
}

/**
Expand All @@ -678,11 +666,8 @@ protected function getReviewRoundsFromSubmission(Submission $submission): Collec
protected function areRecommendationsIn(ReviewRound $currentReviewRound, Enumerable $stageAssignments): ?bool
{
$hasDecidingEditors = $stageAssignments->first(fn (StageAssignment $stageAssignment) => $stageAssignment->recommendOnly);
if (!$hasDecidingEditors) {
return null;
}

return $currentReviewRound->getData('status') == ReviewRound::REVIEW_ROUND_STATUS_RECOMMENDATIONS_READY;
return $hasDecidingEditors ? $currentReviewRound->getData('status') == ReviewRound::REVIEW_ROUND_STATUS_RECOMMENDATIONS_READY : null;
}

/**
Expand Down

0 comments on commit 4c0c5a7

Please sign in to comment.