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/vebon.komma.pro/app/KommaApp/Dashboard/DashboardController.php
<?php

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

namespace KommaApp\Dashboard;

use Illuminate\Support\Facades\Redirect;
use KommaApp\Audit\auditService;
use KommaApp\Audit\Models\Audit;
use KommaApp\Core\CoreController;

class DashboardController extends CoreController
{
    /**
     * @var auditService
     */
    private $auditService;


    /**
     * DashboardController constructor.
     * @param auditService $auditService
     */
    public function __construct(auditService $auditService)
    {
        $this->middleware('auth:endUser');
        $this->auditService = $auditService;
        $this->endUser = \Auth::endUser()->get();
    }

    public function index()
    {

        switch ($this->endUser->role) {
            case 'member':
                return $this->memberDashboard();
            case
            'auditor':
                return $this->auditorDashboard();
        }
        return \App::abort(404, \Auth::endUser()->get()->role . ' dasboard not found');
    }


    /**
     * Check if there is an open audit, redirect to that
     * Else go to the archive
     *
     * @return mixed
     */
    public function memberDashboard()
    {
        //Get an open audit
        if ($audit = $this->auditService->getOpenAudit($this->endUser)) {
            //If there is one, do to the detail page
            if ($audit) return \Redirect::route('audit.detail', [$audit->id]);
        }

        //Go to the archive
        return \Redirect::route('member.archive', [$this->endUser]);

    }

    /**
     * @return mixed
     */
    public function auditorDashboard()
    {
        //Get audits without auditor
        $availableAudits = $this->auditService->getAuditsReadyToBeJudged();

        //Get own open audits
        $activeAudits = $this->auditService->getActiveAuditsForAuditor($this->endUser);

        $closedAudits = $this->auditService->getClosedAuditsForAuditor($this->endUser);

        return \View::make('dashboard/auditor')
            ->with([
                'availableAudits' => $availableAudits,
                'activeAudits' => $activeAudits,
                'closedAudits' => $closedAudits
            ]);
    }

}