Changeset View
Changeset View
Standalone View
Standalone View
src/app/Handlers/Base.php
- This file was copied to src/app/Handlers/Beta.php.
Show All 9 Lines | abstract class Base | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
public static function entitleableClass(): string | public static function entitleableClass(): string | ||||
{ | { | ||||
return ''; | return ''; | ||||
} | } | ||||
/** | /** | ||||
* Check if the SKU is available to the user. An SKU is available | |||||
* to the user when either it is active or there's already an | |||||
* active entitlement. | |||||
* | |||||
* @param \App\Sku $sku The SKU object | |||||
* @param \App\User $user The user object | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public static function isAvailable(\App\Sku $sku, \App\User $user): bool | |||||
{ | |||||
if (!$sku->active) { | |||||
if (!$user->entitlements()->where('sku_id', $sku->id)->first()) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
/** | |||||
* Metadata of this SKU handler. | |||||
* | |||||
* @param \App\Sku $sku The SKU object | |||||
* | |||||
* @return array | |||||
*/ | |||||
public static function metadata(\App\Sku $sku): array | |||||
{ | |||||
$handler = explode('\\', static::class); | |||||
$handler = strtolower(end($handler)); | |||||
$type = explode('\\', static::entitleableClass()); | |||||
$type = strtolower(end($type)); | |||||
return [ | |||||
// entitleable type | |||||
'type' => $type, | |||||
// handler (as a keyword) | |||||
'handler' => $handler, | |||||
vanmeeuwen: the value for the boolean and the comment seem to contradict one another. | |||||
// readonly entitlement state cannot be changed | |||||
'readonly' => false, | |||||
// is entitlement enabled by default? | |||||
'enabled' => false, | |||||
// priority on the entitlements list | |||||
'prio' => static::priority(), | |||||
]; | |||||
} | |||||
/** | |||||
* Prerequisites for the Entitlement to be applied to the object. | * Prerequisites for the Entitlement to be applied to the object. | ||||
* | * | ||||
* @param \App\Entitlement $entitlement | * @param \App\Entitlement $entitlement | ||||
* @param mixed $object | * @param mixed $object | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public static function preReq($entitlement, $object): bool | public static function preReq($entitlement, $object): bool | ||||
{ | { | ||||
$type = static::entitleableClass(); | |||||
if (empty($type) || empty($entitlement->entitleable_type)) { | |||||
\Log::error("Entitleable class/type not specified"); | |||||
return false; | |||||
} | |||||
if ($type !== $entitlement->entitleable_type) { | |||||
\Log::error("Entitleable class mismatch"); | |||||
return false; | |||||
} | |||||
if (!$entitlement->sku->active) { | |||||
\Log::error("Sku not active"); | |||||
return false; | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* The priority that specifies the order of SKUs in UI. | * The priority that specifies the order of SKUs in UI. | ||||
* Higher number means higher on the list. | * Higher number means higher on the list. | ||||
* | * | ||||
* @return int | * @return int | ||||
*/ | */ | ||||
public static function priority(): int | public static function priority(): int | ||||
{ | { | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } |
the value for the boolean and the comment seem to contradict one another.