-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkp/pkp-lib#10280 Additional data for submissions/{ID}/participants API #10383
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,12 @@ | |
use Illuminate\Support\Enumerable; | ||
use PKP\db\DAORegistry; | ||
use PKP\plugins\Hook; | ||
use PKP\security\Role; | ||
use PKP\services\PKPSchemaService; | ||
use PKP\stageAssignment\StageAssignment; | ||
use PKP\user\User; | ||
use PKP\workflow\WorkflowStageDAO; | ||
use Submission; | ||
|
||
class Schema extends \PKP\core\maps\Schema | ||
{ | ||
|
@@ -51,9 +55,9 @@ public function summarize(User $item): array | |
* | ||
* Includes properties with the apiSummary flag in the user schema. | ||
*/ | ||
public function summarizeReviewer(User $item): array | ||
public function summarizeReviewer(User $item, array $auxiliaryData = []): array | ||
{ | ||
return $this->mapByProperties(array_merge($this->getSummaryProps(), ['reviewsActive', 'reviewsCompleted', 'reviewsDeclined', 'reviewsCancelled', 'averageReviewCompletionDays', 'dateLastReviewAssignment', 'reviewerRating']), $item); | ||
return $this->mapByProperties(array_merge($this->getSummaryProps(), ['reviewsActive', 'reviewsCompleted', 'reviewsDeclined', 'reviewsCancelled', 'averageReviewCompletionDays', 'dateLastReviewAssignment', 'reviewerRating']), $item, $auxiliaryData); | ||
} | ||
|
||
/** | ||
|
@@ -98,9 +102,11 @@ public function summarizeManyReviewers(Enumerable $collection): Enumerable | |
/** | ||
* Map schema properties of a user to an assoc array | ||
* | ||
* @param array $auxiliaryData - Associative array used to provide supplementary data needed to populate properties on the response. | ||
* | ||
* @hook UserSchema::getProperties::values [[$this, &$output, $user, $props]] | ||
*/ | ||
protected function mapByProperties(array $props, User $user): array | ||
protected function mapByProperties(array $props, User $user, array $auxiliaryData = []): array | ||
{ | ||
$output = []; | ||
|
||
|
@@ -180,6 +186,54 @@ protected function mapByProperties(array $props, User $user): array | |
} | ||
} | ||
} | ||
break; | ||
case 'stageAssignments': | ||
$submission = $auxiliaryData['submission']; | ||
$stageId = $auxiliaryData['stageId']; | ||
|
||
if((!isset($submission) || !isset($stageId)) || (!($submission instanceof Submission) || !is_numeric($auxiliaryData['stageId']))) { | ||
$output['stageAssignments'] = []; | ||
break; | ||
} | ||
|
||
// Get User's stage assignments for submission. | ||
// Note: | ||
// - A User can potentially have multiple assignments for a submission. | ||
// - A User can potentially have multiple assignments for a stage of a submission. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asmecher, I realized I've been a bit confused about this so I wanted to confirm before this is merged: could you confirm these two assumptions noted? I thought these were the case but I'm less sure after our recent discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's say (using our default user groups) a user is assigned to a submission as both Section Editor and Layout Editor. Then they'll have a row in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asmecher, yes, thanks! |
||
$stageAssignments = StageAssignment::withSubmissionIds([$submission->getId()]) | ||
->withStageIds($stageId ? [$stageId] : []) | ||
->withUserId($user->getId()) | ||
->withContextId($this->context->getId()) | ||
->get(); | ||
|
||
$results = []; | ||
|
||
foreach ($stageAssignments as $stageAssignment /**@var StageAssignment $stageAssignment*/) { | ||
// Get related user group info for stage assignment | ||
$userGroup = Repo::userGroup()->get($stageAssignment->userGroupId); | ||
|
||
// Only prepare data for non-reviewer participants | ||
if ($userGroup->getRoleId() !== Role::ROLE_ID_REVIEWER) { | ||
$entry = [ | ||
'stageAssignmentId' => $stageAssignment->id, | ||
'stageAssignmentUserGroup' => $userGroup->getAllData(), | ||
'stageAssignmentStageId' => $stageId, | ||
'recommendOnly' => (bool)$stageAssignment->recommendOnly, | ||
'canChangeMetadata' => (bool)$stageAssignment->canChangeMetadata | ||
]; | ||
|
||
$workflowStageDao = DAORegistry::getDAO('WorkflowStageDAO'); /** @var WorkflowStageDAO $workflowStageDao */ | ||
$entry['stageAssignmentStage'] = [ | ||
'id' => $stageId, | ||
'label' => __($workflowStageDao->getTranslationKeyFromId($stageId)), | ||
]; | ||
|
||
$results[] = $entry; | ||
} | ||
|
||
$output['stageAssignments'] = $results; | ||
} | ||
|
||
break; | ||
default: | ||
$output[$prop] = $user->getData($prop); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The additional
stage_assignments
table name shouldn't be necessary here. Were you running into any issues with it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the
scopeWithSubmissionIds
filter in combination with another filter, such asscopeWithContextId
, which performs joins with tables containing a column namedsubmission_id
, you'll encounter an ambiguous column error because the column namesubmission_id
exists in multiple tables in the query.So for example the following query would throw the error below
Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!