22
33namespace BookStack \App ;
44
5- use BookStack \Activity \ActivityQueries ;
65use BookStack \Entities \Models \Page ;
76use BookStack \Entities \Queries \EntityQueries ;
8- use BookStack \Entities \Queries \QueryRecentlyViewed ;
9- use BookStack \Entities \Queries \QueryTopFavourites ;
107use BookStack \Entities \Tools \PageContent ;
118use BookStack \Http \Controller ;
129use BookStack \Util \SimpleListOptions ;
@@ -24,49 +21,19 @@ public function __construct(
2421 */
2522 public function index (
2623 Request $ request ,
27- ActivityQueries $ activities ,
28- QueryRecentlyViewed $ recentlyViewed ,
29- QueryTopFavourites $ topFavourites ,
3024 ) {
31- $ activity = $ activities ->latest (10 );
32- $ draftPages = [];
33-
34- if ($ this ->isSignedIn ()) {
35- $ draftPages = $ this ->queries ->pages ->currentUserDraftsForList ()
36- ->orderBy ('updated_at ' , 'desc ' )
37- ->with ('book ' )
38- ->take (6 )
39- ->get ();
40- }
41-
42- $ recentFactor = count ($ draftPages ) > 0 ? 0.5 : 1 ;
43- $ recents = $ this ->isSignedIn () ?
44- $ recentlyViewed ->run (12 * $ recentFactor , 1 )
45- : $ this ->queries ->books ->visibleForList ()->orderBy ('created_at ' , 'desc ' )->take (12 * $ recentFactor )->get ();
46- $ favourites = $ topFavourites ->run (6 );
47- $ recentlyUpdatedPages = $ this ->queries ->pages ->visibleForList ()
48- ->where ('draft ' , false )
49- ->orderBy ('updated_at ' , 'desc ' )
50- ->take ($ favourites ->count () > 0 ? 5 : 10 )
51- ->get ();
52-
53- $ homepageOptions = ['default ' , 'books ' , 'bookshelves ' , 'page ' ];
54- $ homepageOption = setting ('app-homepage-type ' , 'default ' );
55- if (!in_array ($ homepageOption , $ homepageOptions )) {
56- $ homepageOption = 'default ' ;
25+ $ homepageType = setting ('app-homepage-type ' );
26+ if (!in_array ($ homepageType , ['default ' , 'books ' , 'bookshelves ' , 'page ' ])) {
27+ $ homepageType = 'default ' ;
5728 }
5829
5930 $ commonData = [
60- 'activity ' => $ activity ,
61- 'recents ' => $ recents ,
62- 'recentlyUpdatedPages ' => $ recentlyUpdatedPages ,
63- 'draftPages ' => $ draftPages ,
64- 'favourites ' => $ favourites ,
31+ 'homeView ' => $ homepageType ,
6532 ];
6633
6734 // Add required list ordering & sorting for books & shelves views.
68- if ($ homepageOption === 'bookshelves ' || $ homepageOption === 'books ' ) {
69- $ key = $ homepageOption ;
35+ if ($ homepageType === 'bookshelves ' || $ homepageType === 'books ' ) {
36+ $ key = $ homepageType ;
7037 $ view = setting ()->getForCurrentUser ($ key . '_view_type ' );
7138 $ listOptions = SimpleListOptions::fromRequest ($ request , $ key )->withSortOptions ([
7239 'name ' => trans ('common.sort_name ' ),
@@ -80,7 +47,7 @@ public function index(
8047 ]);
8148 }
8249
83- if ($ homepageOption === 'bookshelves ' ) {
50+ if ($ homepageType === 'bookshelves ' ) {
8451 $ shelves = $ this ->queries ->shelves ->visibleForListWithCover ()
8552 ->orderBy ($ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ())
8653 ->paginate (setting ()->getInteger ('lists-page-count-shelves ' , 18 , 1 , 1000 ));
@@ -89,7 +56,7 @@ public function index(
8956 return view ('home.shelves ' , $ data );
9057 }
9158
92- if ($ homepageOption === 'books ' ) {
59+ if ($ homepageType === 'books ' ) {
9360 $ books = $ this ->queries ->books ->visibleForListWithCover ()
9461 ->orderBy ($ commonData ['listOptions ' ]->getSort (), $ commonData ['listOptions ' ]->getOrder ())
9562 ->paginate (setting ()->getInteger ('lists-page-count-books ' , 18 , 1 , 1000 ));
@@ -98,7 +65,7 @@ public function index(
9865 return view ('home.books ' , $ data );
9966 }
10067
101- if ($ homepageOption === 'page ' ) {
68+ if ($ homepageType === 'page ' ) {
10269 $ homepageSetting = setting ('app-homepage ' , '0: ' );
10370 $ id = intval (explode (': ' , $ homepageSetting )[0 ]);
10471 /** @var Page $customHomepage */
0 commit comments