-<?php
-
-namespace BookStack\Http\Controllers;
+<?php namespace BookStack\Http\Controllers;
use Activity;
use BookStack\Repos\UserRepo;
use Illuminate\Http\Request;
-
use Illuminate\Support\Facades\Auth;
-use Illuminate\Support\Str;
use BookStack\Http\Requests;
use BookStack\Repos\BookRepo;
use BookStack\Repos\ChapterRepo;
/**
* Display a listing of the book.
- *
* @return Response
*/
public function index()
/**
* Show the form for creating a new book.
- *
* @return Response
*/
public function create()
/**
* Display the specified book.
- *
* @param $slug
* @return Response
*/
/**
* Show the form for editing the specified book.
- *
* @param $slug
* @return Response
*/
/**
* Update the specified book in storage.
- *
* @param Request $request
* @param $slug
* @return Response
if ($additionalQuery !== false && is_callable($additionalQuery)) {
$additionalQuery($query);
}
- return $query->skip($page * $count)->take($count)->get();
+ return $query->with('book')->skip($page * $count)->take($count)->get();
}
/**
{
return $this->restrictionService->enforcePageRestrictions($this->page)
->where('draft', '=', false)
- ->orderBy('updated_at', 'desc')->skip($page * $count)->take($count)->get();
+ ->orderBy('updated_at', 'desc')->with('book')->skip($page * $count)->take($count)->get();
}
/**
<?php namespace BookStack\Services;
-
use BookStack\Entity;
use BookStack\View;
return 1;
}
-
/**
* Get the entities with the most views.
* @param int $count
{
$skipCount = $count * $page;
$query = $this->restrictionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type')
- ->select('id', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
+ ->select('*', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
->groupBy('viewable_id', 'viewable_type')
->orderBy('view_count', 'desc');
if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel));
- $views = $query->with('viewable')->skip($skipCount)->take($count)->get();
- $viewedEntities = $views->map(function ($item) {
- return $item->viewable()->getResults();
- });
- return $viewedEntities;
+ return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable');
}
/**
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
{
if ($this->user === null) return collect();
- $skipCount = $count * $page;
+
$query = $this->restrictionService
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
$query = $query->where('user_id', '=', auth()->user()->id);
- $views = $query->with('viewable')->orderBy('updated_at', 'desc')->skip($skipCount)->take($count)->get();
- $viewedEntities = $views->map(function ($item) {
- return $item->viewable;
- });
- return $viewedEntities;
+ $viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
+ ->skip($count * $page)->take($count)->get()->pluck('viewable');
+ return $viewables;
}
-
/**
* Reset all view counts by deleting all views.
*/
$this->view->truncate();
}
-
}
\ No newline at end of file