snipe-it/app/Http/Transformers/DepartmentsTranformer.php
snipe 75b527ab59 Features/image uploads (#4320)
* Locations API support for image

* Added manufacturers API support for image

* Added manufacturers API support for image

* Added image support for locations add/update

* Added manufacturer image upload support to controller

* General image string

* Added blade support for image uploads/delete image

* Added $request support (from Input::)

* Added image support in API transformers

* Added image to Manufacturers presenter for data table

* Migration to create image fields

* Ignore the contents of the new image directories

* Create new image upload directories

* Created components/consumables uploads directory

* Fixed missing textSearch scope from companies

* Added ignore for companies uploads directory

* Added blade support for image upload

* Fixed path to upload directory on edit

* Added company image upport to transformers, controllers

* Added image support for categories

* Added support for images in Departments

* Added support for image in Consumables

* Added image support for components
2017-10-25 22:35:58 -07:00

64 lines
2.2 KiB
PHP

<?php
namespace App\Http\Transformers;
use App\Models\Department;
use Illuminate\Database\Eloquent\Collection;
use Gate;
use App\Helpers\Helper;
class DepartmentsTransformer
{
public function transformDepartments (Collection $departments, $total)
{
$array = array();
foreach ($departments as $department) {
$array[] = self::transformDepartment($department);
}
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
public function transformDepartment (Department $department = null)
{
if ($department) {
$array = [
'id' => (int) $department->id,
'name' => e($department->name),
'image' => ($department->image) ? e(url('/').'/uploads/departments/'.e($department->image)) : null,
'company' => ($department->company) ? [
'id' => (int) $department->company->id,
'name'=> e($department->company->name)
] : null,
'manager' => ($department->manager) ? [
'id' => (int) $department->manager->id,
'name' => e($department->manager->getFullNameAttribute()),
'first_name'=> e($department->manager->first_name),
'last_name'=> e($department->manager->last_name)
] : null,
'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'] = [
'update' => Gate::allows('update', Department::class) ? true : false,
'delete' => Gate::allows('delete', Department::class) ? true : false,
];
$array += $permissions_array;
return $array;
}
}
}