diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index 15afe22c..dc5d8a14 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -42,17 +42,13 @@ class DaysController extends GenericApiController $this->isRecursive(), $this->isArchive(), $this->isMonthView(), + $this->isReverse(), $this->getTransformations(), ); // Preload some day responses $this->preloadDays($list); - // Reverse response if requested. - if ($this->isReverse()) { - $list = array_reverse($list); - } - return new JSONResponse($list, Http::STATUS_OK); }); } @@ -74,14 +70,10 @@ class DaysController extends GenericApiController $this->isArchive(), $this->isHidden(), $this->isMonthView(), + $this->isReverse(), $this->getTransformations(), ); - // Reverse response if requested. - if ($this->isReverse()) { - $list = array_reverse($list); - } - return new JSONResponse($list, Http::STATUS_OK); }); } @@ -181,6 +173,7 @@ class DaysController extends GenericApiController $this->isArchive(), $this->isHidden(), $this->isMonthView(), + $this->isReverse(), $this->getTransformations(), ); diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index 2e0737df..82f7f5bb 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -21,6 +21,7 @@ trait TimelineQueryDays * @param bool $recursive Whether to get the days recursively * @param bool $archive Whether to get the days only from the archive folder * @param bool $monthView Whether the response should be in month view + * @param bool $reverse Whether the response should be in reverse order * @param array $queryTransforms An array of query transforms to apply to the query * * @return array The days response @@ -29,6 +30,7 @@ trait TimelineQueryDays bool $recursive, bool $archive, bool $monthView, + bool $reverse, array $queryTransforms = [], ): array { $query = $this->connection->getQueryBuilder(); @@ -54,7 +56,14 @@ trait TimelineQueryDays $rows = $this->executeQueryWithCTEs($query)->fetchAll(); // Post process the days - return $this->postProcessDays($rows, $monthView); + $rows = $this->postProcessDays($rows, $monthView); + + // Reverse order if needed + if ($reverse) { + $rows = array_reverse($rows); + } + + return $rows; } /** @@ -65,6 +74,7 @@ trait TimelineQueryDays * @param bool $archive If the query should include only the archive folder * @param bool $hidden If the query should include hidden files * @param bool $monthView If the query should be in month view (dayIds are monthIds) + * @param bool $reverse If the query should be in reverse order * @param array $queryTransforms The query transformations to apply * * @return array An array of day responses @@ -75,6 +85,7 @@ trait TimelineQueryDays bool $archive, bool $hidden, bool $monthView, + bool $reverse, array $queryTransforms = [], ): array { // Check if we have any dayIds @@ -135,6 +146,11 @@ trait TimelineQueryDays $this->postProcessDayPhoto($photo, $monthView); } + // Reverse order if needed + if ($reverse) { + $day = array_reverse($day); + } + return $day; }