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;
}
}