Updated department transformer

This commit is contained in:
snipe 2017-05-23 02:37:30 -07:00
parent e2f2f9e154
commit 64f17cecbf

View file

@ -9,43 +9,39 @@ use App\Helpers\Helper;
class DepartmentsTransformer class DepartmentsTransformer
{ {
public function transformDepartments (Collection $locations, $total) public function transformDepartments (Collection $departments, $total)
{ {
$array = array(); $array = array();
foreach ($locations as $location) { foreach ($departments as $department) {
$array[] = self::transformDepartment($location); $array[] = self::transformDepartment($department);
} }
return (new DatatablesTransformer)->transformDatatables($array, $total); return (new DatatablesTransformer)->transformDatatables($array, $total);
} }
public function transformDepartment (Department $location = null) public function transformDepartment (Department $department = null)
{ {
if ($location) { if ($department) {
$assets_arr = [];
foreach($location->assets() as $asset) {
$assets_arr = ['id' => $asset->id];
}
$children_arr = [];
foreach($location->childDepartments() as $child) {
$children_arr = ['id' => $child->id];
}
$array = [ $array = [
'id' => e($location->id), 'id' => e($department->id),
'name' => e($location->name), 'name' => e($department->name),
'address' => e($location->address), 'company' => ($department->company) ? [
'city' => e($location->city), 'id' => (int) $department->company->id,
'state' => e($location->state), 'name'=> e($department->company->name)
'assets_checkedout' => $location->assets()->count(), ] : null,
'assets_default' => $location->assignedassets()->count(), 'manager' => ($department->manager) ? [
'country' => e($location->country), 'id' => (int) $department->manager->id,
'assets' => $assets_arr, 'name' => e($department->manager->getFullNameAttribute()),
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'), 'first_name'=> e($department->manager->first_name),
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'), 'last_name'=> e($department->manager->last_name)
'parent_id' => e($location->parent_id), ] : null,
'children' => $children_arr, 'location' => ($department->location) ? [
'id' => (int) $department->location->id,
'name' => e($department->location->name)
] : null,
'users_count' => e($department->users_count),
'created_at' => Helper::getFormattedDateObject($department->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($department->updated_at, 'datetime'),
]; ];
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [