File: D:/HostingSpaces/SBogers10/anvil.komma.pro/app/KommaApp/Vacancies/VacancyService.php
<?php
namespace App\KommaApp\Vacancies;
use App\KommaApp\Pages\Models\Page;
use App\KommaApp\Vacancies\Models\Vacancy;
use Carbon\Carbon;
class VacancyService
{
private $today;
public function __construct()
{
$this->today = Carbon::now()->addHour();
$this->today = $this->today->format('Y-m-d H:i:s');
}
public function getAllVacancies($pagination = false, $itemsPerPage = 9)
{
$site = \App::getSite();
if($site->slug != 'anvil'){
$vacancies = $site
->vacancies()
->where('active', 1)
->where('date', '<=', $this->today)
->orderBy('date','desc')
->orderBy('created_at', 'desc')
->with('translation', 'images', 'sites')
->has('translation');
}
else{
$vacancies = Vacancy::where('active', 1)
->where('date', '<=', $this->today)
->orderBy('date','desc')
->orderBy('created_at', 'desc')
->with('translation', 'images', 'sites')
->has('translation');
}
if($pagination)
{
$vacancies = $vacancies->paginate($itemsPerPage);
}
else
{
$vacancies = $vacancies->get();
}
return $vacancies;
}
public function expandBreadCrumbTree(Page &$page, Vacancy $vacancy, $links){
if(!isset($links->specialisms)) return;
$tree = $page->breadcrumbTree;
$tree[] = (object)[
'name' => $vacancy->translation->name,
'url' => '/' . $links->vacancies->route . '/'.$vacancy->translation->slug,
'node' => $vacancy,
];
$page->breadcrumbTree = $tree;
}
}