2024-02-04 09:39:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
|
|
|
|
use BookStack\Entities\Models\Page;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
|
|
|
class PageQueries
|
|
|
|
{
|
2024-02-04 12:35:16 -05:00
|
|
|
public function start(): Builder
|
2024-02-04 09:39:01 -05:00
|
|
|
{
|
|
|
|
return Page::query();
|
|
|
|
}
|
|
|
|
|
2024-02-04 12:35:16 -05:00
|
|
|
public function visibleForList(): Builder
|
2024-02-04 09:39:01 -05:00
|
|
|
{
|
2024-02-04 12:35:16 -05:00
|
|
|
return $this->start()
|
2024-02-04 09:39:01 -05:00
|
|
|
->select(array_merge(Page::$listAttributes, ['book_slug' => function ($builder) {
|
|
|
|
$builder->select('slug')
|
|
|
|
->from('books')
|
|
|
|
->whereColumn('books.id', '=', 'pages.book_id');
|
|
|
|
}]));
|
|
|
|
}
|
|
|
|
|
2024-02-04 12:35:16 -05:00
|
|
|
public function currentUserDraftsForList(): Builder
|
2024-02-04 09:39:01 -05:00
|
|
|
{
|
2024-02-04 12:35:16 -05:00
|
|
|
return $this->visibleForList()
|
2024-02-04 09:39:01 -05:00
|
|
|
->where('draft', '=', true)
|
|
|
|
->where('created_by', '=', user()->id);
|
|
|
|
}
|
|
|
|
}
|