Skip to content

Commit

Permalink
#10465 Improve GET submissions/{submissionId}/decisions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham authored Sep 27, 2024
2 parents d12ad2b + 1085d09 commit d2ff88f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
25 changes: 20 additions & 5 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,11 @@ public function changeLocale(Request $illuminateRequest): JsonResponse

// Convert a form field value to multilingual (if it is not) and merge rest values
collect(app()->get('schema')->getMultilingualProps(PKPSchemaService::SCHEMA_PUBLICATION))
->each(fn (string $prop) =>
$illuminateRequest->whenHas($prop, fn ($value) =>
->each(
fn (string $prop) =>
$illuminateRequest->whenHas(
$prop,
fn ($value) =>
$illuminateRequest->merge([
$prop => array_merge(
$publication->getData($prop) ?? [],
Expand Down Expand Up @@ -943,8 +946,19 @@ public function getDecisions(Request $illuminateRequest): JsonResponse
], Response::HTTP_NOT_FOUND);
}

$decisionIterator = Repo::decision()->getCollector()
$decisionTypes = array_map('intval', paramToArray($illuminateRequest->input('decisionTypes') ?? []));
$editorIds = array_map('intval', paramToArray($illuminateRequest->input('editorIds') ?? []));
$reviewRoundId = $illuminateRequest->input('reviewRoundId') ? [(int)$illuminateRequest->input('reviewRoundId')] : null;
$stageId = $illuminateRequest->input('stageId') ? [(int)$illuminateRequest->input('stageId')] : null;

$collector = Repo::decision()->getCollector();
$decisionIterator = $collector
->filterBySubmissionIds([$submission->getId()])
->filterByDecisionTypes(!empty($decisionTypes) ? $decisionTypes : null)
->filterByEditorIds(!empty($editorIds) ? $editorIds : null)
->filterByReviewRoundIds($reviewRoundId)
->filterByStageIds($stageId)
->orderBy($collector::ORDERBY_DATE_DECIDED, $collector::ORDER_DIR_DESC)
->getMany();

$data = Repo::decision()
Expand Down Expand Up @@ -2050,7 +2064,8 @@ protected function getSubmissionAndPublicationData(Request $illuminateRequest):
/**
* Copy author, files, etc. multilingual fields from old to new changed language
*/
protected function copyMultilingualData(Submission $submission, string $newLocale): void {
protected function copyMultilingualData(Submission $submission, string $newLocale): void
{
$oldLocale = $submission->getData('locale');
$editProps = fn (Author|SubmissionFile $item, array $props): array => collect($props)
->mapWithKeys(fn (string $prop): array => [$prop => ($data = $item->getData($prop)[$oldLocale] ?? null) ? [$newLocale => $data] : null])
Expand All @@ -2066,7 +2081,7 @@ protected function copyMultilingualData(Submission $submission, string $newLocal
->filterBySubmissionIds([$submission->getId()])
->getMany()
->each(fn (SubmissionFile $file) => Repo::submissionFile()->edit($file, $editProps($file, $fileProps)));

// Contributor
$contributorProps = [
'givenName',
Expand Down
28 changes: 27 additions & 1 deletion classes/decision/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ class Collector implements CollectorInterface
public ?array $stageIds = null;
public ?array $submissionIds = null;

public const ORDERBY_DATE_DECIDED = 'date_decided';
public const ORDER_DIR_ASC = 'ASC';
public const ORDER_DIR_DESC = 'DESC';

/** The default orderBy value for decision collector */
private ?string $orderBy = self::ORDERBY_DATE_DECIDED;

/** The default orderBy direction value for decision collector */
private ?string $orderDirection = self::ORDER_DIR_ASC;


public function __construct(DAO $dao)
{
$this->dao = $dao;
Expand Down Expand Up @@ -129,6 +140,21 @@ public function filterBySubmissionIds(?array $submissionIds): self
return $this;
}

/**
* Order the results
*
* Results are ordered by the date_decided column by default.
*
* @param string|null $column Name of column to order results by.
* @param string $direction One of the self::ORDER_DIR_ constants
*/
public function orderBy(?string $column, string $direction = self::ORDER_DIR_ASC): self
{
$this->orderBy = $column;
$this->orderDirection = $direction;
return $this;
}

/**
* @copydoc CollectorInterface::getQueryBuilder()
*
Expand Down Expand Up @@ -156,7 +182,7 @@ public function getQueryBuilder(): Builder
->when(!is_null($this->submissionIds), function ($q) {
$q->whereIn('submission_id', $this->submissionIds);
})
->orderBy('date_decided', 'asc');
->orderBy($this->orderBy ?? self::ORDERBY_DATE_DECIDED, $this->orderDirection ?? self::ORDER_DIR_ASC);

Hook::call('Decision::Collector', [&$qb, $this]);

Expand Down

0 comments on commit d2ff88f

Please sign in to comment.