2017-02-16 00:32:33 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-02-16 00:32:33 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-02-16 00:32:33 -08:00
|
|
|
use App\Models\Category;
|
|
|
|
use Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-09-29 21:33:52 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2017-02-16 00:32:33 -08:00
|
|
|
|
|
|
|
class CategoriesTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCategories(Collection $categorys, $total)
|
2017-02-16 00:32:33 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-02-16 00:32:33 -08:00
|
|
|
foreach ($categorys as $category) {
|
|
|
|
$array[] = self::transformCategory($category);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-02-16 00:32:33 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCategory(Category $category = null)
|
2017-02-16 00:32:33 -08:00
|
|
|
{
|
|
|
|
if ($category) {
|
|
|
|
$array = [
|
2017-08-22 14:53:48 -07:00
|
|
|
'id' => (int) $category->id,
|
2017-02-16 00:32:33 -08:00
|
|
|
'name' => e($category->name),
|
2018-09-29 21:33:52 -07:00
|
|
|
'image' => ($category->image) ? Storage::disk('public')->url('categories/'.e($category->image)) : null,
|
2020-05-23 10:36:02 -07:00
|
|
|
'category_type' => ucwords(e($category->category_type)),
|
2020-09-11 16:05:42 -07:00
|
|
|
'has_eula' => ($category->getEula() ? true : false),
|
2021-09-10 20:23:49 -07:00
|
|
|
'use_default_eula' => ($category->use_default_eula=='1' ? true : false),
|
2020-05-23 10:36:02 -07:00
|
|
|
'eula' => ($category->getEula()),
|
2021-06-10 13:15:52 -07:00
|
|
|
'checkin_email' => ($category->checkin_email == '1'),
|
2020-05-23 10:36:02 -07:00
|
|
|
'require_acceptance' => ($category->require_acceptance == '1'),
|
|
|
|
'item_count' => (int) $category->itemCount(),
|
2018-05-18 15:48:48 -07:00
|
|
|
'assets_count' => (int) $category->assets_count,
|
|
|
|
'accessories_count' => (int) $category->accessories_count,
|
|
|
|
'consumables_count' => (int) $category->consumables_count,
|
|
|
|
'components_count' => (int) $category->components_count,
|
|
|
|
'licenses_count' => (int) $category->licenses_count,
|
2017-08-22 14:26:08 -07:00
|
|
|
'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'),
|
2017-02-16 00:32:33 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'update' => Gate::allows('update', Category::class),
|
|
|
|
'delete' => $category->isDeletable(),
|
2017-02-16 00:32:33 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|