getPlaylists(); $count = count($playlists); $onlineCount = count(array_filter($playlists, static fn (array $playlist) => $playlist['isOnline'] === true)); $uncheckedCount = count(array_filter($playlists, static fn (array $playlist) => $playlist['isOnline'] === null)); $offlineCount = $count - $onlineCount - $uncheckedCount; $pageSize = config('app.page_size'); if ($pageSize > 0) { $pageCurrent = (int)($request->getAttributes()['page'] ?? $request->getQueryParams()['page'] ?? 1); $pageCount = ceil($count / $pageSize); $offset = max(0, ($pageCurrent - 1) * $pageSize); $playlists = array_slice($playlists, $offset, $pageSize, true); } return $this->view($request, $response, 'list.twig', [ 'updatedAt' => ini()->updatedAt(), 'playlists' => $playlists, 'count' => $count, 'onlineCount' => $onlineCount, 'uncheckedCount' => $uncheckedCount, 'offlineCount' => $offlineCount, 'pageCount' => $pageCount ?? 1, 'pageCurrent' => $pageCurrent ?? 1, ]); } /** * Возвращает страницу FAQ * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface * @throws LoaderError * @throws RuntimeError * @throws SyntaxError */ public function faq(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { return $this->view($request, $response, 'faq.twig'); } /** * Переадресует запрос на прямую ссылку плейлиста * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface * @throws LoaderError * @throws RuntimeError * @throws SyntaxError */ public function redirect(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { $code = $request->getAttributes()['code']; try { $playlist = ini()->getPlaylist($code); return $response->withHeader('Location', $playlist['url']); } catch (Throwable) { return $this->notFound($request, $response); } } /** * Возвращает страницу с описанием плейлиста * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface * @throws LoaderError * @throws RuntimeError * @throws SyntaxError */ public function details(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { $code = $request->getAttributes()['code']; try { $playlist = ini()->getPlaylist($code); return $this->view($request, $response, 'details.twig', ['playlist' => $playlist]); } catch (PlaylistNotFoundException) { return $this->notFound($request, $response); } } }