File: D:/HostingSpaces/PDeckers/opelkapitan.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\Kms\Categories\Models\Category;
use Komma\Pages\PageService;
use Komma\Routes\Models\Route;
class ProjectController extends \BaseController
{
public $data;
protected $pageService;
protected $blockService;
protected $projectService;
public function __construct(PageService $pageService, BlockService $blockService, ProjectService $projectService)
{
parent::__construct();
$this->pageService = $pageService;
$this->blockService = $blockService;
$this->projectService = $projectService;
$this->data = (object)[];
}
//Project index page
public function index(){
$page = $this->pageService->getPageByCodeName('project_overview');
$this->data->content = $page;
$this->data->id = $this->data->content->id;
$this->data->links = $this->pageService->getAllRoutes();
$pockets = $page->findChildren();
$otherLanguages = $this->pageService->getOtherLanguageRoutes($this->data->id);
return \View::make('layouts.pages.projectOverview')
->with('data', $this->data)
->with('blocks', $page->blocks)
->with('otherLanguages', $otherLanguages->allTranslations)
->with('pockets', $pockets);
}
/**
* Get the part types overview for kapitan (as $page)
*
* @param $page
* @return mixed
*/
public function group($page, $other = false){
$otherLanguages = $this->pageService->getOtherLanguageRoutes($page->id);
$this->data->content = $page;
$this->data->activeParts = !$other;
if($other) $this->data->activeOtherParts = $other;
$this->data->activeType = false;
$this->data->links = $this->pageService->getAllRoutes();
$typeKapitan = str_replace('kapitan_', '', $this->data->content->code_name);
$partsTypes = $this->projectService->getPartTypesByKapitan($typeKapitan);
return \View::make('layouts.pages.projectGroup')
->with('data', $this->data)
->with('blocks', $page->blocks)
->with('partTypes', $partsTypes)
->with('url', \Request::url())
->with('otherLanguages', $otherLanguages->allTranslations);
}
/**
* Get available parts by rest_route
* where partType and kapitan Type isset
*
* @param $rest_route_id
* @return mixed
*/
public function type($rest_route_id){
//Get part route information for page content and part id (as routable_id)
$route = Route::where('rest_route', 'parts/'.$rest_route_id)
->where('route', \Request::path())
->first();
//var_dump($rest_route_id);
if(in_array($rest_route_id, [14, 15, 17])){
$this->data->activeParts = false;
$this->data->activeOtherParts = true;
}
else{
$this->data->activeParts = true;
}
$this->data->content = $this->pageService->getPageContent($rest_route_id);
$this->data->activeType = $route->routable_id;
$this->data->links = $this->pageService->getAllRoutes();
$typeKapitan = str_replace('kapitan_', '', $this->data->content->code_name);
$parts = $this->projectService->getPartsByPartTypeAndKapitan($typeKapitan, $route->routable_id);
$partsTypes = $this->projectService->getPartTypesByKapitan($typeKapitan);
$otherLanguages = $this->pageService->getOtherLanguageRoutes($this->data->content->id);
$segments = \Request::segments();
$url = \Request::root().'/'.$segments[0].'/'.$segments[1];
$this->data->content->translation->meta_title = ucfirst($segments[2]).' | '.$this->data->content->translation->meta_title;
return \View::make('layouts.pages.projectsFiltered')
->with('data', $this->data)
->with('blocks', $this->data->content->blocks)
->with('parts', $parts)
->with('partTypes', $partsTypes)
->with('url', $url)
->with('otherLanguages', $otherLanguages->allTranslations);
}
public function otherOverview($page){
$otherLanguages = $this->pageService->getOtherLanguageRoutes($page->id);
$this->data->content = $page;
$this->data->links = $this->pageService->getAllRoutes();
$this->data->activeOtherParts = true;
$pockets = $page->findChildren();
return \View::make('layouts.pages.otherGroup')
->with('data', $this->data)
->with('blocks', $page->blocks)
->with('pockets', $pockets)
->with('url', \Request::url())
->with('otherLanguages', $otherLanguages->allTranslations);
}
public function otherParts($page){
$otherLanguages = $this->pageService->getOtherLanguageRoutes($page->id);
$this->data->content = $page;
$this->data->links = $this->pageService->getAllRoutes();
$this->data->activeOtherParts = true;
$parts = $this->projectService->getOtherParts($page->code_name,$page->translation->slug);
return \View::make('layouts.pages.otherParts')
->with('data', $this->data)
->with('blocks', $page->blocks)
->with('parts', $parts)
->with('url', \Request::url())
->with('otherLanguages', $otherLanguages->allTranslations);
}
public function show($projectId){
$this->data = $this->projectService->getProject($projectId);
$this->data->content = (object)['code_name' => 'part'];
$this->data->activeParts = true;
$this->data->links = $this->pageService->getAllRoutes();
$segments = \Request::segments();
$url = \Request::root().'/'.$segments[0].'/'.$segments[1];
$kapitanTypes = [];
$categoryType = 'other';
foreach($this->data->categories()->get() as $category){
$categoryConverted = str_replace('_', '-', $category->code_name);
$kapitanTypes[] = $category->code_name;
if(str_contains($segments[1], $categoryConverted)) $categoryType = $category->code_name;
}
if( $segments[0] == 'overig'){
$categoryType = $this->projectService->getCategoryCodeName($segments[0].'/'.$segments[1]);
$this->data->activeParts = false;
$this->data->activeOtherParts = true;
$nextPrevious = $this->projectService->getNextPreviousParts($this->data->id, $categoryType, $this->data->partType);
}
else{
$nextPrevious = $this->projectService->getNextPreviousParts($this->data->id, $categoryType, $this->data->partType);
}
$this->data->kapitanTypes = $kapitanTypes;
$partsTypes = $this->projectService->getPartTypesByKapitan($categoryType);
$this->data->categoryType = $categoryType;
return \View::make('layouts.pages.projectDetail')
->with('partTypes', $partsTypes)
->with('url', $url)
->with('next', $nextPrevious['next'])
->with('previous', $nextPrevious['previous'])
->with('data', $this->data);
}
}