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/Jobs/ListJobsAction.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 App\Domain\Cookie\CookieData;
use App\Domain\Jobs\Service\JobReader;
use App\Domain\Pagination\PaginationReader;
use App\Handler\DefaultErrorHandler;


use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;




final class ListJobsAction extends TwigAction
{	
	
	protected $twig;
	protected $pageReader;
	protected $navigationReader;
	protected $errorHandler;
	protected $language;
	protected $jobReader;
	protected $pagination;
	protected $cookies;
	
    public function __construct(
		Twig $twig,
		PageReader $pageReader, 
		NavigationReader $navigationReader,
		LanguageData $language,
		DefaultErrorHandler $errorHandler,
		PaginationReader $pagination,
		JobReader $jobReader,
		CookieData $cookies
	){
        $this->twig 			= $twig;
		$this->pageReader 		= $pageReader;
		$this->navigationReader = $navigationReader;
		$this->language 		= $language;
		$this->cookies 			= $cookies;
		$this->errorHandler 	= $errorHandler;
		$this->jobReader 		= $jobReader;
		$this->pagination 		= $pagination;
    }
	
    public function action() : Response
	{	
		

	    $page 			= ($this->args['page'] ?? 1);	    
		$post_section 	= ($this->args['section'] ?? 1);	   
		$search 		= $this->request->getQueryParams()['q'] ?? '';
		
		$salary_min 	= $this->request->getQueryParams()['salary_min'] ?? '';
		$salary_max		= $this->request->getQueryParams()['salary_max'] ?? '';
		
		$parameters = [
			"salary_min" => $salary_min,
			"salary_max" => $salary_max,
		];
		
		// get data of page
        $this->page = $this->pageReader->getPageData($post_section,null,$page);	
		
		// get all jobs
		$jobs = $this->jobReader->listJobs($page,$search,$post_section,$parameters); 
				
		// set url for pagination
		$this->pagination->setRoute("jobs.list",["page" => $page, "section" => $post_section]);
		$this->pagination->setCurrentPage( $page );		
		$this->pagination->setItemCount( $jobs["count"] );

		//d($this->pagination->html()->itemCount());
					
		// 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(),
			"pagination" => $this->pagination->html(),
			"jobs" => $jobs["jobs"],
			"categories" => $this->jobReader->listJobCategories(),
			"intellectual" => $this->jobReader->listIntellectLevels(),
			"cookies" => $this->cookies,
			"search_string" => $search,
			"message" => empty($this->data["jobs"]) ? "Geen vacatures gevonden" : $this->pagination->html()->itemCount() ." ". $this->language->localizedLanguageData()->setting("labels")["jobs"]["jobs_label"], 
		];
		
		$data["search_cta"] = '<p class="text-center hide">Je zoekopdacht <strong>\''.htmlspecialchars($search) .'\'</strong> heeft geen vacatures opgeleverd.</p>
					    <p><strong>Suggestie:</strong> Pas je zoekopdracht aan | Gebruik minder filters | Probeer andere zoektermen | Gebruik minder zoekwoorden</p>
						<p><a href="'. $post_section .'" class="button primary">Alle vacatures</a></p>';
		
		
		return $this->twig->render($this->response, "vacatures.twig", $data);
		
    }
		
}