From 0ee1c710b77a2bc0b4967560b7651b82c94480bd Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Sat, 14 Dec 2024 21:09:16 +0200 Subject: [PATCH] pkp/pkp-lib#10506 Refactor User Group to Eloquent Model --- api/v1/submissions/SubmissionController.php | 6 +++--- classes/search/PreprintSearch.php | 4 +++- classes/submission/Submission.php | 7 ++++--- pages/index/IndexHandler.php | 5 ++++- pages/search/SearchHandler.php | 8 ++++---- .../grid/settings/sections/form/sectionForm.tpl | 4 ++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index f9664efd9f..2836b2eca2 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -33,6 +33,7 @@ use PKP\security\Role; use PKP\services\PKPSchemaService; use PKP\submission\GenreDAO; +use PKP\userGroup\UserGroup; class SubmissionController extends \PKP\API\v1\submissions\PKPSubmissionController { @@ -154,9 +155,8 @@ public function relatePublication(Request $illuminateRequest): JsonResponse $publication = Repo::publication()->get($publication->getId()); - $userGroups = Repo::userGroup()->getCollector() - ->filterByContextIds([$submission->getData('contextId')]) - ->getMany(); + $userGroups = UserGroup::withContextIds([[$submission->getData('contextId')]]) + ->get(); /** @var GenreDAO $genreDao */ $genreDao = DAORegistry::getDAO('GenreDAO'); diff --git a/classes/search/PreprintSearch.php b/classes/search/PreprintSearch.php index 500a8d70dc..827d0fe75d 100644 --- a/classes/search/PreprintSearch.php +++ b/classes/search/PreprintSearch.php @@ -30,6 +30,7 @@ use PKP\submission\PKPSubmission; use PKP\submission\SubmissionKeywordDAO; use PKP\user\User; +use PKP\userGroup\UserGroup; class PreprintSearch extends SubmissionSearch { @@ -80,7 +81,8 @@ public function getSparseArray($unorderedResults, $orderBy, $orderDir, $exclude) } $i = 0; // Used to prevent ties from clobbering each other - $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->getMany(); + $authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->get(); foreach ($unorderedResults as $submissionId => $data) { // Exclude unwanted IDs. if (in_array($submissionId, $exclude)) { diff --git a/classes/submission/Submission.php b/classes/submission/Submission.php index 3d706462fe..ecc84d4060 100644 --- a/classes/submission/Submission.php +++ b/classes/submission/Submission.php @@ -24,11 +24,10 @@ namespace APP\submission; -use APP\facades\Repo; use APP\publication\Publication; use APP\statistics\StatisticsHelper; -use PKP\facades\Locale; use PKP\submission\PKPSubmission; +use PKP\userGroup\UserGroup; class Submission extends PKPSubmission { @@ -67,7 +66,9 @@ public function _getContextLicenseFieldValue($locale, $field, $publication = nul if (!$publication) { $publication = $this->getCurrentPublication(); } - $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$context->getId()])->getMany(); + $authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$context->getId()]) + ->get(); $fieldValue = [$context->getPrimaryLocale() => $publication->getAuthorString($authorUserGroups)]; break; case 'context': diff --git a/pages/index/IndexHandler.php b/pages/index/IndexHandler.php index 142122953d..bbc026b2da 100644 --- a/pages/index/IndexHandler.php +++ b/pages/index/IndexHandler.php @@ -28,6 +28,7 @@ use PKP\pages\index\PKPIndexHandler; use PKP\plugins\PluginRegistry; use PKP\security\Validation; +use PKP\userGroup\UserGroup; class IndexHandler extends PKPIndexHandler { @@ -95,7 +96,9 @@ public function index($args, $request) 'categories' => iterator_to_array($categories), 'pubIdPlugins' => PluginRegistry::loadCategory('pubIds', true), 'publishedSubmissions' => $publishedSubmissions->toArray(), - 'authorUserGroups' => Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$server->getId()])->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$server->getId()]) + ->get(), ]); $templateMgr->registerClass(Server::class, Server::class); diff --git a/pages/search/SearchHandler.php b/pages/search/SearchHandler.php index 47fecbb93d..c01bdca27b 100644 --- a/pages/search/SearchHandler.php +++ b/pages/search/SearchHandler.php @@ -22,6 +22,7 @@ use APP\search\PreprintSearch; use APP\security\authorization\OpsServerMustPublishPolicy; use APP\template\TemplateManager; +use PKP\userGroup\UserGroup; class SearchHandler extends Handler { @@ -167,10 +168,9 @@ public function search($args, $request) 'simDocsEnabled' => true, 'results' => $results, 'error' => $error, - 'authorUserGroups' => Repo::userGroup()->getCollector() - ->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) - ->filterByContextIds($searchFilters['searchServer'] ? [$searchFilters['searchServer']->getId()] : null) - ->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds($searchFilters['searchServer'] ? [$searchFilters['searchServer']->getId()] : null) + ->get(), ]); $templateMgr->display('frontend/pages/search.tpl'); } diff --git a/templates/controllers/grid/settings/sections/form/sectionForm.tpl b/templates/controllers/grid/settings/sections/form/sectionForm.tpl index 5514ea1b18..f50898f922 100644 --- a/templates/controllers/grid/settings/sections/form/sectionForm.tpl +++ b/templates/controllers/grid/settings/sections/form/sectionForm.tpl @@ -66,8 +66,8 @@ {fbvFormSection list=true title="manager.sections.form.assignEditors"}
{translate key="manager.sections.form.assignEditors.description"}
{foreach from=$assignableUserGroups item="assignableUserGroup"} - {assign var="role" value=$assignableUserGroup.userGroup->getLocalizedName()} - {assign var="userGroupId" value=$assignableUserGroup.userGroup->getId()} + {assign var="role" value=$assignableUserGroup.userGroup->getLocalizedData('name')} + {assign var="userGroupId" value=$assignableUserGroup.userGroup->id} {foreach from=$assignableUserGroup.users item=$username key="id"} {fbvElement type="checkbox"