settings['flexform'] ?? []) as $key => $value) { if (!empty($value)) { $this->settings[$key] = $value; } } if (isset($this->settings['flexform'])) { unset($this->settings['flexform']); } $this->view->assign('settings', $this->settings); $this->view->assign('data', $this->request->getAttribute('currentContentObject')?->data ?? null); } /** * Show a list of recent posts. */ public function listRecentPostsAction(int $currentPage = 1): ResponseInterface { $maximumItems = (int) ($this->settings['lists']['posts']['maximumDisplayedItems'] ?? 0); $posts = (0 === $maximumItems) ? $this->postRepository->findAll() : $this->postRepository->findAllWithLimit($maximumItems); $pagination = $this->getPagination($posts, $currentPage); $this->view->assign('posts', $posts); $this->view->assign('pagination', $pagination); return $this->htmlResponse(); } /** * Show a number of latest posts. */ public function listLatestPostsAction(): ResponseInterface { $limit = (int) ($this->settings['limit'] ?? 3); $posts = $this->postRepository->findAllWithLimit($limit); $this->view->assign('posts', $posts); return $this->htmlResponse(); } /** * Show posts beyond a certain date */ public function listPostsByDateAction( ?int $year = null, ?int $month = null, int $currentPage = 1 ): ResponseInterface { if ($year === null) { $posts = $this->postRepository->findMonthsAndYearsWithPosts(); $this->view->assign('archiveData', ArchiveUtility::extractDataFromPosts($posts)); } else { $dateTime = new DateTimeImmutable(sprintf('%d-%d-1', $year, $month ?? 1)); $posts = $this->postRepository->findByMonthAndYear($year, $month); $pagination = $this->getPagination($posts, $currentPage); $this->view->assign('type', 'bydate'); $this->view->assign('month', $month); $this->view->assign('year', $year); $this->view->assign('timestamp', $dateTime->getTimestamp()); $this->view->assign('posts', $posts); $this->view->assign('pagination', $pagination); $title = str_replace( [ '###MONTH###', '###MONTH_NAME###', '###YEAR###', ], [ $month, $dateTime->format('F'), $year, ], (string) LocalizationUtility::translate('meta.title.listPostsByDate', 'ew_bloggy') ); MetaTagService::set(MetaTagService::META_TITLE, (string) $title); MetaTagService::set( MetaTagService::META_DESCRIPTION, (string) LocalizationUtility::translate('meta.description.listPostsByDate', 'ew_bloggy') ); } return $this->htmlResponse(); } protected function getPagination(QueryResultInterface $objects, int $currentPage = 1): ?BlogPagination { $maximumNumberOfLinks = (int) ($this->settings['lists']['pagination']['maximumNumberOfLinks'] ?? 0); $itemsPerPage = 10; if ($this->request->getFormat() === 'html') { $itemsPerPage = (int) ($this->settings['lists']['pagination']['itemsPerPage'] ?? 10); } $paginator = new QueryResultPaginator($objects, $currentPage, $itemsPerPage); return new BlogPagination($paginator, $maximumNumberOfLinks); } }