Skip to content

Commit

Permalink
Improve buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Mar 12, 2024
1 parent a248b3b commit 25f091b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Http/Controllers/Admin/FeaturedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ private function getFeaturedItemsByBucket($featuredSection, $featuredSectionKey)
*/
private function getFeaturedSources(Request $request, $featuredSection, string $search = null, string $contentType = null)

Check warning on line 136 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L136

Added line #L136 was not covered by tests
{
$fetchedModules = [];
$featuredSources = [];

foreach ($featuredSection['buckets'] as $bucket) {
foreach ($bucket['bucketables'] as $bucketable) {

Check warning on line 141 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L140-L141

Added lines #L140 - L141 were not covered by tests
$module = $bucketable['module'];
if ($contentType !== null && $module !== $contentType) {

if ((!empty($contentType) && $module !== $contentType) || isset($featuredSources[$module])) {
continue;

Check warning on line 145 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L144-L145

Added lines #L144 - L145 were not covered by tests
}

Expand All @@ -154,25 +154,27 @@ private function getFeaturedSources(Request $request, $featuredSection, string $
$scopes[$searchField] = $search;
}

$items = $fetchedModules[$module] ?? $repository->get(
$bucketable['with'] ?? [],
($bucketable['scopes'] ?? []) + ($scopes ?? []),
$bucketable['orders'] ?? [],
$bucketable['per_page'] ?? $request->get('offset') ?? 10,
true
)->appends('bucketable', $module);
$items = null;
if (!empty($contentType) || empty($fetchedModules)) {

Check failure on line 158 in src/Http/Controllers/Admin/FeaturedController.php

View workflow job for this annotation

GitHub Actions / lint

Variable $fetchedModules in empty() is never defined.
$items = $repository->get(
$bucketable['with'] ?? [],
($bucketable['scopes'] ?? []) + ($scopes ?? []),
$bucketable['orders'] ?? [],
$bucketable['per_page'] ?? $request->get('offset') ?? 10,
true
)->appends('bucketable', $module);

Check warning on line 165 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L157-L165

Added lines #L157 - L165 were not covered by tests
}

$morphClass = $repository->getBaseModel()->getMorphClass();

Check warning on line 168 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L168

Added line #L168 was not covered by tests

$fetchedModules[$module] = $items;
$name = $bucketable['name'] ?? ucfirst($module);

Check warning on line 170 in src/Http/Controllers/Admin/FeaturedController.php

View check run for this annotation

Codecov / codecov/patch

src/Http/Controllers/Admin/FeaturedController.php#L170

Added line #L170 was not covered by tests

$featuredSources[$module] = [
'name' => $name,
'type' => $morphClass,
'maxPage' => $items->lastPage(),
'offset' => $items->perPage(),
'items' => $items->map(function ($item) use ($morphClass, $name, $translated, $withImage) {
'maxPage' => $items?->lastPage(),
'offset' => $items?->perPage(),
'items' => $items?->map(function ($item) use ($morphClass, $name, $translated, $withImage) {

Check failure on line 177 in src/Http/Controllers/Admin/FeaturedController.php

View workflow job for this annotation

GitHub Actions / lint

Anonymous function has an unused use $name.
return [
'id' => $item->id,
'name' => $item->titleInBucket ?? $item->title,
Expand Down

0 comments on commit 25f091b

Please sign in to comment.