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/BVerhoeven/verhoevendak.nl/app/Komma/Projects/ProjectController.php
<?php

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

namespace Komma\Projects;

use Komma\Blocks\BlockService;
use Komma\Categories\CategoryService;
use Komma\Images\ImageService;
use Komma\LanguageService;
use Komma\Pages\PageService;
use Illuminate\Http\Request;

class ProjectController extends \BaseController
{

    protected $pageService;
    protected $blockService;
    protected $projectService;
    protected $categoryService;

    public function __construct(PageService $pageService, BlockService $blockService, ProjectService $projectService, CategoryService $categoryService)
    {
        parent::__construct();
        $this->pageService = $pageService;
        $this->blockService = $blockService;
        $this->projectService = $projectService;
        $this->categoryService = $categoryService;
    }

    //Project index page
    public function index(){

        //get content of page and get all page links
        $page = $this->pageService->getPageByCodeName('projects');
        $links = $this->pageService->getAllRoutes();

        $cat = null;
        if(\Request::has('cat')) {
            if(strpos(\Request::get('cat'), ',') !== false ) {
                $cat = explode(",", \Request::get('cat'));
            } else {
                $cat = \Request::get('cat');
            }
        }
        debug($cat);
        if(count($cat) == 1) {
            $projects = $this->projectService->getProjectsByCategory($cat);
        } else {
            //Get all projects
            $projects = $this->projectService->getAllProjects(true);
        }

        $categories = $this->categoryService->getAllCategories();

        return \View::make('layouts.pages.projects.index')
            ->with('page', $page)
            ->with('links', $links)
            ->with('categories', $categories)
            ->with('projects', $projects)
            ->with('currentCat', $cat);

    }

    public function show($projectId){

        //Check if language matches the url before loading content
        $page = $this->projectService->getProject($projectId);
        $page->parent = $this->pageService->getPageByCodeName('projects');
        //$page->nextSibling = $page->parent->getChildren()[$projectId].

        $projects = $this->projectService->getAllProjects(false);
        $nearbyProjects = $this->projectService->getProjectsNearLocation($projectId, $page->translation->location);
        $links = $this->pageService->getAllRoutes();

        $homeBlock = $this->pageService->getPageByCodeName('home')->content->translation->description;

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

    public function getFilteredProjects(){
        //debug(\Request::has('categories'));
        $cats = \Request::has('categories') ? \Request::get('categories') : $this->categoryService->getAllCategories();
        $projects = $this->projectService->getProjectsByCategory($cats);

        return $projects;
    }

}