2017-01-12 23:40:35 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-01-13 04:50:20 -08:00
|
|
|
use phpDocumentor\Reflection\Types\Integer;
|
2017-01-12 23:40:35 -08:00
|
|
|
|
|
|
|
class UsersTransformer
|
|
|
|
{
|
|
|
|
|
2017-01-13 04:50:20 -08:00
|
|
|
public function transformUsers (Collection $users, $total)
|
2017-01-12 23:40:35 -08:00
|
|
|
{
|
2017-01-13 04:50:20 -08:00
|
|
|
$array = array();
|
2017-01-12 23:40:35 -08:00
|
|
|
foreach ($users as $user) {
|
2017-01-13 04:50:20 -08:00
|
|
|
$array[] = self::transformUser($user);
|
2017-01-12 23:40:35 -08:00
|
|
|
}
|
2017-01-13 04:50:20 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
2017-01-12 23:40:35 -08:00
|
|
|
}
|
|
|
|
|
2017-01-13 04:50:20 -08:00
|
|
|
public function transformUser (User $user)
|
2017-01-12 23:40:35 -08:00
|
|
|
{
|
2017-01-13 04:50:20 -08:00
|
|
|
$array = [
|
2017-01-12 23:40:35 -08:00
|
|
|
'id' => e($user->id),
|
2017-01-13 00:13:57 -08:00
|
|
|
'name' => e($user->first_name).' '.($user->last_name),
|
|
|
|
'firstname' => e($user->first_name),
|
|
|
|
'lastname' => e($user->last_name),
|
|
|
|
'username' => e($user->username),
|
2017-01-13 04:50:20 -08:00
|
|
|
'employee_num' => e($user->employee_num),
|
|
|
|
'manager' => ($user->manager) ? $user->manager->name : false,
|
2017-01-13 00:13:57 -08:00
|
|
|
'jobtitle' => e($user->jobtitle),
|
|
|
|
'email' => e($user->email),
|
2017-01-12 23:40:35 -08:00
|
|
|
'location' => (new LocationsTransformer)->transformLocation($user->userloc),
|
|
|
|
'permissions' => $user->decodePermissions(),
|
2017-01-13 04:50:20 -08:00
|
|
|
'activated' => ($user->activated =='1') ? true : false,
|
|
|
|
'two_factor_activated' => ($user->activated =='1') ? true : false,
|
2017-01-12 23:40:35 -08:00
|
|
|
'created_at' => $user->created_at,
|
|
|
|
'updated_at' => $user->updated_at,
|
|
|
|
];
|
|
|
|
|
2017-01-13 04:50:20 -08:00
|
|
|
return $array;
|
2017-01-12 23:40:35 -08:00
|
|
|
}
|
|
|
|
|
2017-01-13 00:13:57 -08:00
|
|
|
public function transformUsersDatatable($users) {
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($users);
|
|
|
|
}
|
|
|
|
|
2017-01-12 23:40:35 -08:00
|
|
|
|
|
|
|
|
|
|
|
}
|