![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/rentpix.corals.io/Corals/modules/RentPix/Transformers/ |
<?php namespace Corals\Modules\RentPix\Transformers; use Corals\Foundation\Facades\Hashids; use Corals\Foundation\Transformers\BaseTransformer; use Corals\Modules\RentPix\Models\Inspection; use Illuminate\Support\Facades\URL; class InspectionTransformer extends BaseTransformer { public function __construct($extras = []) { $this->resource_url = config('rentPix.models.inspection.resource_url'); parent::__construct($extras); } /** * @param Inspection $inspection * @return array * * @throws \Throwable */ public function transform(Inspection $inspection) { $statusLevels = [ 'open' => 'primary', 'completed' => 'success', ]; $status = $inspection->status->value; $typeLevels = [ 'start' => 'warning', 'update' => 'info', 'end' => 'danger', ]; $type = $inspection->type->value; $reservation = $inspection->reservation ? $inspection->reservation->presenter() : null; $count_photos = $inspection->media->whereNull('driver_id')->count(); $transformedArray = [ 'id' => $inspection->id, 'code_without_link' => $inspection->code, 'code' => HtmlElement('a', [ 'href' => URL::signedRoute('inspection-details', ['inspection' => Hashids::encode($inspection->id)]), 'target' => '_blank', ], sprintf('%s %s', $inspection->code, '<i class="fa fa-external-link" aria-hidden="true"></i>') ), 'photos_only' => HtmlElement('a', [ 'href' => URL::signedRoute('inspection-photos', ['inspection' => Hashids::encode($inspection->id)]), 'target' => '_blank' ], '<i class="fa fa-picture-o p-r-10" aria-hidden="true"></i>' . $count_photos), 'type' => formatStatusAsLabels($type, [ 'level' => $typeLevels[$type], 'text' => trans('RentPix::attributes.inspection.type_options.' . $type), ]), 'status' => formatStatusAsLabels($status, [ 'level' => $statusLevels[$status], 'text' => trans('RentPix::attributes.inspection.status_options.' . $status), ]), 'user' => optional($inspection->user)->present('full_name') ?? '-', 'reservation' => data_get($reservation, 'code') ?? '-', 'unit' => data_get($reservation, 'unit') ?? '-', 'customer' => data_get($reservation, 'customer') ?? '-', 'inspected_at' => format_date_time($inspection->inspected_at), 'created_at' => format_date_time($inspection->created_at), 'updated_at' => format_date_time($inspection->updated_at), 'action' => $this->actions($inspection), ]; return parent::transformResponse($transformedArray); } }