mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-24 19:07:20 +03:00
Removes page/chpater addSelect global query, to load book slug, and instead extracts base queries to be managed in new static class, while updating specific entitiy relation loading to use our more efficient MixedEntityListLoader where appropriate. Related to #4823
32 lines
796 B
PHP
32 lines
796 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Entities\Models\Page;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class PageQueries
|
|
{
|
|
public static function start(): Builder
|
|
{
|
|
return Page::query();
|
|
}
|
|
|
|
public static function visibleForList(): Builder
|
|
{
|
|
return Page::visible()
|
|
->select(array_merge(Page::$listAttributes, ['book_slug' => function ($builder) {
|
|
$builder->select('slug')
|
|
->from('books')
|
|
->whereColumn('books.id', '=', 'pages.book_id');
|
|
}]));
|
|
}
|
|
|
|
public static function currentUserDraftsForList(): Builder
|
|
{
|
|
return static::visibleForList()
|
|
->where('draft', '=', true)
|
|
->where('created_by', '=', user()->id);
|
|
}
|
|
}
|