HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rentman.komma.pro/app/Komma/Jobs/JobService.php
<?php

/**
 * Short description for the file.
 *
 * @author      Komma <support@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Jobs;

use Carbon\Carbon;
use Komma\Kms\Languages\Language;
use Komma\Jobs\Models\Job;

class JobService
{


    public function getAllJobs($pagination = false, $itemsPerPage = 5)
    {

        $posts = \DB::table('jobs')
            ->leftJoin('job_translations', function ($join)
            {
                $join->on('job_translations.job_id', '=', 'jobs.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'job_translations.language_id')
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'jobs.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Jobs\Models\Job')
                    ->where('sort_order', '=', 1);
            })
            ->leftJoin('routes', function ($join)
            {
                $join->on('job_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Jobs\Models\JobTranslation');
            })
            ->select('jobs.*', 'job_translations.*', 'routes.route', 'images.*')
            ->where('jobs.active', '=', 1)
            ->where('job_translations.description', '!=', '[]')
            ->orderBy('jobs.lft', 'asc')
            ->get();

        return $posts;

    }


    public function getJob($id, $nextAndPrev = true)
    {

        if( ! $post = Job::where('id', '=', $id)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->where('active', '=', 1)
            ->first()
        ) return \App::abort(404, 'post not found');

        if($nextAndPrev) $nextAndPrev = $this->getNextAndPrevious($post);

        return $post;

    }


    public function getNextAndPrevious(&$post)
    {
        $previous = \DB::table('jobs')
            ->leftJoin('job_translations', function ($join)
            {
                $join->on('job_translations.job_id', '=', 'jobs.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'job_translations.language_id')
            ->leftJoin('routes', function ($join)
            {
                $join->on('job_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Jobs\Models\JobTranslation');
            })
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'jobs.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Jobs\Models\Job')
                    ->where('sort_order', '=', 1);
            })
            ->select('jobs.*', 'job_translations.*', 'routes.route')
            ->where('jobs.active', '=', 1)
            ->where('jobs.lft', '>', $post->lft)
            ->where('jobs.id', '!=', $post->id)
            ->orderBy('jobs.lft', 'asc')
            ->where('job_translations.description', '!=', '[]')
            ->first();
        $next = \DB::table('jobs')
            ->leftJoin('job_translations', function ($join)
            {
                $join->on('job_translations.job_id', '=', 'jobs.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'job_translations.language_id')
            ->leftJoin('routes', function ($join)
            {
                $join->on('job_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Jobs\Models\JobTranslation');
            })
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'jobs.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Jobs\Models\Job')
                    ->where('sort_order', '=', 1);
            })
            ->select('jobs.*', 'job_translations.*', 'routes.route')
            ->where('jobs.active', '=', 1)
            ->where('jobs.lft', '<', $post->lft)
            ->where('jobs.id', '!=', $post->id)
            ->orderBy('jobs.lft', 'desc')
            ->first();

//        $previous = Post::where('date', '>', $post->date)->orderBy('date', 'asc')
//            ->with('translation')
//            ->with('translation.route')
//            ->with('images')
//            ->where('active', '=', 1)
//            ->where('date', '<=', $this->today)
//            ->where('id', '!=', $post->id)
//            ->first();
//        $next = Post::where('date', '<', $post->date)->orderBy('date', 'desc')
//            ->with('translation')
//            ->with('translation.route')
//            ->with('images')
//            ->where('active', '=', 1)
//            ->where('date', '<=', $this->today)
//            ->where('id', '!=', $post->id)
//            ->first();

        $post->next = $previous;
        $post->previous = $next ;
    }

    public function makeCarbonDate(&$posts)
    {
        foreach ($posts as $post)
        {
            $date = $post->date;
            $post->date = Carbon::createFromFormat('Y-m-d H:i:s', $date);
        }
    }

    /**
     * Get all translations of an page
     * based upon this page id
     *
     * @param $page_id
     * @return mixed
     */
    public function getOtherLanguageRoutes($id)
    {
        $job = Job::where('id', '=', $id)
            ->with('allTranslations')
            ->with('allTranslations.route')
            ->first();

        $translatedRoutes = [];
        foreach ($job->allTranslations as $jobTranslation){
            if($jobTranslation->description == '[]') continue;
            $translatedRoutes[] = $jobTranslation;
        }
        return $translatedRoutes;
    }

}