Skip to content

Commit

Permalink
pkp/pkp-lib#10506 Turn User Group to a Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Dec 16, 2024
1 parent 03abd49 commit 17fc029
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
9 changes: 2 additions & 7 deletions api/v1/_dois/BackendDoiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\LazyCollection;
use PKP\db\DAORegistry;
use PKP\userGroup\UserGroup;

Expand Down Expand Up @@ -130,25 +129,21 @@ public function editIssue(Request $illuminateRequest): JsonResponse

Repo::issue()->edit($issue, ['doiId' => $doi->getId()]);
$issue = Repo::issue()->get($issue->getId());
$userGroups = UserGroup::withContextIds([$context->getId()])->get();

return response()->json(
Repo::issue()
->getSchemaMap()
->map(
$issue,
$context,
$this->getUserGroups($context->getId()),
$userGroups,
$this->getGenres($context->getId())
),
Response::HTTP_OK
);
}

protected function getUserGroups(int $contextId): LazyCollection
{
return UserGroup::where('contextId', $contextId)->get();
}

protected function getGenres(int $contextId): array
{
/** @var \PKP\submission\GenreDAO $genreDao */
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 @@ -25,8 +25,8 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\LazyCollection;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
Expand Down Expand Up @@ -267,9 +267,9 @@ public function get(Request $illuminateRequest): JsonResponse
return response()->json($data, Response::HTTP_OK);
}

protected function getUserGroups(int $contextId): LazyCollection
protected function getUserGroups(int $contextId): Collection
{
return UserGroup::where('contextId', $contextId)->get();
return UserGroup::withContextIds([$contextId])->get();
}

protected function getGenres(int $contextId): array
Expand Down
13 changes: 6 additions & 7 deletions classes/issue/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use APP\issue\IssueGalleyDAO;
use APP\journal\Journal;
use Illuminate\Support\Enumerable;
use Illuminate\Support\LazyCollection;
use PKP\db\DAORegistry;
use PKP\services\PKPSchemaService;
use PKP\submission\Genre;
Expand All @@ -33,8 +32,8 @@ class Schema extends \PKP\core\maps\Schema
/** @copydoc \PKP\core\maps\Schema::$schema */
public string $schema = PKPSchemaService::SCHEMA_ISSUE;

/** @var LazyCollection<int,UserGroup> The user groups for this context. */
public LazyCollection $userGroups;
/** @var Enumerable<int,UserGroup> The user groups for this context. */
public Enumerable $userGroups;

/** @var Genre[] The genres for this context. */
public array $genres;
Expand All @@ -44,10 +43,10 @@ class Schema extends \PKP\core\maps\Schema
*
* Includes all properties in the Issue schema
*
* @param LazyCollection<int,UserGroup> $userGroups The user groups of this content
* @param Enumerable<int,UserGroup> $userGroups The user groups of this content
* @param Genre[] $genres The genres of this context
*/
public function map(Issue $item, Journal $context, LazyCollection $userGroups, array $genres): array
public function map(Issue $item, Journal $context, Enumerable $userGroups, array $genres): array
{
$this->userGroups = $userGroups;
$this->genres = $genres;
Expand All @@ -71,10 +70,10 @@ public function summarize(Issue $item, Journal $context): array
*
* @see self::map
*
* @param LazyCollection<int,UserGroup> $userGroups The user groups of this content
* @param Enumerable<int,UserGroup> $userGroups The user groups of this content
* @param Genre[] $genres The genres of this context
*/
public function mapMany(Enumerable $collection, Journal $context, LazyCollection $userGroups, array $genres): Enumerable
public function mapMany(Enumerable $collection, Journal $context, Enumerable $userGroups, array $genres): Enumerable
{
$this->collection = $collection;
return $collection->map(function ($item) use ($context, $userGroups, $genres) {
Expand Down

0 comments on commit 17fc029

Please sign in to comment.