Skip to content

Commit

Permalink
pkp/pkp-lib#10506 User Group refactoring to Eloquent Model
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Dec 15, 2024
1 parent 1187580 commit 3ad25f5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
7 changes: 5 additions & 2 deletions api/v1/submissions/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use APP\components\forms\publication\PublicationLicenseForm;
use APP\components\forms\submission\AudienceForm;
use APP\components\forms\submission\PublicationDatesForm;
use APP\facades\Repo;
use APP\file\PublicFileManager;
use APP\publication\Publication;
use APP\submission\Submission;
Expand All @@ -33,6 +32,7 @@
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\security\Role;
use PKP\userGroup\UserGroup;

class SubmissionController extends PKPSubmissionController
{
Expand Down Expand Up @@ -150,7 +150,10 @@ protected function getPublicationLicenseForm(Request $illuminateRequest): JsonRe
$publicationApiUrl = $data['publicationApiUrl']; /** @var String $publicationApiUrl */

$locales = $this->getPublicationFormLocales($context, $submission);
$authorUserGroups = Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $submission->getData('contextId'));
$authorUserGroups = UserGroup::withRoleIds([Role::ROLE_ID_AUTHOR])
->withContextIds([$submission->getData('contextId')])
->get()
->all();

$publicationLicenseForm = new PublicationLicenseForm($publicationApiUrl, $locales, $publication, $context, $authorUserGroups);
$submissionLocale = $submission->getData('locale');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/components/form/publication/PublicationLicenseForm.php
*
Expand All @@ -20,7 +21,7 @@
use APP\press\Press;
use APP\publication\Publication;
use APP\submission\Submission;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Enumerable;
use PKP\components\forms\FieldText;
use PKP\components\forms\publication\PKPPublicationLicenseForm;
use PKP\userGroup\UserGroup;
Expand All @@ -34,7 +35,7 @@ class PublicationLicenseForm extends PKPPublicationLicenseForm
* @param array $locales Supported locales
* @param Publication $publication The publication to change settings for
* @param Press $context The publication's context
* @param LazyCollection<UserGroup> $userGroups User groups in this context
* @param Enumerable<UserGroup> $userGroups User groups in this context
*/
public function __construct($action, $locales, $publication, $context, $userGroups)
{
Expand Down
1 change: 0 additions & 1 deletion classes/monograph/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ public function setSourceChapterId(?int $sourceChapterId): void
public function isPageEnabled(): ?bool
{
return $this->getData('isPageEnabled') || !empty($this->getDoi());
;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion classes/search/MonographSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PKP\db\DAORegistry;
use PKP\plugins\Hook;
use PKP\search\SubmissionSearch;
use PKP\userGroup\UserGroup;

class MonographSearch extends SubmissionSearch
{
Expand Down Expand Up @@ -75,7 +76,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
8 changes: 6 additions & 2 deletions classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

namespace APP\submission;

use APP\facades\Repo;
use APP\publication\Publication;
use PKP\submission\PKPSubmission;
use PKP\userGroup\UserGroup;

class Submission extends PKPSubmission
{
Expand Down Expand Up @@ -67,7 +67,11 @@ 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
5 changes: 4 additions & 1 deletion pages/index/IndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PKP\pages\index\PKPIndexHandler;
use PKP\security\Validation;
use PKP\site\Site;
use PKP\userGroup\UserGroup;

class IndexHandler extends PKPIndexHandler
{
Expand Down Expand Up @@ -129,7 +130,9 @@ public function _displayPressIndexPage($press, $request)
'homepageImage' => $press->getLocalizedSetting('homepageImage'),
'pageTitleTranslated' => $press->getLocalizedSetting('name'),
'displayCreativeCommons' => $press->getSetting('includeCreativeCommons'),
'authorUserGroups' => Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$press->getId()])->getMany()->remember(),
'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds([$press->getId()])
->get(),
]);

$this->_setupAnnouncements($press, $templateMgr);
Expand Down
9 changes: 4 additions & 5 deletions pages/search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace APP\pages\search;

use APP\core\Request;
use APP\facades\Repo;
use APP\handler\Handler;
use APP\search\MonographSearch;
use APP\template\TemplateManager;
use PKP\userGroup\UserGroup;

class SearchHandler extends Handler
{
Expand Down Expand Up @@ -57,10 +57,9 @@ public function search($args, $request)
$templateMgr->assign([
'results' => $monographSearch->retrieveResults($request, $press, [null => $query], $error, null, null, $rangeInfo),
'searchQuery' => $query,
'authorUserGroups' => Repo::userGroup()->getCollector()
->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->filterByContextIds($press ? [$press->getId()] : null)
->getMany()->remember(),
'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])
->withContextIds($press ? [$press->getId()] : null)
->get(),
]);

// Display
Expand Down

0 comments on commit 3ad25f5

Please sign in to comment.