X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3286f29a61833327b5701b28db626d0a480b07f9..refs/pull/1688/head:/app/Auth/UserRepo.php diff --git a/app/Auth/UserRepo.php b/app/Auth/UserRepo.php index b2ff0bc58..dec973f6c 100644 --- a/app/Auth/UserRepo.php +++ b/app/Auth/UserRepo.php @@ -6,6 +6,7 @@ use BookStack\Exceptions\NotFoundException; use BookStack\Exceptions\UserUpdateException; use BookStack\Uploads\Image; use Exception; +use Illuminate\Database\Eloquent\Builder; use Images; class UserRepo @@ -48,7 +49,7 @@ class UserRepo /** * Get all the users with their permissions. - * @return \Illuminate\Database\Eloquent\Builder|static + * @return Builder|static */ public function getAllUsers() { @@ -59,7 +60,7 @@ class UserRepo * Get all the users with their permissions in a paginated format. * @param int $count * @param $sortData - * @return \Illuminate\Database\Eloquent\Builder|static + * @return Builder|static */ public function getAllUsersPaginatedAndSorted($count, $sortData) { @@ -197,7 +198,7 @@ class UserRepo $user->delete(); // Delete user profile images - $profileImages = $images = Image::where('type', '=', 'user')->where('created_by', '=', $user->id)->get(); + $profileImages = Image::where('type', '=', 'user')->where('uploaded_to', '=', $user->id)->get(); foreach ($profileImages as $image) { Images::destroy($image); } @@ -223,16 +224,15 @@ class UserRepo */ public function getRecentlyCreated(User $user, $count = 20) { + $createdByUserQuery = function (Builder $query) use ($user) { + $query->where('created_by', '=', $user->id); + }; + return [ - 'pages' => $this->entityRepo->getRecentlyCreated('page', $count, 0, function ($query) use ($user) { - $query->where('created_by', '=', $user->id); - }), - 'chapters' => $this->entityRepo->getRecentlyCreated('chapter', $count, 0, function ($query) use ($user) { - $query->where('created_by', '=', $user->id); - }), - 'books' => $this->entityRepo->getRecentlyCreated('book', $count, 0, function ($query) use ($user) { - $query->where('created_by', '=', $user->id); - }) + 'pages' => $this->entityRepo->getRecentlyCreated('page', $count, 0, $createdByUserQuery), + 'chapters' => $this->entityRepo->getRecentlyCreated('chapter', $count, 0, $createdByUserQuery), + 'books' => $this->entityRepo->getRecentlyCreated('book', $count, 0, $createdByUserQuery), + 'shelves' => $this->entityRepo->getRecentlyCreated('bookshelf', $count, 0, $createdByUserQuery) ]; } @@ -247,6 +247,7 @@ class UserRepo 'pages' => $this->entityRepo->getUserTotalCreated('page', $user), 'chapters' => $this->entityRepo->getUserTotalCreated('chapter', $user), 'books' => $this->entityRepo->getUserTotalCreated('book', $user), + 'shelves' => $this->entityRepo->getUserTotalCreated('bookshelf', $user), ]; }