mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Added accessory transformer to assets transformer
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
021c4f2598
commit
51b426f0b4
|
@ -3,12 +3,14 @@
|
||||||
namespace App\Http\Transformers;
|
namespace App\Http\Transformers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
use App\Models\Accessory;
|
||||||
|
use App\Models\AccessoryCheckout;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class AssetsTransformer
|
class AssetsTransformer
|
||||||
{
|
{
|
||||||
|
@ -285,4 +287,44 @@ class AssetsTransformer
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transformCheckedoutAccessories($accessory_checkouts, $total)
|
||||||
|
{
|
||||||
|
|
||||||
|
$array = [];
|
||||||
|
foreach ($accessory_checkouts as $checkout) {
|
||||||
|
$array[] = self::transformCheckedoutAccessory($checkout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function transformCheckedoutAccessory(AccessoryCheckout $accessory_checkout)
|
||||||
|
{
|
||||||
|
|
||||||
|
$array = [
|
||||||
|
'id' => $accessory_checkout->id,
|
||||||
|
'accessory' => [
|
||||||
|
'id' => $accessory_checkout->accessory->id,
|
||||||
|
'name' => $accessory_checkout->accessory->name,
|
||||||
|
],
|
||||||
|
'image' => ($accessory_checkout->accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory_checkout->accessory->image)) : null,
|
||||||
|
'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
|
||||||
|
'created_by' => $accessory_checkout->adminuser ? [
|
||||||
|
'id' => (int) $accessory_checkout->adminuser->id,
|
||||||
|
'name'=> e($accessory_checkout->adminuser->present()->fullName),
|
||||||
|
]: null,
|
||||||
|
'created_at' => Helper::getFormattedDateObject($accessory_checkout->created_at, 'datetime'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions_array['available_actions'] = [
|
||||||
|
'checkout' => false,
|
||||||
|
'checkin' => Gate::allows('checkin', Accessory::class),
|
||||||
|
];
|
||||||
|
|
||||||
|
$array += $permissions_array;
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue