File: D:/HostingSpaces/SBogers10/bomacon.komma.pro/app/Machines/MachineController.php
<?php
namespace App\Machines;
use App\Base\Controller;
use App\Buttons\Models\Button;
use App\Buttons\Models\ButtonTranslation;
use App\Components\ComponentService;
use App\Pages\Models\Page;
use App\Machines\Models\Machine;
use App\Servicepoints\Models\Servicepoint;
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->setSharebleVariables($page->servicepoint_id, $page->cta_button_id, $page->cta_heading);
// Return view
return view('site.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);
$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();
$showServicePoint = Servicepoint::find( !empty($machine->servicepoint_id) ? $machine->servicepoint_id : config('site.global_CTA_servicepoint_id'));
$viewData = [
'showServicePoint' => $showServicePoint,
'page' => $page,
'components' => $components,
'machines' => $machines,
'machine' => $machine,
'links' => $this->links,
'languageMenu' => $languageMenu,
'discover_page_codenames' => $discover_more_page_codenames,
];
$this->pageService->setSharebleVariables($page->servicepoint_id, $page->cta_button_id, $page->cta_heading);
// Return view
return view('site.templates.machines_show', $viewData);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
dd('customize filter function in MachineController');
// if (sizeof($filters) != 1) {
// throw abort(404);
// }
// $categoryName = $filters[0];
//
// // Check if category exist else trow 404
// if ( ! $category = MachineCategoryTranslation::where('slug', $categoryName)
// ->with('translatable')
// ->first()) {
// throw abort(404);
// }
//
// $page = $this->pageService->getPageByCodeName('blog');
// $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
// //Get machines through the category
// $machines = $category->translatable->machines()->paginate(8);
// $machines->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
// // Return view
// return \View::make($this->baseViewPath.$this->pagePrefix.'index',[
// 'page' => $page,
// 'links' => $this->links,
// 'otherLanguages' => $otherLanguageRoutes,
// 'machines' => $machines,
// ]);
}
}