File: D:/HostingSpaces/SBogers10/kemi.komma.pro/app/KommaApp/Pages/PageController.php
<?php
namespace App\KommaApp\Pages;
use App\Http\Controllers\Controller;
use App\KommaApp\Jobs\JobService;
use App\KommaApp\Machines\MachineService;
use App\KommaApp\Pages\Models\Page;
use App\KommaApp\Posts\PostService;
use App\KommaApp\Projects\ProjectService;
class PageController extends Controller
{
private $pagePrefix = 'pages.';
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Page $page)
{
// Load translation by eager loading
$page->load( 'translation', 'images');
// Check if given Page belongs to the set site
if($page->site_id != \App::getSite()->id) throw abort(404);
// Get the route in other languages for menu and meta title
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
$page->translation = $this->decodeDynamicContent( $page->translation );
$view = $this->baseViewPath.$this->pagePrefix. $page->code_name;
$machineService = new MachineService();
$machines = null;
if( ! \View::exists($view)) {
if(!empty($page->getParent()) && $page->getParent()->code_name == 'production') {
$machines = $machineService->getMachinesByType($page->code_name); //$this->machineService->getFullMachineTypeById($production->machines);
$view = $this->baseViewPath . $this->pagePrefix . 'production-subpage';
} else {
$view = $this->baseViewPath . $this->pagePrefix . 'default';
}
}
if($page->code_name == 'quality'){
$machines = $machineService->getMachinesByType('measure');
}
$machineTypes = null;
if($page->code_name == 'machinepark' || $page->code_name == 'production') {
$machineTypes = $machineService->getFullMachineTypes();
}
$homePost = null;
if($page->code_name == 'home') {
$postService = new PostService();
$homePost = $postService->getAllPosts()->first();
}
$homeJob = null;
$jobService = new JobService();
if($page->code_name == 'home') {
$homeJob = $jobService->getAllJobs()->first();
}
$homeProject = null;
$projectService = new ProjectService();
if($page->code_name == 'home' || $page->code_name == 'engineering') {
$homeProject = $projectService->getAllProjects()->first();
}
// Get the parent so we can use check on it
$pageParent = $page->getParent();
if(in_array($page->code_name, ['production', 'projects']) || (isset($pageParent) && in_array($pageParent->code_name, ['production', 'projects'])) ){
\View::share('showHexagon', true);
}
// Return view
return \View::make($view,[
'page' => $page,
'machines' => $machines,
'machineTypes' => $machineTypes,
'links' => $this->links,
'jobCount' => $this->jobCount,
'homeJob' => $homeJob,
'homePost' => $homePost,
'homeProject' => $homeProject,
'otherLanguages' => $otherLanguageRoutes,
]);
}
}