use BookStack\Entities\Bookshelf;
use BookStack\Entities\Chapter;
use BookStack\Entities\Entity;
+use BookStack\Entities\EntityProvider;
use BookStack\Entities\Page;
use BookStack\Ownable;
use Illuminate\Database\Connection;
protected $userRoles = false;
protected $currentUserModel = false;
- public $book;
- public $chapter;
- public $page;
- public $bookshelf;
-
+ /**
+ * @var Connection
+ */
protected $db;
+ /**
+ * @var JointPermission
+ */
protected $jointPermission;
+
+ /**
+ * @var Role
+ */
protected $role;
+
+ /**
+ * @var EntityPermission
+ */
protected $entityPermission;
+ /**
+ * @var EntityProvider
+ */
+ protected $entityProvider;
+
protected $entityCache;
/**
* @param EntityPermission $entityPermission
* @param Role $role
* @param Connection $db
- * @param Bookshelf $bookshelf
- * @param Book $book
- * @param \BookStack\Entities\Chapter $chapter
- * @param \BookStack\Entities\Page $page
+ * @param EntityProvider $entityProvider
*/
public function __construct(
JointPermission $jointPermission,
Permissions\EntityPermission $entityPermission,
Role $role,
Connection $db,
- Bookshelf $bookshelf,
- Book $book,
- Chapter $chapter,
- Page $page
+ EntityProvider $entityProvider
) {
$this->db = $db;
$this->jointPermission = $jointPermission;
$this->entityPermission = $entityPermission;
$this->role = $role;
- $this->bookshelf = $bookshelf;
- $this->book = $book;
- $this->chapter = $chapter;
- $this->page = $page;
+ $this->entityProvider = $entityProvider;
}
/**
return $this->entityCache['book']->get($bookId);
}
- $book = $this->book->find($bookId);
+ $book = $this->entityProvider->book->find($bookId);
if ($book === null) {
$book = false;
}
return $this->entityCache['chapter']->get($chapterId);
}
- $chapter = $this->chapter->find($chapterId);
+ $chapter = $this->entityProvider->chapter->find($chapterId);
if ($chapter === null) {
$chapter = false;
}
});
// Chunk through all bookshelves
- $this->bookshelf->newQuery()->select(['id', 'restricted', 'created_by'])
+ $this->entityProvider->bookshelf->newQuery()->select(['id', 'restricted', 'created_by'])
->chunk(50, function ($shelves) use ($roles) {
$this->buildJointPermissionsForShelves($shelves, $roles);
});
*/
protected function bookFetchQuery()
{
- return $this->book->newQuery()->select(['id', 'restricted', 'created_by'])->with(['chapters' => function ($query) {
+ return $this->entityProvider->book->newQuery()
+ ->select(['id', 'restricted', 'created_by'])->with(['chapters' => function ($query) {
$query->select(['id', 'restricted', 'created_by', 'book_id']);
}, 'pages' => function ($query) {
$query->select(['id', 'restricted', 'created_by', 'book_id', 'chapter_id']);
});
// Chunk through all bookshelves
- $this->bookshelf->newQuery()->select(['id', 'restricted', 'created_by'])
+ $this->entityProvider->bookshelf->newQuery()->select(['id', 'restricted', 'created_by'])
->chunk(50, function ($shelves) use ($roles) {
$this->buildJointPermissionsForShelves($shelves, $roles);
});
*/
public function bookChildrenQuery($book_id, $filterDrafts = false, $fetchPageContent = false)
{
- $pageSelect = $this->db->table('pages')->selectRaw($this->page->entityRawQuery($fetchPageContent))->where('book_id', '=', $book_id)->where(function ($query) use ($filterDrafts) {
+ $entities = $this->entityProvider;
+ $pageSelect = $this->db->table('pages')->selectRaw($entities->page->entityRawQuery($fetchPageContent))
+ ->where('book_id', '=', $book_id)->where(function ($query) use ($filterDrafts) {
$query->where('draft', '=', 0);
if (!$filterDrafts) {
$query->orWhere(function ($query) {
});
}
});
- $chapterSelect = $this->db->table('chapters')->selectRaw($this->chapter->entityRawQuery())->where('book_id', '=', $book_id);
+ $chapterSelect = $this->db->table('chapters')->selectRaw($entities->chapter->entityRawQuery())->where('book_id', '=', $book_id);
$query = $this->db->query()->select('*')->from($this->db->raw("({$pageSelect->toSql()} UNION {$chapterSelect->toSql()}) AS U"))
->mergeBindings($pageSelect)->mergeBindings($chapterSelect);
$this->currentAction = 'view';
$tableDetails = ['tableName' => $tableName, 'entityIdColumn' => $entityIdColumn];
- $pageMorphClass = $this->page->getMorphClass();
+ $pageMorphClass = $this->entityProvider->page->getMorphClass();
$q = $query->where(function ($query) use ($tableDetails, $pageMorphClass) {
$query->where(function ($query) use (&$tableDetails, $pageMorphClass) {
$query->whereExists(function ($permissionQuery) use (&$tableDetails, $pageMorphClass) {
public function getAssetCounts(User $user)
{
return [
- 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
- 'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(),
- 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
+ 'pages' => $this->entityRepo->getUserTotalCreated('page', $user),
+ 'chapters' => $this->entityRepo->getUserTotalCreated('chapter', $user),
+ 'books' => $this->entityRepo->getUserTotalCreated('book', $user),
];
}
use BookStack\Auth\Permissions\EntityPermission;
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Ownable;
+use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\MorphMany;
+/**
+ * Class Entity
+ * The base class for book-like items such as pages, chapters & books.
+ * This is not a database model in itself but extended.
+ *
+ * @property integer $id
+ * @property string $name
+ * @property string $slug
+ * @property Carbon $created_at
+ * @property Carbon $updated_at
+ * @property int $created_by
+ * @property int $updated_by
+ * @property boolean $restricted
+ *
+ * @package BookStack\Entities
+ */
class Entity extends Ownable
{
/**
* @var Bookshelf
*/
- protected $bookshelf;
+ public $bookshelf;
/**
* @var Book
*/
- protected $book;
+ public $book;
/**
* @var Chapter
*/
- protected $chapter;
+ public $chapter;
/**
* @var Page
*/
- protected $page;
+ public $page;
/**
* @var PageRevision
*/
- protected $pageRevision;
+ public $pageRevision;
/**
* EntityProvider constructor.
];
}
+ /**
+ * Get an entity instance by it's basic name.
+ * @param string $type
+ * @return Entity
+ */
+ public function get(string $type)
+ {
+ $type = strtolower($type);
+ return $this->all()[$type];
+ }
+
}
\ No newline at end of file
use BookStack\Actions\TagRepo;
use BookStack\Actions\ViewService;
use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Auth\User;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\NotifyException;
use BookStack\Uploads\AttachmentService;
use Carbon\Carbon;
use DOMDocument;
use DOMXPath;
+use Illuminate\Http\Request;
use Illuminate\Support\Collection;
class EntityRepo
{
- /**
- * @var \BookStack\Entities\Bookshelf
- */
- public $bookshelf;
-
- /**
- * @var \BookStack\Entities\Book $book
- */
- public $book;
-
- /**
- * @var Chapter
- */
- public $chapter;
-
- /**
- * @var Page
- */
- public $page;
-
- /**
- * @var PageRevision
- */
- protected $pageRevision;
/**
- * Base entity instances keyed by type
- * @var []Entity
+ * @var EntityProvider
*/
- protected $entities;
+ protected $entityProvider;
/**
* @var PermissionService
protected $viewService;
/**
- * @var \BookStack\Actions\TagRepo
+ * @var TagRepo
*/
protected $tagRepo;
/**
* EntityRepo constructor.
- * @param \BookStack\Entities\Bookshelf $bookshelf
- * @param \BookStack\Entities\Book $book
- * @param Chapter $chapter
- * @param \BookStack\Entities\Page $page
- * @param \BookStack\Entities\PageRevision $pageRevision
+ * @param EntityProvider $entityProvider
* @param ViewService $viewService
* @param PermissionService $permissionService
- * @param \BookStack\Actions\TagRepo $tagRepo
+ * @param TagRepo $tagRepo
* @param SearchService $searchService
*/
public function __construct(
- Bookshelf $bookshelf,
- Book $book,
- Chapter $chapter,
- Page $page,
- PageRevision $pageRevision,
+ EntityProvider $entityProvider,
ViewService $viewService,
PermissionService $permissionService,
TagRepo $tagRepo,
SearchService $searchService
) {
- $this->bookshelf = $bookshelf;
- $this->book = $book;
- $this->chapter = $chapter;
- $this->page = $page;
- $this->pageRevision = $pageRevision;
- $this->entities = [
- 'bookshelf' => $this->bookshelf,
- 'page' => $this->page,
- 'chapter' => $this->chapter,
- 'book' => $this->book
- ];
+ $this->entityProvider = $entityProvider;
$this->viewService = $viewService;
$this->permissionService = $permissionService;
$this->tagRepo = $tagRepo;
$this->searchService = $searchService;
}
- /**
- * Get an entity instance via type.
- * @param $type
- * @return \BookStack\Entities\Entity
- */
- protected function getEntity($type)
- {
- return $this->entities[strtolower($type)];
- }
-
/**
* Base query for searching entities via permission system
* @param string $type
* @param bool $allowDrafts
+ * @param string $permission
* @return \Illuminate\Database\Query\Builder
*/
protected function entityQuery($type, $allowDrafts = false, $permission = 'view')
{
- $q = $this->permissionService->enforceEntityRestrictions($type, $this->getEntity($type), $permission);
+ $q = $this->permissionService->enforceEntityRestrictions($type, $this->entityProvider->get($type), $permission);
if (strtolower($type) === 'page' && !$allowDrafts) {
$q = $q->where('draft', '=', false);
}
*/
public function getById($type, $id, $allowDrafts = false, $ignorePermissions = false)
{
+ $query = $this->entityQuery($type, $allowDrafts);
+
+ if ($ignorePermissions) {
+ $query = $this->entityProvider->get($type)->newQuery();
+ }
+
+ return $query->find($id);
+ }
+
+ /**
+ * @param string $type
+ * @param []int $ids
+ * @param bool $allowDrafts
+ * @param bool $ignorePermissions
+ * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|Collection
+ */
+ public function getManyById($type, $ids, $allowDrafts = false, $ignorePermissions = false)
+ {
+ $query = $this->entityQuery($type, $allowDrafts);
+
if ($ignorePermissions) {
- $entity = $this->getEntity($type);
- return $entity->newQuery()->find($id);
+ $query = $this->entityProvider->get($type)->newQuery();
}
- return $this->entityQuery($type, $allowDrafts)->find($id);
+
+ return $query->whereIn('id', $ids)->get();
}
/**
if (strtolower($type) === 'chapter' || strtolower($type) === 'page') {
$q = $q->where('book_id', '=', function ($query) use ($bookSlug) {
$query->select('id')
- ->from($this->book->getTable())
+ ->from($this->entityProvider->book->getTable())
->where('slug', '=', $bookSlug)->limit(1);
});
}
*/
public function getPageByOldSlug($pageSlug, $bookSlug)
{
- $revision = $this->pageRevision->where('slug', '=', $pageSlug)
+ $revision = $this->entityProvider->pageRevision->where('slug', '=', $pageSlug)
->whereHas('page', function ($query) {
$this->permissionService->enforceEntityRestrictions('page', $query);
})
*/
public function getRecentlyCreated($type, $count = 20, $page = 0, $additionalQuery = false)
{
- $query = $this->permissionService->enforceEntityRestrictions($type, $this->getEntity($type))
+ $query = $this->permissionService->enforceEntityRestrictions($type, $this->entityProvider->get($type))
->orderBy('created_at', 'desc');
if (strtolower($type) === 'page') {
$query = $query->where('draft', '=', false);
*/
public function getRecentlyUpdated($type, $count = 20, $page = 0, $additionalQuery = false)
{
- $query = $this->permissionService->enforceEntityRestrictions($type, $this->getEntity($type))
+ $query = $this->permissionService->enforceEntityRestrictions($type, $this->entityProvider->get($type))
->orderBy('updated_at', 'desc');
if (strtolower($type) === 'page') {
$query = $query->where('draft', '=', false);
*/
public function getRecentlyViewed($type, $count = 10, $page = 0)
{
- $filter = is_bool($type) ? false : $this->getEntity($type);
+ $filter = is_bool($type) ? false : $this->entityProvider->get($type);
return $this->viewService->getUserRecentlyViewed($count, $page, $filter);
}
*/
public function getPopular($type, $count = 10, $page = 0)
{
- $filter = is_bool($type) ? false : $this->getEntity($type);
+ $filter = is_bool($type) ? false : $this->entityProvider->get($type);
return $this->viewService->getPopular($count, $page, $filter);
}
* Get draft pages owned by the current user.
* @param int $count
* @param int $page
+ * @return Collection
*/
public function getUserDraftPages($count = 20, $page = 0)
{
- return $this->page->where('draft', '=', true)
+ return $this->entityProvider->page->where('draft', '=', true)
->where('created_by', '=', user()->id)
->orderBy('updated_at', 'desc')
->skip($count * $page)->take($count)->get();
}
+ /**
+ * Get the number of entities the given user has created.
+ * @param string $type
+ * @param User $user
+ * @return int
+ */
+ public function getUserTotalCreated(string $type, User $user)
+ {
+ return $this->entityProvider->get($type)
+ ->where('created_by', '=', $user->id)->count();
+ }
+
/**
* Get the child items for a chapter sorted by priority but
* with draft items floated to the top.
$tree = [];
foreach ($q as $index => $rawEntity) {
- if ($rawEntity->entity_type === $this->page->getMorphClass()) {
- $entities[$index] = $this->page->newFromBuilder($rawEntity);
+ if ($rawEntity->entity_type === $this->entityProvider->page->getMorphClass()) {
+ $entities[$index] = $this->entityProvider->page->newFromBuilder($rawEntity);
if ($renderPages) {
$entities[$index]->html = $rawEntity->html;
$entities[$index]->html = $this->renderPage($entities[$index]);
};
- } else if ($rawEntity->entity_type === $this->chapter->getMorphClass()) {
- $entities[$index] = $this->chapter->newFromBuilder($rawEntity);
+ } else if ($rawEntity->entity_type === $this->entityProvider->chapter->getMorphClass()) {
+ $entities[$index] = $this->entityProvider->chapter->newFromBuilder($rawEntity);
$key = $entities[$index]->entity_type . ':' . $entities[$index]->id;
$parents[$key] = $entities[$index];
$parents[$key]->setAttribute('pages', collect());
if ($entity->chapter_id === 0 || $entity->chapter_id === '0') {
continue;
}
- $parentKey = $this->chapter->getMorphClass() . ':' . $entity->chapter_id;
+ $parentKey = $this->entityProvider->chapter->getMorphClass() . ':' . $entity->chapter_id;
if (!isset($parents[$parentKey])) {
$tree[] = $entity;
continue;
*/
protected function slugExists($type, $slug, $currentId = false, $bookId = false)
{
- $query = $this->getEntity($type)->where('slug', '=', $slug);
+ $query = $this->entityProvider->get($type)->where('slug', '=', $slug);
if (strtolower($type) === 'page' || strtolower($type) === 'chapter') {
$query = $query->where('book_id', '=', $bookId);
}
/**
* Updates entity restrictions from a request
- * @param $request
+ * @param Request $request
* @param \BookStack\Entities\Entity $entity
+ * @throws \Throwable
*/
- public function updateEntityPermissionsFromRequest($request, Entity $entity)
+ public function updateEntityPermissionsFromRequest(Request $request, Entity $entity)
{
$entity->restricted = $request->get('restricted', '') === 'true';
$entity->permissions()->delete();
public function createFromInput($type, $input = [], $book = false)
{
$isChapter = strtolower($type) === 'chapter';
- $entityModel = $this->getEntity($type)->newInstance($input);
+ $entityModel = $this->entityProvider->get($type)->newInstance($input);
$entityModel->slug = $this->findSuitableSlug($type, $entityModel->name, false, $isChapter ? $book->id : false);
$entityModel->created_by = user()->id;
$entityModel->updated_by = user()->id;
*/
public function getDraftPage(Book $book, $chapter = false)
{
- $page = $this->page->newInstance();
+ $page = $this->entityProvider->page->newInstance();
$page->name = trans('entities.pages_initial_name');
$page->created_by = user()->id;
$page->updated_by = user()->id;
}
$book->pages()->save($page);
- $page = $this->page->find($page->id);
+ $page = $this->entityProvider->page->find($page->id);
$this->permissionService->buildJointPermissionsForEntity($page);
return $page;
}
*/
public function savePageRevision(Page $page, $summary = null)
{
- $revision = $this->pageRevision->newInstance($page->toArray());
+ $revision = $this->entityProvider->pageRevision->newInstance($page->toArray());
if (setting('app-editor') !== 'markdown') {
$revision->markdown = '';
}
$revisionLimit = config('app.revision_limit');
if ($revisionLimit !== false) {
- $revisionsToDelete = $this->pageRevision->where('page_id', '=', $page->id)
+ $revisionsToDelete = $this->entityProvider->pageRevision->where('page_id', '=', $page->id)
->orderBy('created_at', 'desc')->skip(intval($revisionLimit))->take(10)->get(['id']);
if ($revisionsToDelete->count() > 0) {
- $this->pageRevision->whereIn('id', $revisionsToDelete->pluck('id'))->delete();
+ $this->entityProvider->pageRevision->whereIn('id', $revisionsToDelete->pluck('id'))->delete();
}
}
*/
protected function userUpdatePageDraftsQuery(Page $page, $userId)
{
- return $this->pageRevision->where('created_by', '=', $userId)
+ return $this->entityProvider->pageRevision->where('created_by', '=', $userId)
->where('type', 'update_draft')
->where('page_id', '=', $page->id)
->orderBy('created_at', 'desc');
*/
protected function activePageEditingQuery(Page $page, $minRange = null)
{
- $query = $this->pageRevision->where('type', '=', 'update_draft')
+ $query = $this->entityProvider->pageRevision->where('type', '=', 'update_draft')
->where('page_id', '=', $page->id)
->where('updated_at', '>', $page->updated_at)
->where('created_by', '!=', user()->id)
if ($drafts->count() > 0) {
$draft = $drafts->first();
} else {
- $draft = $this->pageRevision->newInstance();
+ $draft = $this->entityProvider->pageRevision->newInstance();
$draft->page_id = $page->id;
$draft->slug = $page->slug;
$draft->book_slug = $page->book->slug;
use BookStack\Auth\Permissions\PermissionService;
use Illuminate\Database\Connection;
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
class SearchService
{
+ /**
+ * @var SearchTerm
+ */
protected $searchTerm;
- protected $bookshelf;
- protected $book;
- protected $chapter;
- protected $page;
+
+ /**
+ * @var EntityProvider
+ */
+ protected $entityProvider;
+
+ /**
+ * @var Connection
+ */
protected $db;
- protected $permissionService;
/**
- * @var Entity[]
+ * @var PermissionService
*/
- protected $entities;
+ protected $permissionService;
+
/**
* Acceptable operators to be used in a query
/**
* SearchService constructor.
* @param SearchTerm $searchTerm
- * @param Bookshelf $bookshelf
- * @param \BookStack\Entities\Book $book
- * @param \BookStack\Entities\Chapter $chapter
- * @param Page $page
+ * @param EntityProvider $entityProvider
* @param Connection $db
* @param PermissionService $permissionService
*/
- public function __construct(SearchTerm $searchTerm, Bookshelf $bookshelf, Book $book, Chapter $chapter, Page $page, Connection $db, PermissionService $permissionService)
+ public function __construct(SearchTerm $searchTerm, EntityProvider $entityProvider, Connection $db, PermissionService $permissionService)
{
$this->searchTerm = $searchTerm;
- $this->bookshelf = $bookshelf;
- $this->book = $book;
- $this->chapter = $chapter;
- $this->page = $page;
+ $this->entityProvider = $entityProvider;
$this->db = $db;
- $this->entities = [
- 'bookshelf' => $this->bookshelf,
- 'page' => $this->page,
- 'chapter' => $this->chapter,
- 'book' => $this->book
- ];
$this->permissionService = $permissionService;
}
public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20, $action = 'view')
{
$terms = $this->parseSearchString($searchString);
- $entityTypes = array_keys($this->entities);
+ $entityTypes = array_keys($this->entityProvider->all());
$entityTypesToSearch = $entityTypes;
if ($entityType !== 'all') {
* @param array $terms
* @param string $entityType
* @param string $action
- * @return \Illuminate\Database\Eloquent\Builder
+ * @return EloquentBuilder
*/
protected function buildEntitySearchQuery($terms, $entityType = 'page', $action = 'view')
{
- $entity = $this->getEntity($entityType);
+ $entity = $this->entityProvider->get($entityType);
$entitySelect = $entity->newQuery();
// Handle normal search terms
if (count($terms['search']) > 0) {
$subQuery = $this->db->table('search_terms')->select('entity_id', 'entity_type', \DB::raw('SUM(score) as score'));
- $subQuery->where('entity_type', '=', 'BookStack\\' . ucfirst($entityType));
+ $subQuery->where('entity_type', '=', $entity->getMorphClass());
$subQuery->where(function (Builder $query) use ($terms) {
foreach ($terms['search'] as $inputTerm) {
$query->orWhere('term', 'like', $inputTerm .'%');
// Handle exact term matching
if (count($terms['exact']) > 0) {
- $entitySelect->where(function (\Illuminate\Database\Eloquent\Builder $query) use ($terms, $entity) {
+ $entitySelect->where(function (EloquentBuilder $query) use ($terms, $entity) {
foreach ($terms['exact'] as $inputTerm) {
- $query->where(function (\Illuminate\Database\Eloquent\Builder $query) use ($inputTerm, $entity) {
+ $query->where(function (EloquentBuilder $query) use ($inputTerm, $entity) {
$query->where('name', 'like', '%'.$inputTerm .'%')
->orWhere($entity->textField, 'like', '%'.$inputTerm .'%');
});
/**
* Apply a tag search term onto a entity query.
- * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param EloquentBuilder $query
* @param string $tagTerm
* @return mixed
*/
- protected function applyTagSearch(\Illuminate\Database\Eloquent\Builder $query, $tagTerm)
+ protected function applyTagSearch(EloquentBuilder $query, $tagTerm)
{
preg_match("/^(.*?)((".$this->getRegexEscapedOperators().")(.*?))?$/", $tagTerm, $tagSplit);
- $query->whereHas('tags', function (\Illuminate\Database\Eloquent\Builder $query) use ($tagSplit) {
+ $query->whereHas('tags', function (EloquentBuilder $query) use ($tagSplit) {
$tagName = $tagSplit[1];
$tagOperator = count($tagSplit) > 2 ? $tagSplit[3] : '';
$tagValue = count($tagSplit) > 3 ? $tagSplit[4] : '';
return $query;
}
- /**
- * Get an entity instance via type.
- * @param $type
- * @return Entity
- */
- protected function getEntity($type)
- {
- return $this->entities[strtolower($type)];
- }
-
/**
* Index the given entity.
* @param Entity $entity
{
$this->searchTerm->truncate();
- foreach ($this->entities as $entityModel) {
+ foreach ($this->entityProvider->all() as $entityModel) {
$selectFields = ['id', 'name', $entityModel->textField];
$entityModel->newQuery()->select($selectFields)->chunk(1000, function ($entities) {
$this->indexEntities($entities);
* Custom entity search filters
*/
- protected function filterUpdatedAfter(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterUpdatedAfter(EloquentBuilder $query, Entity $model, $input)
{
try {
$date = date_create($input);
$query->where('updated_at', '>=', $date);
}
- protected function filterUpdatedBefore(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterUpdatedBefore(EloquentBuilder $query, Entity $model, $input)
{
try {
$date = date_create($input);
$query->where('updated_at', '<', $date);
}
- protected function filterCreatedAfter(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterCreatedAfter(EloquentBuilder $query, Entity $model, $input)
{
try {
$date = date_create($input);
$query->where('created_at', '>=', $date);
}
- protected function filterCreatedBefore(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterCreatedBefore(EloquentBuilder $query, Entity $model, $input)
{
try {
$date = date_create($input);
$query->where('created_at', '<', $date);
}
- protected function filterCreatedBy(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input)
{
if (!is_numeric($input) && $input !== 'me') {
return;
$query->where('created_by', '=', $input);
}
- protected function filterUpdatedBy(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterUpdatedBy(EloquentBuilder $query, Entity $model, $input)
{
if (!is_numeric($input) && $input !== 'me') {
return;
$query->where('updated_by', '=', $input);
}
- protected function filterInName(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterInName(EloquentBuilder $query, Entity $model, $input)
{
$query->where('name', 'like', '%' .$input. '%');
}
- protected function filterInTitle(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterInTitle(EloquentBuilder $query, Entity $model, $input)
{
$this->filterInName($query, $model, $input);
}
- protected function filterInBody(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterInBody(EloquentBuilder $query, Entity $model, $input)
{
$query->where($model->textField, 'like', '%' .$input. '%');
}
- protected function filterIsRestricted(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterIsRestricted(EloquentBuilder $query, Entity $model, $input)
{
$query->where('restricted', '=', true);
}
- protected function filterViewedByMe(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterViewedByMe(EloquentBuilder $query, Entity $model, $input)
{
$query->whereHas('views', function ($query) {
$query->where('user_id', '=', user()->id);
});
}
- protected function filterNotViewedByMe(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterNotViewedByMe(EloquentBuilder $query, Entity $model, $input)
{
$query->whereDoesntHave('views', function ($query) {
$query->where('user_id', '=', user()->id);
});
}
- protected function filterSortBy(\Illuminate\Database\Eloquent\Builder $query, Entity $model, $input)
+ protected function filterSortBy(EloquentBuilder $query, Entity $model, $input)
{
$functionName = camel_case('sort_by_' . $input);
if (method_exists($this, $functionName)) {
* Sorting filter options
*/
- protected function sortByLastCommented(\Illuminate\Database\Eloquent\Builder $query, Entity $model)
+ protected function sortByLastCommented(EloquentBuilder $query, Entity $model)
{
$commentsTable = $this->db->getTablePrefix() . 'comments';
$morphClass = str_replace('\\', '\\\\', $model->getMorphClass());
// Get the books involved in the sort
$bookIdsInvolved = $bookIdsInvolved->unique()->toArray();
- $booksInvolved = $this->entityRepo->book->newQuery()->whereIn('id', $bookIdsInvolved)->get();
+ $booksInvolved = $this->entityRepo->getManyById('book', $bookIdsInvolved, false, true);
// Throw permission error if invalid ids or inaccessible books given.
if (count($bookIdsInvolved) !== count($booksInvolved)) {
$this->showPermissionError();
/**
* Get the page this file was uploaded to.
- * @return Page
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function page()
{
* ImageRepo constructor.
* @param Image $image
* @param ImageService $imageService
- * @param \BookStack\Auth\\BookStack\Auth\Permissions\PermissionService $permissionService
+ * @param \BookStack\Auth\Permissions\PermissionService $permissionService
* @param \BookStack\Entities\Page $page
*/
public function __construct(Image $image, ImageService $imageService, PermissionService $permissionService, Page $page)