File: /var/www/vhosts/creativefellows.nl/firstbrick.creativefellows.nl/src/Action/Jobs/ViewJobAction.php
<?php
namespace App\Action\Jobs;
use App\Action\TwigAction;
use App\Domain\Page\Service\PageReader;
use App\Domain\Page\Data\PageData;
use App\Domain\Navigation\Service\NavigationReader;
use App\Domain\Language\LanguageData;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use App\Handler\DefaultErrorHandler;
use App\Domain\Jobs\Service\JobReader;
final class ViewJobAction extends TwigAction
{
private $twig;
private $pageReader;
private $navigationReader;
private $errorHandler;
private $language;
private $JobReader;
public function __construct(
Twig $twig,
PageReader $pageReader,
NavigationReader $navigationReader,
LanguageData $language,
DefaultErrorHandler $errorHandler,
JobReader $jobReader
){
$this->twig = $twig;
$this->pageReader = $pageReader;
$this->navigationReader = $navigationReader;
$this->language = $language;
$this->errorHandler = $errorHandler;
$this->jobReader = $jobReader;
}
public function action() : Response
{
$job_slug = ($this->args['job_slug'] ?? null);
$post_section = "vacatures";
// get data of page
$this->page = $this->pageReader->getPageData($post_section);
// get all jobs
$jobs = $this->jobReader->getJobBySlug($job_slug);
// return error page if no result in page
if( !$this->page->hasData() ) return $this->errorHandler->respond($this->response,$this->page,$this->navigationReader->getNavigationData($post_section));
$data = [
"navigation" => $this->navigationReader->getNavigationData($post_section),
"localization" => $this->language->localizedLanguageData()->setting("labels"),
"page" => $this->page->twigData(),
"jobs" => $jobs,
];
return $this->twig->render($this->response, "vacature-details.twig", $data);
}
}