Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SkusController.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | class SkusController extends Controller | ||||
/** | /** | ||||
* Display a listing of the sku. | * Display a listing of the sku. | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$response = []; | $response = []; | ||||
$skus = Sku::select()->orderBy('title')->get(); | $skus = Sku::select()->get(); | ||||
// Note: we do not limit the result to active SKUs only. | // Note: we do not limit the result to active SKUs only. | ||||
// It's because we might need users assigned to old SKUs, | // It's because we might need users assigned to old SKUs, | ||||
// we need to display these old SKUs on the entitlements list | // we need to display these old SKUs on the entitlements list | ||||
foreach ($skus as $sku) { | foreach ($skus as $sku) { | ||||
if ($data = $this->skuElement($sku)) { | if ($data = $this->skuElement($sku)) { | ||||
$response[] = $data; | $response[] = $data; | ||||
} | } | ||||
} | } | ||||
usort($response, function ($a, $b) { | |||||
return ($b['prio'] <=> $a['prio']); | |||||
}); | |||||
return response()->json($response); | return response()->json($response); | ||||
} | } | ||||
/** | /** | ||||
* Store a newly created sku in storage. | * Store a newly created sku in storage. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request | * @param \Illuminate\Http\Request $request | ||||
* | * | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | protected function skuElement($sku): ?array | ||||
$handler = strtolower(end($handler)); | $handler = strtolower(end($handler)); | ||||
$data = $sku->toArray(); | $data = $sku->toArray(); | ||||
$data['type'] = $type; | $data['type'] = $type; | ||||
$data['handler'] = $handler; | $data['handler'] = $handler; | ||||
$data['readonly'] = false; | $data['readonly'] = false; | ||||
$data['enabled'] = false; | $data['enabled'] = false; | ||||
$data['prio'] = $sku->handler_class::priority(); | |||||
// Use localized value, toArray() does not get them right | // Use localized value, toArray() does not get them right | ||||
$data['name'] = $sku->name; | $data['name'] = $sku->name; | ||||
$data['description'] = $sku->description; | $data['description'] = $sku->description; | ||||
unset($data['handler_class']); | unset($data['handler_class']); | ||||
switch ($handler) { | switch ($handler) { | ||||
case 'activesync': | |||||
$data['required'] = ['groupware']; | |||||
break; | |||||
case 'auth2f': | |||||
$data['forbidden'] = ['activesync']; | |||||
break; | |||||
case 'storage': | case 'storage': | ||||
// Quota range input | // Quota range input | ||||
$data['readonly'] = true; // only the checkbox will be disabled, not range | $data['readonly'] = true; // only the checkbox will be disabled, not range | ||||
$data['enabled'] = true; | $data['enabled'] = true; | ||||
$data['range'] = [ | $data['range'] = [ | ||||
'min' => $data['units_free'], | 'min' => $data['units_free'], | ||||
'max' => $sku->handler_class::MAX_ITEMS, | 'max' => $sku->handler_class::MAX_ITEMS, | ||||
'unit' => $sku->handler_class::ITEM_UNIT, | 'unit' => $sku->handler_class::ITEM_UNIT, | ||||
Show All 13 Lines |