File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Jobs/JobController.php
<?php
namespace App\Komma\Jobs;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Jobs\Models\Job;
use App\Komma\Servicepoints\Models\Servicepoint;
final class JobController extends Controller
{
private $jobService;
private $jobPaginationKey = 'jobPagination';
public function __construct(JobService $jobService)
{
parent::__construct();
$this->jobService = $jobService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
// If you don't know the code_name get page through given page id through request
// $page = $this->pageService->getPage(request()->get('page_id'));
$page = $this->links->jobs->node;
$jobs = $this->jobService->getJobsPaginated();
$jobs->withPath($this->links->jobs->route);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->jobs, $this->links->home);
// Return view
return view('site.templates.jobs_index',[
'page' => $page,
'links' => $this->links,
'languageMenu' => $languageMenu,
'jobs' => $jobs,
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
dd('customize filter function in JobController');
// if (sizeof($filters) != 1) {
// throw abort(404);
// }
// $categoryName = $filters[0];
//
// // Check if category exist else trow 404
// if ( ! $category = JobCategoryTranslation::where('slug', $categoryName)
// ->with('translatable')
// ->first()) {
// throw abort(404);
// }
//
// $page = $this->pageService->getPageByCodeName('blog');
// $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
// //Get jobs through the category
// $jobs = $category->translatable->jobs()->paginate(8);
// $jobs->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
// // Return view
// return view($this->baseViewPath.$this->pagePrefix.'index',[
// 'page' => $page,
// 'links' => $this->links,
// 'otherLanguages' => $otherLanguageRoutes,
// 'jobs' => $jobs,
// ]);
}
/**
* @param Job $job
* @return \Illuminate\Contracts\View\View
*/
public function show(Job $job)
{
$job->load('translation','translations', 'sites');
// This checks if the job belongs to the set site
if(! $job->sites->contains($this->site)) throw abort(404);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($job->translation);
$jobs = $this->jobService->getJobsPaginated();
$jobs->withPath($this->links->jobs->route);
$nextJobs = $this->jobService->getNextJobs($job);
// If we don't have any next post, we manually add the latest one
if($nextJobs->count() == 0) {
$latestJob = $this->jobService->getLastJob();
view()->share('latestJob', $latestJob);
}
// By default get the first servicepoint
$servicepoint = Servicepoint::first();
// Get the chosen servicepoint for the page
if(!empty($job->servicepoint_id)) $servicepoint = Servicepoint::find($job->servicepoint_id);
$page = $this->links->jobs->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->jobs, $this->links->home);
$previousRoute = $this->createPreviousRoute($this->jobPaginationKey, $this->links->jobs->route);
// Return view
return view('site.templates.jobs_show',[
'components' => $components,
'page' => $page,
'jobs' => $jobs,
'job' => $job,
'nextJobs' => $nextJobs,
'links' => $this->links,
'languageMenu' => $languageMenu,
'previousRoute' => $previousRoute,
'servicepoint' => $servicepoint
]);
}
}