HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/oudlondon.creativefellows.nl/src/Action/News/NewsViewAction.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 NewsViewAction extends Action
{	
	
    protected $container;	
	protected $responder;
	protected $pageReader;
	protected $navigationReader;
	protected $language;
	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
	{
		
		// check of a post url is set
	    $post_name = ($this->args['page'] ?? null);
	    $post_category = ($this->args['category'] ?? null);
		
		
		// get data of page
        $this->page = $this->pageReader->getPageData($post_name);
		
		// list categories + pages
		$this->categories = $this->categoryReader->getPagesInCategory("newsroom",$post_category,$post_name,15);
		
		
		// get menu elements
		$this->navigation = $this->navigationReader->getNavigationData("newsroom");	
				
			
		// 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, $this->page->getTemplateName(), [
			"navigation" => $this->navigation,
			"page" => $this->page,
			"category" => $this->categories,
		]);
		
    }
		
}