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/SBogers87/basephotography.nl/app/Komma/Projects/ProjectService.php
<?php


namespace Komma\Projects;


use Illuminate\Support\Str;
use Komma\Kms\Categories\Models\CategoryTranslation;
use Komma\Kms\Images\Models\Image;

class ProjectService
{
    protected $projectRepository;

    public function __construct(ProjectRepository $projectRepository)
    {
        $this->projectRepository = $projectRepository;
    }

    public function getProjects($id = null){
        if(isset($id)){
            $projects = $this->projectRepository->getProjects($id);

            $projects = $this->projectRepository->getProjectInformation($projects);
            return $projects;

        }

        $projects = $this->projectRepository->getProjects();
        $projects = $this->projectRepository->getProjectInformation($projects);
        return $projects;
    }

    public function getCategories($selected = null){
        return $this->projectRepository->getCategories($selected);
    }

    public function splitImages($images){
        $amountImages = sizeof($images);
        $lftArray = [];
        $rgtArray = [];

        if($amountImages != 0){
            $firstHalf = (int)round(($amountImages/2), 0, PHP_ROUND_HALF_UP);
            for($i = 0; $i< $amountImages; $i++){
                if($i < $firstHalf) {
                    $lftArray[]= $images[$i];
                }
                else{
                    $rgtArray[]= $images[$i];
                }
            }
        }
        return (object)['lft' => $lftArray, 'rgt'=>$rgtArray];
    }

    /**
     * Get all images of a category
     *
     * @param $category
     * @return array
     */
    public function getCategoryImages($category){
        //get category id
        $select = $this->projectRepository->getCategoryId($category);

        //get all image ids of that category
        $imageIds = $this->projectRepository->getCategoryImageIds($select);

        //get image information based upon image ids
        $images = $this->projectRepository->getCategoryImages($imageIds);
        $images = $images->shuffle();
        //dd($images);

        return $images;
    }

}