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/BVerhoeven/verhoevendak.nl/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 Komma\Images\ImageService;
use Komma\Pages\PageService;
use Komma\Jobs\Models\Job;
use Komma\Jobs\Models\JobTranslation;
use Illuminate\Support\Collection;


class JobService
{
    protected $imageService;
    protected $pageService;

    public function __construct(ImageService $imageService, PageService $pageService)
    {
        $this->imageService = $imageService;
        $this->pageService = $pageService;
    }

    /**
     * Get Job by id
     *
     * @param $id
     * @return mixed
     */
    public function getJob($id)
    {
        if (!$job = Job::where('id', '=', $id)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->with('job_images')
            ->where('active', '=', 1)
            ->first()) return \App::abort(404, 'job not found');


        $this->fillJob($job);

        return $job;
    }

    /**
     * Fill additional content to job
     *
     * @param Job $job
     */
    protected function fillJob(Job &$job)
    {
        //debug($job);
        //Comment the decode when there aren't dynamic blocks
//        $job->translation->description = json_decode($job->translation->description);

        $job->meta_description = strip_tags($job->meta_description);

        $metaParent = $this->pageService->getMetaData('jobs');
        debug($metaParent);
        $job->translation->meta_title = $job->translation->name . ' | ' . $metaParent->meta_title;
    }


    /**
     * Get all jobs
     *
     * @param bool $pagination
     * @param int $itemsPerPage
     * @return mixed
     */
    public function getAllJobs($pagination = false, $itemsPerPage = 9)
    {

        $jobs = Job::where('lft', '!=', 1)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->with('job_images')
            ->where('active', '=', 1)
            ->orderBy('lft');

        if ($pagination) {
            $jobs = $jobs->paginate($itemsPerPage);
        } else {
            $jobs = $jobs->get();
            foreach ($jobs as $key => $job) {
                if (!isset($job->translation)) $jobs->forget($key);
            }
        }

        return $jobs;

    }


    /**
     * This method gets the jobs where
     *
     * @param $field | string, field for the where
     * @param $values | array, value for the where
     * @return mixed
     */
    public function getJobsWhere($field, $values)
    {
        //Only get the active blocks
        $jobs = Job::where('active', '=', 1)
            //Where field is value
            ->where('lft', '!=', 1)
            ->where($field, '=', $values)
            //Also load the translation
            ->with('translation')
            ->with('images')
            ->orderBy('lft')
            ->get();

        foreach ($jobs as $key => $job) {
            if (!isset($job->translation)) $jobs->forget($key);
        }

        return $jobs;
    }

}