33namespace BookStack \App ;
44
55use BookStack \Activity \ActivityQueries ;
6- use BookStack \Entities \Models \Book ;
76use BookStack \Entities \Models \Page ;
8- use BookStack \Entities \Queries \RecentlyViewed ;
9- use BookStack \Entities \Queries \TopFavourites ;
10- use BookStack \Entities \Repos \BookRepo ;
11- use BookStack \Entities \Repos \BookshelfRepo ;
7+ use BookStack \Entities \Queries \EntityQueries ;
8+ use BookStack \Entities \Queries \QueryRecentlyViewed ;
9+ use BookStack \Entities \Queries \QueryTopFavourites ;
1210use BookStack \Entities \Tools \PageContent ;
1311use BookStack \Http \Controller ;
1412use BookStack \Uploads \FaviconHandler ;
1715
1816class HomeController extends Controller
1917{
18+ public function __construct (
19+ protected EntityQueries $ queries ,
20+ ) {
21+ }
22+
2023 /**
2124 * Display the homepage.
2225 */
23- public function index (Request $ request , ActivityQueries $ activities )
24- {
26+ public function index (
27+ Request $ request ,
28+ ActivityQueries $ activities ,
29+ QueryRecentlyViewed $ recentlyViewed ,
30+ QueryTopFavourites $ topFavourites ,
31+ ) {
2532 $ activity = $ activities ->latest (10 );
2633 $ draftPages = [];
2734
2835 if ($ this ->isSignedIn ()) {
29- $ draftPages = Page::visible ()
30- ->where ('draft ' , '= ' , true )
31- ->where ('created_by ' , '= ' , user ()->id )
36+ $ draftPages = $ this ->queries ->pages ->currentUserDraftsForList ()
3237 ->orderBy ('updated_at ' , 'desc ' )
3338 ->with ('book ' )
3439 ->take (6 )
@@ -37,14 +42,13 @@ public function index(Request $request, ActivityQueries $activities)
3742
3843 $ recentFactor = count ($ draftPages ) > 0 ? 0.5 : 1 ;
3944 $ recents = $ this ->isSignedIn () ?
40- ( new RecentlyViewed ()) ->run (12 * $ recentFactor , 1 )
41- : Book:: visible ()->orderBy ('created_at ' , 'desc ' )->take (12 * $ recentFactor )->get ();
42- $ favourites = ( new TopFavourites ()) ->run (6 );
43- $ recentlyUpdatedPages = Page:: visible ()-> with ( ' book ' )
45+ $ recentlyViewed ->run (12 * $ recentFactor , 1 )
46+ : $ this -> queries -> books -> visibleForList ()->orderBy ('created_at ' , 'desc ' )->take (12 * $ recentFactor )->get ();
47+ $ favourites = $ topFavourites ->run (6 );
48+ $ recentlyUpdatedPages = $ this -> queries -> pages -> visibleForList ( )
4449 ->where ('draft ' , false )
4550 ->orderBy ('updated_at ' , 'desc ' )
4651 ->take ($ favourites ->count () > 0 ? 5 : 10 )
47- ->select (Page::$ listAttributes )
4852 ->get ();
4953
5054 $ homepageOptions = ['default ' , 'books ' , 'bookshelves ' , 'page ' ];
@@ -78,14 +82,18 @@ public function index(Request $request, ActivityQueries $activities)
7882 }
7983
8084 if ($ homepageOption === 'bookshelves ' ) {
81- $ shelves = app ()->make (BookshelfRepo::class)->getAllPaginated (18 , $ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ());
85+ $ shelves = $ this ->queries ->shelves ->visibleForListWithCover ()
86+ ->orderBy ($ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ())
87+ ->paginate (18 );
8288 $ data = array_merge ($ commonData , ['shelves ' => $ shelves ]);
8389
8490 return view ('home.shelves ' , $ data );
8591 }
8692
8793 if ($ homepageOption === 'books ' ) {
88- $ books = app ()->make (BookRepo::class)->getAllPaginated (18 , $ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ());
94+ $ books = $ this ->queries ->books ->visibleForListWithCover ()
95+ ->orderBy ($ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ())
96+ ->paginate (18 );
8997 $ data = array_merge ($ commonData , ['books ' => $ books ]);
9098
9199 return view ('home.books ' , $ data );
@@ -95,7 +103,7 @@ public function index(Request $request, ActivityQueries $activities)
95103 $ homepageSetting = setting ('app-homepage ' , '0: ' );
96104 $ id = intval (explode (': ' , $ homepageSetting )[0 ]);
97105 /** @var Page $customHomepage */
98- $ customHomepage = Page:: query ()->where ('draft ' , '= ' , false )->findOrFail ($ id );
106+ $ customHomepage = $ this -> queries -> pages -> start ()->where ('draft ' , '= ' , false )->findOrFail ($ id );
99107 $ pageContent = new PageContent ($ customHomepage );
100108 $ customHomepage ->html = $ pageContent ->render (false );
101109
0 commit comments