2016-04-26 03:53:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
use App\Models\User;
|
2016-04-27 02:06:19 +02:00
|
|
|
use Utils;
|
2016-04-26 03:53:39 +02:00
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class GenericEntityPolicy
|
|
|
|
*/
|
2016-04-26 03:53:39 +02:00
|
|
|
class GenericEntityPolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param $itemType
|
|
|
|
* @param $ownerUserId
|
|
|
|
* @return bool|mixed
|
|
|
|
*/
|
|
|
|
public static function editByOwner(User $user, $itemType, $ownerUserId) {
|
2016-04-27 02:06:19 +02:00
|
|
|
$itemType = Utils::getEntityName($itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
if (method_exists("App\\Policies\\{$itemType}Policy", 'editByOwner')) {
|
2016-07-03 18:11:58 +02:00
|
|
|
return call_user_func(["App\\Policies\\{$itemType}Policy", 'editByOwner'], $user, $ownerUserId);
|
2016-04-26 03:53:39 +02:00
|
|
|
}
|
2016-10-27 10:57:51 +02:00
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param $itemType
|
|
|
|
* @param $ownerUserId
|
|
|
|
* @return bool|mixed
|
|
|
|
*/
|
|
|
|
public static function viewByOwner(User $user, $itemType, $ownerUserId) {
|
2016-04-27 02:06:19 +02:00
|
|
|
$itemType = Utils::getEntityName($itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
if (method_exists("App\\Policies\\{$itemType}Policy", 'viewByOwner')) {
|
2016-07-03 18:11:58 +02:00
|
|
|
return call_user_func(["App\\Policies\\{$itemType}Policy", 'viewByOwner'], $user, $ownerUserId);
|
2016-04-26 03:53:39 +02:00
|
|
|
}
|
2016-10-27 10:57:51 +02:00
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param $itemType
|
|
|
|
* @return bool|mixed
|
|
|
|
*/
|
|
|
|
public static function create(User $user, $itemType) {
|
2016-10-27 10:57:51 +02:00
|
|
|
$entityName = Utils::getEntityName($itemType);
|
|
|
|
if (method_exists("App\\Policies\\{$entityName}Policy", 'create')) {
|
|
|
|
return call_user_func(["App\\Policies\\{$entityName}Policy", 'create'], $user, $itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
}
|
2016-10-27 10:57:51 +02:00
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 10:57:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param $itemType
|
|
|
|
* @return bool|mixed
|
|
|
|
*/
|
|
|
|
public static function view(User $user, $itemType) {
|
|
|
|
$entityName = Utils::getEntityName($itemType);
|
|
|
|
if (method_exists("App\\Policies\\{$entityName}Policy", 'view')) {
|
|
|
|
return call_user_func(["App\\Policies\\{$entityName}Policy", 'view'], $user, $itemType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|