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/SBogers85/dale-int.com/app/Komma/Projects/ProjectService.php
<?php

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

namespace Komma\Projects;

use Komma\Images\ImageService;
use Komma\Projects\Models\Project;

class ProjectService
{
    protected $imageService; 

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

    public function getAllProjects($pagination = true, $itemsPerPage = 10)
    {

        $projects = Project::where('lft', '!=', 1)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->where('active', '=', 1);
        if ($pagination) {
            $projects = $projects->paginate($itemsPerPage);
        } else {
            $projects = $projects->get();
        }

        foreach ($projects as &$content){
            if(!$content->images->count()) continue;
            $content->images = $this->imageService->orderImagesOnLanguage($content->images);
        }

        return $projects;

    }

    public function getProject($id)
    {
        if(!$project = Project::where('id', '=', $id)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->with('project_images')
            ->where('active', '=', 1)
            ->first()) return \App::abort(404, 'project not found');

        if($project->images->count() != 0) $project->images = $this->imageService->orderImagesOnLanguage($project->images);

        return $project;

    }

    /**
     * This method gets the projects where
     *
     * @param $field | string, field for the where
     * @param $values | array, value for the where
     * @return mixed
     */
    public function getProjectsWhere($field, $values)
    {
        //Only get the active blocks
        $blocks = Project::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 ($blocks as &$content){
            if(!$content->images->count()) continue;
            $content->images = $this->imageService->orderImagesOnLanguage($content->images);
        }

        return $blocks;
    }


}