]> BookStack Code Mirror - bookstack/blob - app/Repos/EntityRepo.php
Merge branch 'custom_role_system'
[bookstack] / app / Repos / EntityRepo.php
1 <?php namespace BookStack\Repos;
2
3
4 use BookStack\Book;
5 use BookStack\Chapter;
6 use BookStack\Page;
7 use BookStack\Services\RestrictionService;
8
9 class EntityRepo
10 {
11
12     public $book;
13     public $chapter;
14     public $page;
15     private $restrictionService;
16
17     /**
18      * EntityService constructor.
19      * @param Book $book
20      * @param Chapter $chapter
21      * @param Page $page
22      * @param RestrictionService $restrictionService
23      */
24     public function __construct(Book $book, Chapter $chapter, Page $page, RestrictionService $restrictionService)
25     {
26         $this->book = $book;
27         $this->chapter = $chapter;
28         $this->page = $page;
29         $this->restrictionService = $restrictionService;
30     }
31
32     /**
33      * Get the latest books added to the system.
34      * @param $count
35      * @param $page
36      */
37     public function getRecentlyCreatedBooks($count = 20, $page = 0)
38     {
39         return $this->restrictionService->enforceBookRestrictions($this->book)
40             ->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get();
41     }
42
43     /**
44      * Get the most recently updated books.
45      * @param $count
46      * @param int $page
47      * @return mixed
48      */
49     public function getRecentlyUpdatedBooks($count = 20, $page = 0)
50     {
51         return $this->restrictionService->enforceBookRestrictions($this->book)
52             ->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get();
53     }
54
55     /**
56      * Get the latest pages added to the system.
57      * @param $count
58      * @param $page
59      */
60     public function getRecentlyCreatedPages($count = 20, $page = 0)
61     {
62         return $this->restrictionService->enforcePageRestrictions($this->page)
63             ->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get();
64     }
65
66     /**
67      * Get the most recently updated pages.
68      * @param $count
69      * @param int $page
70      * @return mixed
71      */
72     public function getRecentlyUpdatedPages($count = 20, $page = 0)
73     {
74         return $this->restrictionService->enforcePageRestrictions($this->page)
75             ->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get();
76     }
77
78
79 }