From bee016e0be2bf033eeeca0e16ff8fc512fea1988 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 21 Feb 2024 09:31:01 -0800 Subject: [PATCH] keeps example values in the example preview, fixes indent --- app/Http/Controllers/LabelsController.php | 71 ++++++++++++----------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index 7ea6843d4f..07d14dbbc7 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -6,6 +6,7 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; use App\Models\Company; +use App\Models\CustomField; use App\Models\Labels\Label; use App\Models\Location; use App\Models\Manufacturer; @@ -29,47 +30,51 @@ class LabelsController extends Controller $labelName = str_replace('/', '\\', $labelName); $template = Label::find($labelName); - $exampleAsset = new Asset(); + $exampleAsset = new Asset(); - $exampleAsset->id = 999999; - $exampleAsset->name = 'JEN-867-5309'; - $exampleAsset->asset_tag = '100001'; - $exampleAsset->serial = 'SN9876543210'; - $exampleAsset->asset_eol_date = '2025-01-01'; - $exampleAsset->order_number = '12345'; - $exampleAsset->purchase_date = '2023-01-01'; - $exampleAsset->status_id = 1; + $exampleAsset->id = 999999; + $exampleAsset->name = 'JEN-867-5309'; + $exampleAsset->asset_tag = '100001'; + $exampleAsset->serial = 'SN9876543210'; + $exampleAsset->asset_eol_date = '2025-01-01'; + $exampleAsset->order_number = '12345'; + $exampleAsset->purchase_date = '2023-01-01'; + $exampleAsset->status_id = 1; - $exampleAsset->company = new Company([ - 'name' => trans('admin/labels/table.example_company'), - 'phone' => '1-555-555-5555', - 'email' => 'company@example.com', - ]); + $exampleAsset->company = new Company([ + 'name' => trans('admin/labels/table.example_company'), + 'phone' => '1-555-555-5555', + 'email' => 'company@example.com', + ]); - $exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker'])); - $exampleAsset->defaultLoc = new Location(['name' => trans('admin/labels/table.example_defaultloc'), 'phone' => '1-555-555-5555']); - $exampleAsset->location = new Location(['name' => trans('admin/labels/table.example_location'), 'phone' => '1-555-555-5555']); + $exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker'])); + $exampleAsset->defaultLoc = new Location(['name' => trans('admin/labels/table.example_defaultloc'), 'phone' => '1-555-555-5555']); + $exampleAsset->location = new Location(['name' => trans('admin/labels/table.example_location'), 'phone' => '1-555-555-5555']); - $exampleAsset->model = new AssetModel(); - $exampleAsset->model->id = 999999; - $exampleAsset->model->name = trans('admin/labels/table.example_model'); - $exampleAsset->model->model_number = 'MDL5678'; - $exampleAsset->model->manufacturer = new Manufacturer(); - $exampleAsset->model->manufacturer->id = 999999; - $exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer'); - $exampleAsset->model->manufacturer->support_email = 'support@test.com'; - $exampleAsset->model->manufacturer->support_phone = '1-555-555-5555'; - $exampleAsset->model->manufacturer->support_url = 'https://example.com'; - $exampleAsset->supplier = new Supplier(['name' => trans('admin/labels/table.example_company')]); - $exampleAsset->model->category = new Category(); - $exampleAsset->model->category->id = 999999; - $exampleAsset->model->category->name = trans('admin/labels/table.example_category'); + $exampleAsset->model = new AssetModel(); + $exampleAsset->model->id = 999999; + $exampleAsset->model->name = trans('admin/labels/table.example_model'); + $exampleAsset->model->model_number = 'MDL5678'; + $exampleAsset->model->manufacturer = new Manufacturer(); + $exampleAsset->model->manufacturer->id = 999999; + $exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer'); + $exampleAsset->model->manufacturer->support_email = 'support@test.com'; + $exampleAsset->model->manufacturer->support_phone = '1-555-555-5555'; + $exampleAsset->model->manufacturer->support_url = 'https://example.com'; + $exampleAsset->supplier = new Supplier(['name' => trans('admin/labels/table.example_company')]); + $exampleAsset->model->category = new Category(); + $exampleAsset->model->category->id = 999999; + $exampleAsset->model->category->name = trans('admin/labels/table.example_category'); + + $customFieldColumns = CustomField::all()->pluck('db_column'); collect(explode(';', Setting::getSettings()->label2_fields)) - ->each(function ($item) use ($exampleAsset){ + ->each(function ($item) use ($customFieldColumns, $exampleAsset) { $pair = explode('=', $item); - $exampleAsset->{$pair[1]} = "{{$pair[0]}}"; + if ($customFieldColumns->contains($pair[1])) { + $exampleAsset->{$pair[1]} = "{{$pair[0]}}"; + } }); $settings = Setting::getSettings();