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/SBogers10/zuiderbos.komma.pro/app/Komma/Interns/InternController.php
<?php

/**
 * Short description for the file.
 *
 * @author      Komma <support@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Interns;

use Komma\Kms\Schools\School;
use Komma\LanguageService;
use Komma\Pages\PageService;

class InternController extends \BaseController
{
    public $data;

    protected $pageService;

    protected $internService;

    public $languageService;

    public function __construct(PageService $pageService, LanguageService $languageService, InternService $internService)
    {
        parent::__construct();
        $this->pageService = $pageService;
        $this->$internService = $internService;
        $this->languageService = $languageService;
    }

    //Overview page
    public function index($page = null)
    {
        if ($page == null) {
            //Check if language matches the url before loading the content
            $this->languageService->checkRouteWithSetLanguage();

            //get content of page by route because of the multiple news overviews all page links
            $page = $this->pageService->getPageByRoute(\Request::path());

            // Get root parent and append code_name to page
            // So we can find out to which branch/school the page belongs
            if ($page->getDepth() != 1) {
                $page->root = $this->pageService->getRootParent($page);
            } else {
                // The page itself is the root branch, so to prevent writing if/else statements append it as branch
                $page->root = $page;
            }

            // Load school to page
            $page->school = School::where('type', $page->root->code_name)->first();
        }

        $links = $this->pageService->getAllRoutes();
        $interns = $this->internService->getAllInterns();

        return \View::make('layouts.pages.interns.index')
            ->with('interns', $interns)
            ->with('page', $page)
            ->with('links', $links);
    }

    public function show($referenceId)
    {
        //Check if language matches the url before loading content
        $this->languageService->checkRouteWithSetLanguage();

        //Load post content and translation of this reference
        $reference = $this->internService->getReference($referenceId);
        $links = $this->pageService->getAllRoutes();

        // Get Page by route because we can't use the rest_root 'news' to get it
        // This is because there are multiple news overviews
        $segments = \Request::segments();
        $parentRoute = '';
        for ($i = 0; $i <= (count($segments) - 2); $i++) {
            $parentRoute .= $segments[$i].'/';
        }
        $parentRoute = rtrim($parentRoute, '/');

        $page = $this->pageService->getPageByRoute($parentRoute);
        $page->root = $this->pageService->getRootParent($page);
        $page->school = School::where('type', $page->root->code_name)->first();

        return \View::make('layouts.pages.interns.show')
            ->with('page', $page)
            ->with('reference', $reference)
            ->with('links', $links);
    }
}