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/SBogers84/zuiderbos.nl/app/Komma/References/ReferenceController.php
<?php

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

namespace Komma\References;

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

class ReferenceController extends \BaseController
{

    public $data;
    protected $pageService;
    protected $referenceService;
    public $languageService;

    public function __construct(PageService $pageService, LanguageService $languageService, ReferenceService $referenceService)
    {
        parent::__construct();
        $this->pageService = $pageService;
        $this->referenceService = $referenceService;
        $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();

        return \View::make('layouts.pages.references.index')
            ->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->referenceService->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 <= (sizeof($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.references.show')
            ->with('page', $page)
            ->with('reference', $reference)
            ->with('links', $links);
    }

}