Skip to content

Commit

Permalink
Merge pull request #827 from Vitaliy-1/i10506_usergroup_eloquent
Browse files Browse the repository at this point in the history
pkp/pkp-lib#10506 Refactor UserGroup to Eloquent Model
  • Loading branch information
Vitaliy-1 authored Dec 16, 2024
2 parents 2d26ff5 + 9b8868d commit 2fb914a
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 19 deletions.
6 changes: 3 additions & 3 deletions api/v1/submissions/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion classes/search/PreprintSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PKP\submission\PKPSubmission;
use PKP\submission\SubmissionKeywordDAO;
use PKP\user\User;
use PKP\userGroup\UserGroup;

class PreprintSearch extends SubmissionSearch
{
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 4 additions & 3 deletions classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 120 files
5 changes: 4 additions & 1 deletion pages/index/IndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion pages/preprints/PreprintsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PKP\config\Config;
use PKP\plugins\PluginRegistry;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\userGroup\UserGroup;

class PreprintsHandler extends Handler
{
Expand Down Expand Up @@ -88,7 +89,9 @@ public function index($args, $request)
'categories' => iterator_to_array($categories),
'publishedSubmissions' => $publishedSubmissions,
'pubIdPlugins' => PluginRegistry::loadCategory('pubIds', true),
'authorUserGroups' => Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$context->getId()])->getMany()->remember(),
'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds([$context->getId()])
->get(),
'showingStart' => $showingStart,
'showingEnd' => $showingEnd,
'total' => $total,
Expand Down
5 changes: 4 additions & 1 deletion pages/preprints/SectionsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\userGroup\UserGroup;

class SectionsHandler extends Handler
{
Expand Down Expand Up @@ -119,7 +120,9 @@ public function section($args, $request)
'total' => $total,
'nextPage' => $nextPage,
'prevPage' => $prevPage,
'authorUserGroups' => Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$contextId])->getMany()->remember(),
'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds([$contextId])
->get(),
]);

$templateMgr->display('frontend/pages/sections.tpl');
Expand Down
8 changes: 4 additions & 4 deletions pages/search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/generic/citationStyleLanguage
2 changes: 1 addition & 1 deletion plugins/generic/webFeed
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
{fbvFormSection list=true title="manager.sections.form.assignEditors"}
<div>{translate key="manager.sections.form.assignEditors.description"}</div>
{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"
Expand Down

0 comments on commit 2fb914a

Please sign in to comment.