File: D:/HostingSpaces/stafa/stafa.nl/app/Komma/Assortments/AssortmentController.php
<?php
namespace App\Komma\Assortments;
use App\Komma\Base\Controller;
use App\Komma\Buttons\Models\Button;
use App\Komma\Buttons\Models\ButtonTranslation;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
use App\Komma\Assortments\Models\Assortment;
use App\Komma\Servicepoints\Models\Servicepoint;
class AssortmentController extends Controller
{
private $assortmentService;
public function __construct(AssortmentService $assortmentService)
{
parent::__construct();
$this->assortmentService = $assortmentService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->links->assortment->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$assortments = $this->assortmentService->getAllAssortments();
// Get the chosen servicepoint for the page
$servicepoint = null;
if(!empty($page->translation->servicepoint_id)) $servicepoint = Servicepoint::find($page->translation->servicepoint_id);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($page->translation);
// Return view
return view('site.templates.assortments_index',[
'page' => $page,
'components' => $components,
'assortments' => $assortments,
'links' => $this->links,
'languageMenu' => $languageMenu,
'servicepoint' => $servicepoint,
]);
}
/**
* @param Assortment $service
* @return \Illuminate\Contracts\View\View
*/
public function show(Assortment $assortment)
{
$assortment->load('translation','translations', 'site');
// This checks if the assortment belongs to the set site
if(! $assortment->site == $this->site) abort(404);
$page = $this->links->assortment->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$this->pageService->extendLanguageMenuWithResource($languageMenu, $assortment);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($assortment->translation);
// By default get the first servicepoint
$servicepoint = $assortment->translation->servicepoint ?? Servicepoint::first();
// split the Hero images from the "normal" post images
list($documents, $heroDocuments) = $assortment->documents->partition(function ($document) {
return $document->key == 'Documents-assortments';
});
$assortment->documents = $documents;
// fill the page hero object
$heroButton = Button::where('id', $assortment->translation->hero_button_id)->with('translation')->first();
$assortment->hero = (object)[
'documents' => $heroDocuments,
'active' => $assortment->translation->hero_active,
'title' => $assortment->translation->hero_title,
'description' => $assortment->translation->hero_description,
'buttons' => !empty($heroButton) ? $heroButton : null,
];
$viewData = [
'page' => $page,
'components' => $components,
'assortment' => $assortment,
'links' => $this->links,
'languageMenu' => $languageMenu,
'servicepoint' => $servicepoint
];
// Return view
return view('site.templates.assortments_show', $viewData);
}
}