2017-02-01 18:50:28 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-02-01 18:50:28 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-02-01 18:50:28 -08:00
|
|
|
use App\Models\Group;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-02-01 18:50:28 -08:00
|
|
|
|
|
|
|
class GroupsTransformer
|
|
|
|
{
|
2021-12-23 17:54:34 -08:00
|
|
|
public function transformGroups (Collection $groups, $total = null)
|
2017-02-01 18:50:28 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-02-01 18:50:28 -08:00
|
|
|
foreach ($groups as $group) {
|
|
|
|
$array[] = self::transformGroup($group);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-12-23 17:54:34 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
2017-02-01 18:50:28 -08:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformGroup(Group $group)
|
2017-02-01 18:50:28 -08:00
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $group->id,
|
2017-02-01 18:50:28 -08:00
|
|
|
'name' => e($group->name),
|
2017-09-27 15:18:29 -07:00
|
|
|
'permissions' => json_decode($group->permissions),
|
2017-07-25 23:40:30 -07:00
|
|
|
'users_count' => (int) $group->users_count,
|
2024-02-28 00:15:59 -08:00
|
|
|
'created_by' => ($group->admin) ? e($group->admin->present()->fullName) : null,
|
2017-03-03 17:53:42 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($group->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($group->updated_at, 'datetime'),
|
2017-02-01 18:50:28 -08:00
|
|
|
];
|
|
|
|
|
2017-02-08 18:24:55 -08:00
|
|
|
$permissions_array['available_actions'] = [
|
|
|
|
'update' => Gate::allows('superadmin') ? true : false,
|
|
|
|
'delete' => Gate::allows('superadmin') ? true : false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
2017-02-01 18:50:28 -08:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|