]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/UserRepo.php
Added recent pages to home view and made the home content more compact
[bookstack] / app / Repos / UserRepo.php
index 380eb24c98c2f691fc1d3d5cd3b6732c9f1f59f1..48541a51aa341aeb576dab3ef91056bee8d1b39b 100644 (file)
@@ -1,9 +1,6 @@
 <?php namespace BookStack\Repos;
 
-
-use BookStack\Page;
 use BookStack\Role;
-use BookStack\Services\EntityService;
 use BookStack\User;
 use Setting;
 
@@ -12,19 +9,19 @@ class UserRepo
 
     protected $user;
     protected $role;
-    protected $entityService;
+    protected $entityRepo;
 
     /**
      * UserRepo constructor.
      * @param User $user
      * @param Role $role
-     * @param EntityService $entityService
+     * @param EntityRepo $entityRepo
      */
-    public function __construct(User $user, Role $role, EntityService $entityService)
+    public function __construct(User $user, Role $role, EntityRepo $entityRepo)
     {
         $this->user = $user;
         $this->role = $role;
-        $this->entityService = $entityService;
+        $this->entityRepo = $entityRepo;
     }
 
     /**
@@ -132,28 +129,35 @@ class UserRepo
     }
 
     /**
-     * Get the pages the the given user has created.
+     * Get the recently created content for this given user.
      * @param User $user
      * @param int $count
-     * @param int $page
      * @return mixed
      */
-    public function getCreatedPages(User $user, $count = 20, $page = 0)
+    public function getRecentlyCreated(User $user, $count = 20)
     {
-        return $this->entityService->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
-            ->skip($page * $count)->take($count)->get();
+        return [
+            'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
+                ->take($count)->get(),
+            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
+                ->take($count)->get(),
+            'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
+                ->take($count)->get()
+        ];
     }
 
     /**
      * Get asset created counts for the give user.
+     * @param User $user
      * @return array
      */
     public function getAssetCounts(User $user)
     {
         return [
-            'pages' => $this->entityService->page->where('created_by', '=', $user->id)->count(),
-            'chapters' => $this->entityService->chapter->where('created_by', '=', $user->id)->count(),
-            'books' => $this->entityService->book->where('created_by', '=', $user->id)->count(),
+            '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(),
         ];
     }
+
 }
\ No newline at end of file