File: D:/HostingSpaces/BVerhoeven/verhoevendak.nl/app/Komma/Projects/ProjectController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Projects;
use Komma\Blocks\BlockService;
use Komma\Categories\CategoryService;
use Komma\Images\ImageService;
use Komma\LanguageService;
use Komma\Pages\PageService;
use Illuminate\Http\Request;
class ProjectController extends \BaseController
{
protected $pageService;
protected $blockService;
protected $projectService;
protected $categoryService;
public function __construct(PageService $pageService, BlockService $blockService, ProjectService $projectService, CategoryService $categoryService)
{
parent::__construct();
$this->pageService = $pageService;
$this->blockService = $blockService;
$this->projectService = $projectService;
$this->categoryService = $categoryService;
}
//Project index page
public function index(){
//get content of page and get all page links
$page = $this->pageService->getPageByCodeName('projects');
$links = $this->pageService->getAllRoutes();
$cat = null;
if(\Request::has('cat')) {
if(strpos(\Request::get('cat'), ',') !== false ) {
$cat = explode(",", \Request::get('cat'));
} else {
$cat = \Request::get('cat');
}
}
debug($cat);
if(count($cat) == 1) {
$projects = $this->projectService->getProjectsByCategory($cat);
} else {
//Get all projects
$projects = $this->projectService->getAllProjects(true);
}
$categories = $this->categoryService->getAllCategories();
return \View::make('layouts.pages.projects.index')
->with('page', $page)
->with('links', $links)
->with('categories', $categories)
->with('projects', $projects)
->with('currentCat', $cat);
}
public function show($projectId){
//Check if language matches the url before loading content
$page = $this->projectService->getProject($projectId);
$page->parent = $this->pageService->getPageByCodeName('projects');
//$page->nextSibling = $page->parent->getChildren()[$projectId].
$projects = $this->projectService->getAllProjects(false);
$nearbyProjects = $this->projectService->getProjectsNearLocation($projectId, $page->translation->location);
$links = $this->pageService->getAllRoutes();
$homeBlock = $this->pageService->getPageByCodeName('home')->content->translation->description;
return \View::make('layouts.pages.projects.show')
->with('page', $page)
->with('links', $links)
->with('projects', $projects)
->with('nearbyProjects', $nearbyProjects)
->with('homeBlock', $homeBlock);
}
public function getFilteredProjects(){
//debug(\Request::has('categories'));
$cats = \Request::has('categories') ? \Request::get('categories') : $this->categoryService->getAllCategories();
$projects = $this->projectService->getProjectsByCategory($cats);
return $projects;
}
}