Changeset View
Changeset View
Standalone View
Standalone View
src/app/Handlers/Storage.php
<?php | <?php | ||||
namespace App\Handlers; | namespace App\Handlers; | ||||
class Storage extends \App\Handlers\Base | class Storage extends \App\Handlers\Base | ||||
{ | { | ||||
public const MAX_ITEMS = 100; | public const MAX_ITEMS = 100; | ||||
public const ITEM_UNIT = 'GB'; | public const ITEM_UNIT = 'GB'; | ||||
/** | |||||
* The entitleable class for this handler. | |||||
* | |||||
* @return string | |||||
*/ | |||||
public static function entitleableClass(): string | public static function entitleableClass(): string | ||||
{ | { | ||||
return \App\User::class; | return \App\User::class; | ||||
} | } | ||||
public static function preReq($entitlement, $object): bool | /** | ||||
* SKU handler metadata. | |||||
* | |||||
* @param \App\Sku $sku The SKU object | |||||
* | |||||
* @return array | |||||
*/ | |||||
public static function metadata(\App\Sku $sku): array | |||||
{ | { | ||||
if (!$entitlement->sku->active) { | $data = parent::metadata($sku); | ||||
\Log::error("Sku not active"); | |||||
return false; | |||||
} | |||||
// TODO: The storage can not be modified to below what is already consumed. | $data['readonly'] = true; // only the checkbox will be disabled, not range | ||||
$data['enabled'] = true; | |||||
$data['range'] = [ | |||||
'min' => $sku->units_free, | |||||
'max' => self::MAX_ITEMS, | |||||
'unit' => self::ITEM_UNIT, | |||||
]; | |||||
return true; | return $data; | ||||
} | } | ||||
/** | /** | ||||
* 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 90; | return 90; | ||||
} | } | ||||
} | } |