mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
934afa036f
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Supplier;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class SuppliersTransformer
|
|
{
|
|
public function transformSuppliers(Collection $suppliers, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($suppliers as $supplier) {
|
|
$array[] = self::transformSupplier($supplier);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformSupplier(Supplier $supplier = null)
|
|
{
|
|
if ($supplier) {
|
|
$array = [
|
|
'id' => (int) $supplier->id,
|
|
'name' => e($supplier->name),
|
|
'image' => ($supplier->image) ? Storage::disk('public')->url('suppliers/'.e($supplier->image)) : null,
|
|
'url' => e($supplier->url),
|
|
'address' => e($supplier->address),
|
|
'address2' => e($supplier->address2),
|
|
'city' => e($supplier->city),
|
|
'state' => e($supplier->state),
|
|
'country' => e($supplier->country),
|
|
'zip' => e($supplier->zip),
|
|
'fax' => e($supplier->fax),
|
|
'phone' => e($supplier->phone),
|
|
'email' => e($supplier->email),
|
|
'contact' => e($supplier->contact),
|
|
'assets_count' => (int) $supplier->assets_count,
|
|
'accessories_count' => (int) $supplier->accessories_count,
|
|
'licenses_count' => (int) $supplier->licenses_count,
|
|
'notes' => ($supplier->notes) ? e($supplier->notes) : null,
|
|
'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),
|
|
'delete' => (Gate::allows('delete', Supplier::class) && ($supplier->assets_count == 0) && ($supplier->licenses_count == 0) && ($supplier->accessories_count == 0)),
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
}
|
|
}
|