1 <?php namespace Oxbow\Repos;
4 use Illuminate\Support\Str;
12 * PageRepo constructor.
15 public function __construct(Page $page)
20 public function getById($id)
22 return $this->page->findOrFail($id);
25 public function getAll()
27 return $this->page->all();
30 public function getBySlug($slug, $bookId)
32 return $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first();
35 public function newFromInput($input)
37 $page = $this->page->fill($input);
41 public function countBySlug($slug, $bookId)
43 return $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->count();
46 public function destroyById($id)
48 $page = $this->getById($id);
52 public function getBySearch($term)
54 $terms = explode(' ', trim($term));
56 foreach($terms as $term) {
57 $query = $query->where('text', 'like', '%'.$term.'%');
62 public function getBreadCrumbs($page)
66 while($cPage->parent && $cPage->parent->id !== 0) {
67 $cPage = $cPage->parent;
70 return count($tree) > 0 ? array_reverse($tree) : false;
74 * Gets the pages at the top of the page hierarchy.
77 private function getTopLevelPages($bookId)
79 return $this->page->where('book_id', '=', $bookId)->where('chapter_id', '=', 0)->orderBy('priority')->get();
83 * Applies a sort map to all applicable pages.
87 public function applySortMap($sortMap, $bookId)
89 foreach($sortMap as $index => $map) {
90 $page = $this->getById($map->id);
91 if($page->book_id === $bookId) {
92 $page->page_id = $map->parent;
93 $page->priority = $index;