This repository has been archived on 2021-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
laravel-elearning/app/Policies/TestPolicy.php
2016-10-26 16:17:58 +02:00

80 lines
1.9 KiB
PHP

<?php
namespace App\Policies;
use App\User;
use App\Question;
use App\Test;
use Illuminate\Auth\Access\HandlesAuthorization;
class TestPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the test.
*
* @param \App\User $user
* @param \App\Test $test
* @return mixed
*/
public function view(User $user, Test $test)
{
if ($user->isAdministrator() || ($user->isModerator() AND ($user->group_id === $test->group_id || $test->group_id === 1))) {
return true;
}
return false;
}
/**
* Determine whether the user can create tests.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user)
{
if ($user->isAdministrator() || $user->isModerator()) {
return true;
}
return false;
}
/**
* Determine whether the user can update the test.
*
* @param \App\User $user
* @param \App\Test $test
* @return mixed
*/
public function update(User $user, Test $test)
{
if ($user->isAdministrator() || ($user->isModerator() AND $user->group_id === $test->group_id)) {
return true;
}
return false;
}
/**
* Determine whether the user can delete the test.
*
* @param \App\User $user
* @param \App\Test $test
* @return mixed
*/
public function delete(User $user, Test $test)
{
if ($user->isAdministrator() || ($user->isModerator() AND $user->group_id === $test->group_id)) {
return true;
}
return false;
}
public function createQuestion(User $user, Test $test)
{
if ($user->isAdministrator() || ($user->isModerator() AND $user->group_id === $test->group_id)) {
return true;
}
return false;
}
}