diff --git a/api/v1/_submissions/PKPBackendSubmissionsController.php b/api/v1/_submissions/PKPBackendSubmissionsController.php index d6af90f196f..452188611fc 100644 --- a/api/v1/_submissions/PKPBackendSubmissionsController.php +++ b/api/v1/_submissions/PKPBackendSubmissionsController.php @@ -126,13 +126,17 @@ public function getGroupRoutes(): void Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT, + Role::ROLE_ID_AUTHOR, + Role::ROLE_ID_REVIEWER, ]) ]); Route::get('reviewerAssignments', $this->getReviewAssignments(...)) ->name('_submission.getReviewAssignments') ->middleware([ - Role::ROLE_ID_REVIEWER, + self::roleAuthorizer([ + Role::ROLE_ID_REVIEWER, + ]) ]); } } @@ -328,7 +332,7 @@ public function reviews(Request $illuminateRequest): JsonResponse } /** - * Get a number of the submissions for each view + * Get a number of the submissions/review assignments for each view depending on a user role */ public function getViewsCount(Request $illuminateRequest): JsonResponse { @@ -363,7 +367,7 @@ public function getReviewAssignments(Request $illuminateRequest): JsonResponse } $currentUser = $request->getUser(); $collector = Repo::reviewAssignment()->getCollector() - ->filterByReviewRoundIds([$currentUser->getId()]) + ->filterByReviewerIds([$currentUser->getId()]) ->filterByContextIds([$context->getId()]); foreach ($illuminateRequest->query() as $param => $val) { diff --git a/classes/submission/Collector.php b/classes/submission/Collector.php index 85c1b596e96..24043fb8dfb 100644 --- a/classes/submission/Collector.php +++ b/classes/submission/Collector.php @@ -35,10 +35,8 @@ /** * @template T of Submission */ -abstract class Collector implements CollectorInterface +abstract class Collector implements CollectorInterface, ViewsCount { - use ViewsCount; - public const ORDERBY_DATE_PUBLISHED = 'datePublished'; public const ORDERBY_DATE_SUBMITTED = 'dateSubmitted'; public const ORDERBY_ID = 'id'; @@ -776,6 +774,19 @@ protected function buildReviewStageQueries(Builder $q): Builder return $q; } + public static function getViewsCountBuilder(Collection $keyCollectorPair): Builder + { + $q = DB::query(); + $keyCollectorPair->each(function(AppCollector $collector, string $key) use ($q) { + // Get query builder from a collector instance, override a select statement to retrieve submissions count instead of submissions data + $subQuery = $collector->getQueryBuilder()->select([])->selectRaw( + 'COUNT(s.submission_id)' + ); + $q->selectSub($subQuery, $key); + }); + return $q; + } + protected function getReviewStages(): array { return [WORKFLOW_STAGE_ID_EXTERNAL_REVIEW]; diff --git a/classes/submission/DashboardView.php b/classes/submission/DashboardView.php index 85062606e2b..301669a524d 100644 --- a/classes/submission/DashboardView.php +++ b/classes/submission/DashboardView.php @@ -80,7 +80,7 @@ public static function getTypes(): Collection /** * Get the collector with filters applied to retrieve submissions for the view */ - public function getCollector(): Collector + public function getCollector(): SubmissionCollector|ReviewAssignmentCollector { return $this->submissionCollector; } diff --git a/classes/submission/Repository.php b/classes/submission/Repository.php index 8e10db0a52b..4eadf62f177 100644 --- a/classes/submission/Repository.php +++ b/classes/submission/Repository.php @@ -39,6 +39,7 @@ use PKP\services\PKPSchemaService; use PKP\stageAssignment\StageAssignmentDAO; use PKP\submission\Collector as SubmissionCollector; +use PKP\submission\reviewAssignment\Collector as ReviewCollector; use PKP\submissionFile\SubmissionFile; use PKP\user\User; use PKP\validation\ValidatorFactory; @@ -789,7 +790,6 @@ public function getUrlSubmissionWizard(Context $context, ?int $submissionId = nu /** * Get all views, views count to be retrieved separately due to performance reasons - * TODO return views depending on a user role */ public function getDashboardViews(Context $context, User $user): Collection { @@ -1044,7 +1044,7 @@ public function getDashboardViews(Context $context, User $user): Collection $filteredViews = $this->filterViewsByUserRoles($views, $roleIds); - return $this->getViewsCount($filteredViews); + return $this->setViewsCount($filteredViews); } protected function filterViewsByUserRoles(Collection $views, array $roleIds): Collection @@ -1055,19 +1055,31 @@ protected function filterViewsByUserRoles(Collection $views, array $roleIds): Co } /** - * @param Collection [ - * Dashboard view unique ID => Submission Collector with filters applied - * ] + * @param Collection $dashboardViews + * + * Set the submissions/reviews count to the list of dashboard views */ - protected function getViewsCount(Collection $dashboardViews): Collection + protected function setViewsCount(Collection $dashboardViews): Collection { - $collectors = $dashboardViews->map(function (DashboardView $view) { - return $view->getCollector(); - }); + $submissionCollectors = collect(); + $reviewCollectors = collect(); + foreach ($dashboardViews as $id => $dashboardView) { + $collector = $dashboardView->getCollector(); + is_a($collector, SubmissionCollector::class) ? + $submissionCollectors->put($id, $collector) : + $reviewCollectors->put($id, $collector); + } + + $submissionsCount = $submissionCollectors->isNotEmpty() ? + get_object_vars(SubmissionCollector::getViewsCountBuilder($submissionCollectors)?->first() ?? []) : + []; + + $reviewsCount = $reviewCollectors->isNotEmpty() ? + get_object_vars(ReviewCollector::getViewsCountBuilder($reviewCollectors)?->first() ?? []) : + []; - $viewCounts = SubmissionCollector::getViewsCountBuilder($collectors)->first(); - foreach ($viewCounts as $viewId => $count) { + foreach (array_merge($submissionsCount, $reviewsCount) as $viewId => $count) { $view = $dashboardViews->get($viewId); /** @var $view DashboardView */ $view->setCount($count); } diff --git a/classes/submission/ViewsCount.php b/classes/submission/ViewsCount.php index 06bc7a60511..fb186d5757c 100644 --- a/classes/submission/ViewsCount.php +++ b/classes/submission/ViewsCount.php @@ -8,34 +8,22 @@ * * @class ViewsCount * - * @brief trait to use with a collector to build a query for counting submissions/reviewAssignments in a view + * @brief interface to use with a collector to build a query for counting submissions/reviewAssignments in a view */ namespace PKP\submission; -use APP\submission\Collector as AppCollector; use Illuminate\Database\Query\Builder; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; +use PKP\core\interfaces\CollectorInterface; -trait ViewsCount +interface ViewsCount { /** * Builds a single query to retrieve submissions count for all dashboard views - * @param Collection [ + * @param Collection $keyCollectorPair [ * Dashboard view unique ID => Submission Collector with filters applied * ] */ - public static function getViewsCountBuilder(Collection $keyCollectorPair): Builder - { - $q = DB::query(); - $keyCollectorPair->each(function(AppCollector $collector, string $key) use ($q) { - // Get query builder from a collector instance, override a select statement to retrieve submissions count instead of submissions data - $subQuery = $collector->getQueryBuilder()->select([])->selectRaw( - 'COUNT('. $this->dao->table . '.' . $this->dao->primaryKeyColumn . ')' - ); - $q->selectSub($subQuery, $key); - }); - return $q; - } + public static function getViewsCountBuilder(Collection $keyCollectorPair): Builder; } diff --git a/classes/submission/reviewAssignment/Collector.php b/classes/submission/reviewAssignment/Collector.php index e31aee13c8d..227e6b08815 100644 --- a/classes/submission/reviewAssignment/Collector.php +++ b/classes/submission/reviewAssignment/Collector.php @@ -25,10 +25,8 @@ /** * @template T of ReviewAssignment */ -class Collector implements CollectorInterface +class Collector implements CollectorInterface, ViewsCount { - use ViewsCount; - public DAO $dao; public ?array $contextIds = null; public ?array $submissionIds = null; @@ -225,7 +223,7 @@ public function getQueryBuilder(): Builder ->whereIn('ra.submission_id', fn(Builder $q) => $q ->select('s.submission_id') ->from('submissions AS s') - ->where('s.stage_id', 'ra.stage_id') + ->whereRaw('s.stage_id = ra.stage_id') ) ) ); @@ -284,4 +282,17 @@ public function getQueryBuilder(): Builder return $q; } + + public static function getViewsCountBuilder(Collection $keyCollectorPair): Builder + { + $q = DB::query(); + $keyCollectorPair->each(function(Collector $collector, string $key) use ($q) { + // Get query builder from a collector instance, override a select statement to retrieve submissions count instead of submissions data + $subQuery = $collector->getQueryBuilder()->select([])->selectRaw( + 'COUNT(ra.review_id)' + ); + $q->selectSub($subQuery, $key); + }); + return $q; + } }