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
]);
}
}