File: /var/www/vhosts/creativefellows.nl/oudlondon.creativefellows.nl/src/Action/News/NewsListAction.php
<?php
namespace App\Action\News;
use App\Action\Action;
use App\Domain\Page\Service\PageReader;
use App\Domain\Category\Service\CategoryReader;
use App\Domain\Navigation\Service\NavigationReader;
use App\Handler\DefaultErrorHandler;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Container\ContainerInterface;
use Slim\Views\PhpRenderer;
final class NewsListAction extends Action
{
protected $container;
protected $responder;
protected $pageReader;
protected $navigationReader;
protected $errorHandler;
public function __construct(
ContainerInterface $container,
PhpRenderer $responder,
PageReader $pageReader,
CategoryReader $categoryReader,
NavigationReader $navigationReader,
DefaultErrorHandler $errorHandler
) {
$this->container = $container;
$this->responder = $responder;
$this->pageReader = $pageReader;
$this->categoryReader = $categoryReader;
$this->navigationReader = $navigationReader;
$this->errorHandler = $errorHandler;
}
public function action() : ResponseInterface
{
// get data of page
$this->page = $this->pageReader->getPageData("actueel");
// list categories + pages
$this->categories = $this->categoryReader->getCategoryPages("actueel",10);
// get menu elements
$this->navigation = $this->navigationReader->getNavigationData('actueel');
// return error page if no result in page
if( !$this->page->hasData() ) return $this->errorHandler->respond($this->response,$this->page,$this->navigation);
// return
return $this->responder->render($this->response, 'list.news.php', [
"navigation" => $this->navigation,
"page" => $this->page,
"categories" => $this->categories,
]);
}
}