Skip to content
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#10506 user group to use eloquent model #4526

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions api/v1/_dois/BackendDoiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\LazyCollection;
use PKP\db\DAORegistry;
use PKP\userGroup\UserGroup;

class BackendDoiController extends \PKP\API\v1\_dois\PKPBackendDoiController
{
Expand Down Expand Up @@ -145,9 +146,7 @@ public function editIssue(Request $illuminateRequest): JsonResponse

protected function getUserGroups(int $contextId): LazyCollection
{
return Repo::userGroup()->getCollector()
->filterByContextIds([$contextId])
->getMany();
return UserGroup::withContextIds($contextId)->cursor();
}

protected function getGenres(int $contextId): array
Expand Down
6 changes: 3 additions & 3 deletions api/v1/issues/IssueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\submission\GenreDAO;
use PKP\userGroup\UserGroup;

class IssueController extends PKPBaseController
{
Expand Down Expand Up @@ -268,9 +269,8 @@ public function get(Request $illuminateRequest): JsonResponse

protected function getUserGroups(int $contextId): LazyCollection
{
return Repo::userGroup()->getCollector()
->filterByContextIds([$contextId])
->getMany();
return UserGroup::withContextIds($contextId)->cursor();

}

protected function getGenres(int $contextId): array
Expand Down
4 changes: 3 additions & 1 deletion classes/search/ArticleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PKP\plugins\Hook;
use PKP\search\SubmissionSearch;
use PKP\submission\PKPSubmission;
use PKP\userGroup\UserGroup;

class ArticleSearch extends SubmissionSearch
{
Expand Down Expand Up @@ -77,7 +78,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
3 changes: 2 additions & 1 deletion classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use APP\publication\Publication;
use PKP\facades\Locale;
use PKP\submission\PKPSubmission;
use PKP\userGroup\UserGroup;

class Submission extends PKPSubmission
{
Expand Down Expand Up @@ -69,7 +70,7 @@ public function _getContextLicenseFieldValue($locale, $field, $publication = nul
$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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PKP\controllers\grid\users\userSelect\UserSelectGridCellProvider;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\Role;
use PKP\userGroup\UserGroup;

class SubscriberSelectGridHandler extends GridHandler
{
Expand Down Expand Up @@ -65,13 +66,17 @@ public function initialize($request, $args = null)
parent::initialize($request, $args);

$stageId = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_WORKFLOW_STAGE);
$userGroups = Repo::userGroup()->getUserGroupsByStage(
$request->getContext()->getId(),
$stageId
);
$contextId = $request->getContext()->getId();

$userGroups = UserGroup::withContextIds($contextId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserGroup::withContextIds([$contextId])

->whereHas('userGroupStages', function ($query) use ($stageId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you already created helper in the Repository:

PKP\userGroup\Repository::getUserGroupsByStage()

The second option is just use the scope, that is also already created:

UserGroup::withContextIds([$contextId])->withStageIds([$stageId]);

$query->withStageId($stageId);
})
->get();

$this->_userGroupOptions = [];
foreach ($userGroups as $userGroup) {
$this->_userGroupOptions[$userGroup->getId()] = $userGroup->getLocalizedName();
$this->_userGroupOptions[$userGroup->id] = $userGroup->getLocalizedData('name');
}

$this->setTitle('editor.submission.findAndSelectUser');
Expand All @@ -95,7 +100,8 @@ public function initialize($request, $args = null)
null,
null,
$cellProvider,
['alignment' => GridColumn::COLUMN_ALIGNMENT_LEFT,
[
'alignment' => GridColumn::COLUMN_ALIGNMENT_LEFT,
'width' => 30
]
)
Expand Down Expand Up @@ -146,16 +152,12 @@ protected function loadData($request, $filter)
*/
public function renderFilter($request, $filterData = [])
{
$context = $request->getContext();
$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$context->getId()])
->getMany();
$contextId = $request->getContext()->getId();
$userGroups = UserGroup::withContextIds($contextId)->get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserGroup::withContextIds([$contextId])


$userGroupOptions = ['' => __('grid.user.allRoles')];
foreach ($userGroups as $userGroup) {
$userGroupOptions[$userGroup->getId()] = $userGroup->getLocalizedName();
$userGroupOptions[$userGroup->id] = $userGroup->getLocalizedData('name');
}

return parent::renderFilter(
$request,
[
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 243 files
2 changes: 1 addition & 1 deletion lib/ui-library
Submodule ui-library updated 182 files
5 changes: 4 additions & 1 deletion pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use PKP\submission\GenreDAO;
use PKP\submission\PKPSubmission;
use PKP\submissionFile\SubmissionFile;
use PKP\userGroup\UserGroup;
use stdClass;

class ArticleHandler extends Handler
Expand Down Expand Up @@ -286,7 +287,9 @@ public function view($args, $request)
$templateMgr->assign([
'primaryGalleys' => $primaryGalleys,
'supplementaryGalleys' => $supplementaryGalleys,
'userGroupsById' => Repo::userGroup()->getCollector()->filterByPublicationIds([$this->publication->getId()])->getMany()->toArray()
'userGroupsById' => UserGroup::withPublicationIds([$this->publication->getId()])
->get()
->toArray()
]);

// Citations
Expand Down
5 changes: 4 additions & 1 deletion pages/issue/IssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use PKP\security\Validation;
use PKP\submission\GenreDAO;
use PKP\submission\PKPSubmission;
use PKP\userGroup\UserGroup;

class IssueHandler extends Handler
{
Expand Down Expand Up @@ -390,7 +391,9 @@ public static function _setupIssueTemplate(Request $request, Issue $issue, ?Jour
$issueSubmissionsInSection[$sectionId]['articles'][] = $submission;
}

$authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$journal->getId()])->getMany()->remember();
$authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds([$journal->getId()])
->get();
$templateMgr->assign([
'issue' => $issue,
'issueGalleys' => $issueGalleyDao->getByIssueId($issue->getId()),
Expand Down
10 changes: 6 additions & 4 deletions pages/search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use APP\search\ArticleSearch;
use APP\security\authorization\OjsJournalMustPublishPolicy;
use APP\template\TemplateManager;
use PKP\userGroup\UserGroup;

class SearchHandler extends Handler
{
Expand Down Expand Up @@ -160,16 +161,17 @@ public function search($args, $request)
$this->_assignSearchFilters($request, $templateMgr, $searchFilters);
[$orderBy, $orderDir] = $articleSearch->getResultSetOrdering($request);

$authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds($searchFilters['searchJournal'] ? [$searchFilters['searchJournal']->getId()] : null)
->get();

$templateMgr->assign([
'orderBy' => $orderBy,
'orderDir' => $orderDir,
'simDocsEnabled' => true,
'results' => $results,
'error' => $error,
'authorUserGroups' => Repo::userGroup()->getCollector()
->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->filterByContextIds($searchFilters['searchJournal'] ? [$searchFilters['searchJournal']->getId()] : null)
->getMany()->remember(),
'authorUserGroups' => $authorUserGroups,
'searchResultOrderOptions' => $articleSearch->getResultSetOrderingOptions($request),
'searchResultOrderDirOptions' => $articleSearch->getResultSetOrderingDirectionOptions(),
]);
Expand Down
2 changes: 1 addition & 1 deletion plugins/generic/webFeed
10 changes: 4 additions & 6 deletions plugins/reports/articles/ArticleReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PKP\submission\SubmissionDisciplineDAO;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\userGroup\UserGroup;

class ArticleReportPlugin extends ReportPlugin
{
Expand Down Expand Up @@ -90,15 +91,12 @@ public function display($args, $request)
$submissionDisciplineDao = DAORegistry::getDAO('SubmissionDisciplineDAO'); /** @var SubmissionDisciplineDAO $submissionDisciplineDao */
$submissionAgencyDao = DAORegistry::getDAO('SubmissionAgencyDAO'); /** @var SubmissionAgencyDAO $submissionAgencyDao */

$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$context->getId()])
->getMany()
->toArray();
$userGroups = UserGroup::withContextIds([$context->getId()])->get()->toArray();

$editorUserGroupIds = array_map(function ($userGroup) {
return $userGroup->getId();
return $userGroup->id;
}, array_filter($userGroups, function ($userGroup) {
return in_array($userGroup->getRoleId(), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);
return in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);
}));

// Load the data from the database and store it in an array.
Expand Down