2017-02-16 00:32:33 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Category;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Gate;
|
2017-08-22 14:26:08 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-02-16 00:32:33 -08:00
|
|
|
|
|
|
|
class CategoriesTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformCategories (Collection $categorys, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($categorys as $category) {
|
|
|
|
$array[] = self::transformCategory($category);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformCategory (Category $category = null)
|
|
|
|
{
|
|
|
|
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),
|
2017-11-07 11:11:47 -08:00
|
|
|
'image' => ($category->image) ? app('categories_upload_url').e($category->image) : null,
|
2017-11-21 20:33:30 -08:00
|
|
|
'category_type' => e($category->category_type),
|
2017-10-11 14:44:25 -07:00
|
|
|
'eula' => ($category->getEula()) ? true : false,
|
2017-08-22 14:26:08 -07:00
|
|
|
'checkin_email' => ($category->checkin_email =='1') ? true : false,
|
2017-02-16 00:32:33 -08:00
|
|
|
'require_acceptance' => ($category->require_acceptance =='1') ? true : false,
|
|
|
|
'assets_count' => $category->assets_count,
|
|
|
|
'accessories_count' => $category->accessories_count,
|
|
|
|
'consumables_count' => $category->consumables_count,
|
|
|
|
'components_count' => $category->components_count,
|
2018-05-04 21:01:38 -07:00
|
|
|
'licenses_count' => $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'] = [
|
2017-03-03 17:56:05 -08:00
|
|
|
'update' => Gate::allows('update', Category::class) ? true : false,
|
2017-10-19 11:41:35 -07:00
|
|
|
'delete' => (Gate::allows('delete', Category::class) && ($category->assets_count == 0) && ($category->accessories_count == 0) && ($category->consumables_count == 0) && ($category->components_count == 0)) ? true : false,
|
2017-02-16 00:32:33 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|