File: D:/HostingSpaces/SBogers10/stielman.komma.nl/app/Machines/MachineController.php
<?php
namespace App\Machines;
use App\Base\Controller;
use App\Buttons\Models\Button;
use App\Buttons\Models\ButtonTranslation;
use App\Pages\Models\Page;
use App\Machines\Models\Machine;
use App\Servicepoints\Models\Servicepoint;
use Komma\KMS\Components\ComponentService;
class MachineController extends Controller
{
private $machineservice;
public function __construct(Machineservice $machineservice)
{
parent::__construct();
$this->machineservice = $machineservice;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->links->machines->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$machines = $this->machineservice->getAllMachines(true);
$machines->withPath('/' . $this->links->machines->route);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($page->translation);
$this->pageService->setSharableVariables($page->servicepoint_id, $page->servicepoint_button_id, $page->servicepoint_heading);
// split the Hero images from the "normal" page images
list($documents, $heroDocuments) = $page->translation->documents->partition(function ($document) {
return $document->key == 'Documents-pages';
});
$page->documents = $documents;
$heroButton = Button::where('id', $page->translation->hero_button_id)->with('translation')->first();
$page->hero = (object)[
'documents' => $heroDocuments,
'active' => $page->translation->hero_active,
'title' => $page->translation->hero_title,
'description' => $page->translation->hero_description,
'buttons' => !empty($heroButton) ? $heroButton : null,
];
// Return view
return view('templates.machines_index',[
'page' => $page,
'components' => $components,
'machines' => $machines,
'links' => $this->links,
'languageMenu' => $languageMenu,
]);
}
/**
* @param Machine $service
* @return \Illuminate\Contracts\View\View
*/
public function show(Machine $machine)
{
$machine->load('translation','translations');
$machines = $this->machineservice->getAllMachines();
$page = $this->links->machines->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$this->pageService->extendLanguageMenuWithResource($languageMenu, $machine);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($machine->translation);
// split the Hero images from the "normal" post images
list($documents, $heroDocuments) = $machine->translation->documents->partition(function ($document) {
return $document->key == 'Documents-machines';
});
$machine->documents = $documents;
// fill the page hero object
$heroButton = Button::where('id', $machine->translation->hero_button_id)->with('translation')->first();
$machine->hero = (object)[
'documents' => $heroDocuments,
'active' => $machine->translation->hero_active,
'title' => $machine->translation->hero_title,
'description' => $machine->translation->hero_description,
'buttons' => !empty($heroButton) ? $heroButton : null,
];
$discover_more_page_codenames = $page->discoverPages()->get()->map(function(Page $page) {
return $page->code_name;
})->toArray();
$viewData = [
'page' => $page,
'components' => $components,
'machines' => $machines,
'machine' => $machine,
'links' => $this->links,
'languageMenu' => $languageMenu,
'discover_page_codenames' => $discover_more_page_codenames,
];
$this->pageService->setSharableVariables($machine->servicepoint_id, $machine->servicepoint_button_id, $machine->servicepoint_heading);
// Return view
return view('templates.machines_show', $viewData);
}
}