diff --git a/classes/invitation/invitations/userRoleAssignment/rules/AddUserGroupRule.php b/classes/invitation/invitations/userRoleAssignment/rules/AddUserGroupRule.php index b6347eb42a9..30754005074 100644 --- a/classes/invitation/invitations/userRoleAssignment/rules/AddUserGroupRule.php +++ b/classes/invitation/invitations/userRoleAssignment/rules/AddUserGroupRule.php @@ -32,7 +32,7 @@ public function passes($attribute, $value) // At this point, we know the user group exists; check if the user has it assigned if ($user = $this->invitation->getExistingUser()) { $userUserGroups = UserUserGroup::withUserId($user->getId()) - ->withUserGroupId($value) // The $value is the userGroupId + ->withUserGroupIds([$value]) // The $value is the userGroupId ->withActive() ->get(); diff --git a/classes/mail/mailables/UserRoleAssignmentInvitationNotify.php b/classes/mail/mailables/UserRoleAssignmentInvitationNotify.php index 3e7cbacaec8..3c57ac2e233 100644 --- a/classes/mail/mailables/UserRoleAssignmentInvitationNotify.php +++ b/classes/mail/mailables/UserRoleAssignmentInvitationNotify.php @@ -188,7 +188,7 @@ public function setData(?string $locale = null): void foreach ($userGroups as $userGroup) { $userUserGroups = UserUserGroup::withUserId($user->getId()) - ->withUserGroupId($userGroup->id) + ->withUserGroupIds([$userGroup->id]) ->withActive() ->get(); diff --git a/classes/services/PKPContextService.php b/classes/services/PKPContextService.php index cf65fe33eee..2b425ca1eed 100644 --- a/classes/services/PKPContextService.php +++ b/classes/services/PKPContextService.php @@ -562,7 +562,7 @@ public function add($context, $request) $assignmentExists = UserUserGroup::query() ->withUserId($currentUser->getId()) - ->withUserGroupId($managerUserGroup->id) + ->withUserGroupIds([$managerUserGroup->id]) ->exists(); if (!$assignmentExists) { diff --git a/classes/user/Repository.php b/classes/user/Repository.php index 049ac69e6e4..dab90795979 100644 --- a/classes/user/Repository.php +++ b/classes/user/Repository.php @@ -344,7 +344,7 @@ public function mergeUsers(int $oldUserId, int $newUserId) $submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO'); /** @var SubmissionCommentDAO $submissionCommentDao */ $submissionComments = $submissionCommentDao->getByUserId($oldUserId); - while ($submissionComment = $submissionComments->next()) { + while ($submissionComment = $submissionComments->next()) { /** @var \PKP\submission\SubmissionComment $submissionComment */ $submissionComment->setAuthorId($newUserId); $submissionCommentDao->updateObject($submissionComment); } @@ -369,7 +369,7 @@ public function mergeUsers(int $oldUserId, int $newUserId) // Check if the new user is already assigned to this user group $exists = UserUserGroup::query() ->withUserId($newUserId) - ->withUserGroupId($userUserGroup->userGroupId) + ->withUserGroupIds([$userUserGroup->userGroupId]) ->exists(); if (!$exists) { diff --git a/classes/user/maps/Schema.php b/classes/user/maps/Schema.php index ff4c916d280..b40b6923b4f 100644 --- a/classes/user/maps/Schema.php +++ b/classes/user/maps/Schema.php @@ -177,7 +177,7 @@ protected function mapByProperties(array $props, User $user, array $auxiliaryDat 'recommendOnly' => (bool) $userGroup->recommendOnly, 'dateStart' => UserUserGroup::withUserId($user->getId()) ->withActive() - ->withUserGroupId($userGroup->id) + ->withUserGroupIds([$userGroup->id]) ->pluck('date_start')->first() ]; } diff --git a/classes/userGroup/Repository.php b/classes/userGroup/Repository.php index 83b167e5814..3c8ff162e37 100644 --- a/classes/userGroup/Repository.php +++ b/classes/userGroup/Repository.php @@ -15,6 +15,7 @@ use Carbon\Carbon; use DateInterval; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\LazyCollection; @@ -218,7 +219,7 @@ public function userInGroup(int $userId, int $userGroupId): bool { return UserUserGroup::query() ->withUserId($userId) - ->withUserGroupId($userGroupId) + ->withUserGroupIds($userGroupId) ->withActive() ->exists(); } @@ -242,7 +243,7 @@ public function userOnMasthead(int $userId, ?int $userGroupId = null): bool ->withMasthead(); if ($userGroupId) { - $query->withUserGroupId($userGroupId); + $query->withUserGroupIds([$userGroupId]); } return $query->exists(); @@ -256,7 +257,7 @@ public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): U { $masthead = UserUserGroup::query() ->withUserId($userId) - ->withUserGroupId($userGroupId) + ->withUserGroupIds([$userGroupId]) ->withActive() ->pluck('masthead') ->first(); @@ -344,7 +345,7 @@ public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null) $query = UserUserGroup::query()->withUserId($userId); if ($userGroupId) { - $query->withUserGroupId($userGroupId); + $query->withUserGroupIds([$userGroupId]); $userGroup = $this->get($userGroupId); if ($userGroup && $userGroup->masthead) { self::forgetEditorialCache($userGroup->contextId); @@ -374,7 +375,7 @@ public function endAssignments(int $contextId, int $userId, ?int $userGroupId = ->withActive(); if ($userGroupId) { - $query->withUserGroupId($userGroupId); + $query->withUserGroupIds([$userGroupId]); } $query->update(['date_end' => $dateEnd]); @@ -590,12 +591,13 @@ public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId $users = UserUserGroup::query() ->withContextId($contextId) ->withUserGroupIds($mastheadRoleIds) - ->withUserUserGroupStatus($userUserGroupStatus->value) - ->withUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON->value) + ->whereHas('userGroup', fn (Builder $query) => $query->withUserUserGroupStatus($userUserGroupStatus->value)) + ->withMasthead() ->orderBy('user_groups.role_id', 'asc') ->join('user_groups', 'user_user_groups.user_group_id', '=', 'user_groups.user_group_id') ->join('users', 'user_user_groups.user_id', '=', 'users.user_id') - ->orderBy('users.family_name', 'asc') + ->join('user_settings', 'user_user_groups.user_id', '=', 'user_settings.user_id') + ->orderBy('user_settings.family_name', 'asc') ->get(['user_groups.user_group_id', 'users.user_id']); // group unique user ids by UserGroup id diff --git a/classes/userGroup/relationships/UserUserGroup.php b/classes/userGroup/relationships/UserUserGroup.php index e54e2f7f11a..14fd1a3fb19 100644 --- a/classes/userGroup/relationships/UserUserGroup.php +++ b/classes/userGroup/relationships/UserUserGroup.php @@ -14,13 +14,13 @@ namespace PKP\userGroup\relationships; +use PKP\core\Core; use APP\facades\Repo; +use PKP\userGroup\UserGroup; +use Eloquence\Behaviours\HasCamelCasing; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Eloquence\Behaviours\HasCamelCasing; -use PKP\core\Core; -use PKP\userGroup\UserGroup; class UserUserGroup extends \Illuminate\Database\Eloquent\Model { @@ -52,9 +52,9 @@ public function scopeWithUserId(Builder $query, int $userId): Builder return $query->where('user_user_groups.user_id', $userId); } - public function scopeWithUserGroupId(Builder $query, int $userGroupId): Builder + public function scopeWithUserGroupIds(Builder $query, array $userGroupIds): Builder { - return $query->where('user_user_groups.user_group_id', $userGroupId); + return $query->whereIn('user_user_groups.user_group_id', $userGroupIds); } public function scopeWithActive(Builder $query): Builder diff --git a/controllers/grid/settings/user/form/UserForm.php b/controllers/grid/settings/user/form/UserForm.php index 8dad160cb9f..2aad221f68f 100644 --- a/controllers/grid/settings/user/form/UserForm.php +++ b/controllers/grid/settings/user/form/UserForm.php @@ -143,7 +143,7 @@ public function saveUserGroupAssignments(Request $request): void fn ($userGroupId) => UserUserGroup::query() ->withUserId($this->userId) - ->withUserGroupId($userGroupId) + ->withUserGroupIds([$userGroupId]) ->withActive() ->update(['date_end' => now()]) ); diff --git a/pages/about/AboutContextHandler.php b/pages/about/AboutContextHandler.php index 0bc051e6098..c836cdf4362 100644 --- a/pages/about/AboutContextHandler.php +++ b/pages/about/AboutContextHandler.php @@ -21,6 +21,8 @@ use APP\handler\Handler; use APP\template\TemplateManager; use DateTime; +use Illuminate\Support\Collection; +use PKP\context\Context; use PKP\facades\Locale; use PKP\orcid\OrcidManager; use PKP\plugins\Hook; @@ -61,7 +63,7 @@ public function index($args, $request) } - private function getSortedMastheadUserGroups($context) + private function getSortedMastheadUserGroups(Context $context): Collection { $mastheadUserGroups = UserGroup::withContextIds([$context->getId()]) ->masthead(true) @@ -95,7 +97,7 @@ public function editorialMasthead($args, $request) // Get all user IDs grouped by user group ID for the masthead roles $allUsersIdsGroupedByUserGroupId = Repo::userGroup()->getMastheadUserIdsByRoleIds( - $mastheadRoles, + $mastheadRoles->all(), $context->getId() ); @@ -104,7 +106,7 @@ public function editorialMasthead($args, $request) foreach ($allUsersIdsGroupedByUserGroupId[$userGroupId] ?? [] as $userId) { $user = Repo::user()->get($userId); $userUserGroup = UserUserGroup::withUserId($user->getId()) - ->withUserGroupId($userGroupId) + ->withUserGroupIds([$userGroupId]) ->withActive() ->withMasthead() ->first(); @@ -161,7 +163,7 @@ public function editorialHistory($args, $request) // get all user IDs grouped by user group ID for the masthead roles with ended status $allUsersIdsGroupedByUserGroupId = Repo::userGroup()->getMastheadUserIdsByRoleIds( - $mastheadRoles, + $mastheadRoles->all(), $context->getId(), UserUserGroupStatus::STATUS_ENDED ); @@ -171,7 +173,7 @@ public function editorialHistory($args, $request) foreach ($allUsersIdsGroupedByUserGroupId[$userGroupId] ?? [] as $userId) { $user = Repo::user()->get($userId); $userUserGroups = UserUserGroup::withUserId($user->getId()) - ->withUserGroupId($userGroupId) + ->withUserGroupIds([$userGroupId]) ->withEnded() ->withMasthead() ->orderBy('date_start', 'desc') diff --git a/templates/frontend/pages/editorialMasthead.tpl b/templates/frontend/pages/editorialMasthead.tpl index b740259fa7f..50adcf3ca1b 100644 --- a/templates/frontend/pages/editorialMasthead.tpl +++ b/templates/frontend/pages/editorialMasthead.tpl @@ -15,10 +15,10 @@