HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/KommaApp/PastEvents/PastEventController.php
<?php

namespace App\KommaApp\PastEvents;

use App\Http\Controllers\Controller;
use App\KommaApp\PastEvents\Models\PastEvent;
use App\KommaApp\Regions\Models\Region;
use Illuminate\Support\Str;

class PastEventController extends Controller
{
    private $modelPrefix = 'pages.pastEvents.';
    private $pastEventService;

    public function __construct(PastEventService $pastEventService)
    {
        parent::__construct();
        $this->pastEventService = $pastEventService;
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->pageService->getPageByCodeName('pastEvents');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        // Load the highlighted events
        $highlightedPastEvents = $this->pastEventService->getHighlightedPastEvents();

        // Get the id's of the highlighted events, because we need to exclude them from the paginated events
        $pastEventIds = $highlightedPastEvents->pluck('id')->all();

        $pastEvents = $this->pastEventService->getPastEvents(true, true, $pastEventIds);
        $pastEvents->withPath('/' . $this->links->pastEvents->route);

        // Return view
        return \View::make($this->baseViewPath.$this->modelPrefix.'index',[
            'page' => $page,
            'otherLanguages' => $otherLanguageRoutes,
            'highlightedEvents' => $highlightedPastEvents,
            'events' => $pastEvents,
        ]);

    }

    /**
     *
     * @param Region $region
     * @return \Illuminate\Contracts\View\View
     */
    public function region(Region $region){

        $page = $this->pageService->getPageByCodeName('pastEvents');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        $pastEvents = $this->pastEventService->getPastEventsByRegion($region->id);
        $pastEvents->withPath('/' . $this->links->pastEvents->route.'/'.Str::slug($region->name));

        // Return view
        return \View::make($this->baseViewPath.$this->modelPrefix.'region',[
            'page' => $page,
            'otherLanguages' => $otherLanguageRoutes,
            'events' => $pastEvents,
            'eventRegion' => $region,
        ]);
    }

    /**
     * @param PastEvent $pastEvent
     * @return \Illuminate\Contracts\View\View
     */
    public function show(PastEvent $pastEvent)
    {
        // Load translation by eager loading
        $pastEvent->load( 'translation', 'tags', 'tags.translation', 'partners', 'partners.type', 'partners.type.translation');

        $page = $this->pageService->getPageByCodeName('pastEvents');

        // Get the route in other languages for menu and meta title
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $pastEvent);

        // Get the other event in this region
        $otherEvents = $this->pastEventService->getPastEventsByRegion($pastEvent->region_id, false, [$pastEvent->id], 3);

        // Return view
        return \View::make($this->baseViewPath.$this->modelPrefix. 'show',[
            'page' => $page,
            'pastEvent' => $pastEvent,
            'otherPastEvents' => $otherEvents,
            'overviewRoute' => $this->links->pastEvents->route,
            'otherLanguages' => $otherLanguageRoutes,
        ]);
    }

}