File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Jobs/JobService.php
<?php
namespace App\Komma\Jobs;
use App\Komma\Base\Service;
use App\Komma\Jobs\Models\Job;
class JobService extends Service
{
public function getJobs()
{
$jobs = $this->site
->jobs()
->with('translation', 'images')
->orderBy('lft')
// We need to use a join to select the active jobs because that is defined on the translations
->join('job_translations', 'jobs.id', '=', 'job_translations.job_id')
->select('jobs.*', 'job_translations.active', 'job_translations.language_id')
->where('active', 1)
->where('language_id', \App::getLanguage()->id)
->get();
return $jobs;
}
public function getNextJobs(Job $job, $amountOfJobs = 3)
{
$jobQuery = $this->site
->jobs()
->with('translation', 'images')
->where('jobs.id', '!=', $job->id)
->orderBy('lft')
// We need to use a join to select the active jobs because that is defined on the translations
->join('job_translations', 'jobs.id', '=', 'job_translations.job_id')
->select('jobs.*', 'job_translations.active', 'job_translations.language_id')
->where('active', 1)
->where('language_id', \App::getLanguage()->id);
$olderJobs = clone $jobQuery;
$foundJobs = $olderJobs->where('lft', '>', $job->lft)
->take($amountOfJobs)
->get();
$foundStoriesAmount = $foundJobs->count();
// If we have enough vacancies return them
if ($foundStoriesAmount == $amountOfJobs) {
return $foundJobs;
}
$newerJobs = $jobQuery->where('lft', '<', $job->lft)
->take(($amountOfJobs - $foundStoriesAmount))
->get();
return $foundJobs->merge($newerJobs);
}
}