Skip to content

Commit aa96198

Browse files
committed
Make it more readable
1 parent 3674ed5 commit aa96198

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Http/Controllers/CP/Collections/QueriesAuthorEntries.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Statamic\Http\Controllers\CP\Collections;
44

5-
use Illuminate\Support\Collection as SupportCollection;
65
use Statamic\Contracts\Entries\Collection;
76
use Statamic\Contracts\Query\Builder;
87
use Statamic\Facades\User;
@@ -12,33 +11,35 @@ trait QueriesAuthorEntries
1211
{
1312
protected function queryAuthorEntries(Builder $query, Collection $collection): void
1413
{
15-
$blueprintsWithAuthor = $this->blueprintsWithAuthor($collection->entryBlueprints());
16-
$blueprintsWithoutAuthor = $this->blueprintsWithoutAuthor($collection->entryBlueprints());
14+
$blueprintsWithAuthor = $this->blueprintsWithAuthor($collection);
1715

1816
if (empty($blueprintsWithAuthor)) {
1917
return;
2018
}
2119

2220
$query->where(fn ($query) => $query
23-
->whereNotIn('collectionHandle', [$collection->handle()]) // Needed for entries fieldtypes configured for multiple collections
21+
// Exclude entries from other collections (for entries fieldtypes with multiple collections)
22+
->whereNotIn('collectionHandle', [$collection->handle()])
23+
// Include entries with blueprints where the current user is the author
2424
->orWhere(fn ($query) => $query
2525
->whereIn('blueprint', $blueprintsWithAuthor)
26-
->whereHas('author', fn ($subquery) => $subquery->where('id', User::current()->id()))
26+
->whereHas('author', fn ($query) => $query->where('id', User::current()->id()))
2727
)
28-
->orWhereIn('blueprint', $blueprintsWithoutAuthor)
28+
// Include entries with blueprints that don't have an author
29+
->orWhereIn('blueprint', $this->blueprintsWithoutAuthor($collection))
2930
);
3031
}
3132

32-
protected function blueprintsWithAuthor(SupportCollection $blueprints): array
33+
protected function blueprintsWithAuthor(Collection $collection): array
3334
{
34-
return $blueprints
35+
return $collection->entryBlueprints()
3536
->filter(fn (Blueprint $blueprint) => $blueprint->hasField('author'))
3637
->map->handle()->all();
3738
}
3839

39-
protected function blueprintsWithoutAuthor(SupportCollection $blueprints): array
40+
protected function blueprintsWithoutAuthor(Collection $collection): array
4041
{
41-
return $blueprints
42+
return $collection->entryBlueprints()
4243
->filter(fn (Blueprint $blueprint) => ! $blueprint->hasField('author'))
4344
->map->handle()->all();
4445
}

0 commit comments

Comments
 (0)