2017-05-31 06:52:37 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Supplier;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Gate;
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
|
|
|
|
class SuppliersTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformSuppliers (Collection $suppliers, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($suppliers as $supplier) {
|
|
|
|
$array[] = self::transformSupplier($supplier);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformSupplier (Supplier $supplier = null)
|
|
|
|
{
|
|
|
|
if ($supplier) {
|
|
|
|
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $supplier->id,
|
2017-05-31 06:52:37 -07:00
|
|
|
'name' => e($supplier->name),
|
|
|
|
'address' => ($supplier->address) ? e($supplier->address) : null,
|
|
|
|
'address2' => ($supplier->address2) ? e($supplier->address2) : null,
|
|
|
|
'city' => ($supplier->city) ? e($supplier->city) : null,
|
|
|
|
'state' => ($supplier->state) ? e($supplier->state) : null,
|
2017-07-25 23:40:30 -07:00
|
|
|
'country' => ($supplier->country) ? e($supplier->country) : null,
|
2017-08-22 14:18:21 -07:00
|
|
|
'zip' => ($supplier->zip) ? e($supplier->zip) : null,
|
2017-07-25 23:40:30 -07:00
|
|
|
'fax' => ($supplier->fax) ? e($supplier->fax) : null,
|
2017-05-31 06:52:37 -07:00
|
|
|
'phone' => ($supplier->phone) ? e($supplier->phone) : null,
|
|
|
|
'email' => ($supplier->email) ? e($supplier->email) : null,
|
|
|
|
'contact' => ($supplier->contact) ? e($supplier->contact) : null,
|
2017-07-25 23:40:30 -07:00
|
|
|
'assets_count' => (int) $supplier->assets_count,
|
|
|
|
'licenses_count' => (int) $supplier->licenses_count,
|
2017-07-29 15:46:10 -07:00
|
|
|
'image' => ($supplier->image) ? e($supplier->image) : null,
|
2017-08-22 14:18:21 -07:00
|
|
|
'notes' => ($supplier->notes) ? e($supplier->notes) : null,
|
2017-05-31 06:52:37 -07:00
|
|
|
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
|
|
|
'update' => Gate::allows('update', Supplier::class) ? true : false,
|
|
|
|
'delete' => Gate::allows('delete', Supplier::class) ? true : false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|