File: D:/HostingSpaces/SBogers10/rentman.komma.pro/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 = false, $itemsPerPage = 10)
{
$projects = Project::where('lft', '!=', 1)
->with('translation')
->with('translation.route')
->where('active', '=', 1)
->orderBy('lft');
if ($pagination) {
$projects = $projects->paginate($itemsPerPage);
} else {
$projects = $projects->get();
foreach ($projects as $key =>$project){
if(!isset($project->translation)) $projects->forget($key);
}
}
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
$projects = 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 ($projects as &$content){
if(!$content->images->count()) continue;
$content->images = $this->imageService->orderImagesOnLanguage($content->images);
}
foreach ($projects as $key =>$project){
if(!isset($project->translation)) $projects->forget($key);
}
return $projects;
}
/**
* Get all translations of an page
* based upon this page id
*
* @param $page_id
* @return mixed
*/
public function getOtherLanguageRoutes($id){
return Project::where('id', '=', $id)
->with('allTranslations')
->with('allTranslations.route')
->first();
}
}