mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-22 19:21:58 -08:00
gives a better example with custom fields in label preview
This commit is contained in:
parent
5cbcac28b1
commit
250b0a7afb
|
@ -6,7 +6,6 @@ use App\Models\Asset;
|
|||
use App\Models\AssetModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\CustomFieldset;
|
||||
use App\Models\Labels\Label;
|
||||
use App\Models\Location;
|
||||
use App\Models\Manufacturer;
|
||||
|
@ -27,63 +26,59 @@ class LabelsController extends Controller
|
|||
*/
|
||||
public function show(string $labelName)
|
||||
{
|
||||
$setting = Setting::getSettings();
|
||||
//This part allows for the custom selection label preview
|
||||
$data = explode(';', Setting::getSettings()->label2_fields);
|
||||
$fields = str_replace('=', ' ', $data);
|
||||
$data = array_map(function($element) {
|
||||
$a = explode('=', $element);
|
||||
return [$a[0] => $a[1]];
|
||||
}, $data);
|
||||
|
||||
$custom_fields= [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
|
||||
$parts = explode('_', $field, 2);
|
||||
|
||||
$key = trim($parts[0]);
|
||||
$value = trim($parts[1]);
|
||||
|
||||
$custom_fields["_".$value] = $key ;
|
||||
}
|
||||
// dd($custom_fields);
|
||||
$labelName = str_replace('/', '\\', $labelName);
|
||||
$template = Label::find($labelName);
|
||||
|
||||
$exampleAsset = new Asset();
|
||||
if($setting->label2_enable && ($setting->label2_template != 'DefaultLabel')) {
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
foreach($custom_fields as $key => $value){
|
||||
$exampleAsset->{$key} = "{{$value}}" ;
|
||||
foreach($data as $innerArray){
|
||||
foreach($innerArray as $key => $value) {
|
||||
$exampleAsset->{$value} = "{{$key}}";
|
||||
}
|
||||
}
|
||||
|
||||
$settings = Setting::getSettings();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts/default')
|
||||
@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
|
|
Loading…
Reference in a new issue