55use Illuminate \Database \Eloquent \Model ;
66use Illuminate \Support \Arr ;
77use Illuminate \Support \Facades \DB ;
8- use SolutionForest \InspireCms \Collection \ContentCollection ;
98use SolutionForest \InspireCms \Content \SegmentProviderInterface ;
109use SolutionForest \InspireCms \Factories \ContentSegmentFactory ;
10+ use SolutionForest \InspireCms \Helpers \ContentHelper ;
1111use SolutionForest \InspireCms \InspireCmsConfig ;
1212use SolutionForest \InspireCms \Models \Contracts \Content ;
1313use SolutionForest \InspireCms \Models \Scopes \ContentVersionDetailScope ;
@@ -95,23 +95,23 @@ public function getPaginatedByIds($ids, $page = 1, $perPage = 10, $pageName = 'p
9595 {
9696 return $ this ->buildFindByIdsQuery ($ ids , $ isWebPage , $ isPublished , $ withRelations , $ sorting , null )
9797 ->paginate ($ perPage , ['* ' ], $ pageName , $ page )
98- ->tap (fn ($ paginator ) => $ this -> initializePaginatorCollection ($ paginator ));
98+ ->tap (fn ($ paginator ) => ContentHelper:: initializePaginatorCollection ($ paginator ));
9999 }
100100
101101 /** {@inheritDoc} */
102102 public function getPaginatedByRealPath ($ path , $ page = 1 , $ perPage = 10 , $ pageName = 'page ' , $ isWebPage = null , $ isPublished = null , $ withRelations = [], $ sorting = [])
103103 {
104104 return $ this ->buildFindByRealPathQuery ($ path , $ isWebPage , $ isPublished , $ withRelations , $ sorting , null )
105105 ->paginate ($ perPage , ['* ' ], $ pageName , $ page )
106- ->tap (fn ($ paginator ) => $ this -> initializePaginatorCollection ($ paginator ));
106+ ->tap (fn ($ paginator ) => ContentHelper:: initializePaginatorCollection ($ paginator ));
107107 }
108108
109109 /** {@inheritDoc} */
110110 public function getPaginatedUnderRealPath ($ path , $ page = 1 , $ perPage = 10 , $ pageName = 'page ' , $ isWebPage = null , $ isPublished = null , $ withRelations = [], $ sorting = [])
111111 {
112112 return $ this ->buildGetUnderRealPathQuery ($ path , $ isWebPage , $ isPublished , $ withRelations , $ sorting , null )
113113 ->paginate ($ perPage , ['* ' ], $ pageName , $ page )
114- ->tap (fn ($ paginator ) => $ this -> initializePaginatorCollection ($ paginator ));
114+ ->tap (fn ($ paginator ) => ContentHelper:: initializePaginatorCollection ($ paginator ));
115115 }
116116
117117 /** {@inheritDoc} */
@@ -128,7 +128,7 @@ public function getPaginatedByDocumentType($documentType, $page = 1, $perPage =
128128 $ query = $ this ->applySortingAndLimit ($ query , $ sorting , null );
129129
130130 return $ query ->paginate ($ perPage , ['* ' ], $ pageName , $ page )
131- ->tap (fn ($ paginator ) => $ this -> initializePaginatorCollection ($ paginator ));
131+ ->tap (fn ($ paginator ) => ContentHelper:: initializePaginatorCollection ($ paginator ));
132132 }
133133
134134 /** {@inheritDoc} */
@@ -339,22 +339,4 @@ private function buildGetUnderRealPathQuery($path, $isWebPage = null, $isPublish
339339
340340 return $ query ;
341341 }
342-
343- private function initializePaginatorCollection ($ paginator )
344- {
345- if ($ paginator instanceof \Illuminate \Contracts \Pagination \Paginator) {
346-
347- $ items = $ paginator ->getCollection ();
348-
349- // for "toDto" method
350- if ($ items instanceof ContentCollection) {
351- $ items = $ items ->setPaginator ($ paginator );
352- }
353-
354- $ paginator ->setCollection ($ items );
355-
356- }
357-
358- return $ paginator ;
359- }
360342}
0 commit comments