Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that there is a company before trying to get name property #13473

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions app/View/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function render(callable $callback = null)
$assets = $this->data->get('assets');
$offset = $this->data->get('offset');
$template = $this->data->get('template');

// If disabled, pass to legacy view
if ((!$settings->label2_enable) && (!$template)) {
return view('hardware/labels')
Expand All @@ -49,8 +49,12 @@ public function render(callable $callback = null)
->with('count', $this->data->get('count'));
}

if (empty($template)) $template = LabelModel::find($settings->label2_template);
elseif (is_string($template)) $template = LabelModel::find($template);
// If a specific template was set, use it, otherwise fall back to default
if (empty($template)) {
$template = LabelModel::find($settings->label2_template);
} elseif (is_string($template)) {
$template = LabelModel::find($template);
}

$template->validate();

Expand Down Expand Up @@ -87,25 +91,36 @@ public function render(callable $callback = null)
$assetData->put('tag', $asset->asset_tag);

if ($template->getSupportTitle()) {
$title = !empty($settings->label2_title) ?
str_ireplace('{COMPANY}', $asset->company->name, $settings->label2_title) :

if ($asset->company && !empty($settings->label2_title)) {
$title = str_replace('{COMPANY}', $asset->company->name, $settings->label2_title);
$settings->qr_text;
if (!empty($title)) $assetData->put('title', $title);
$assetData->put('title', $title);
}
}

if ($template->getSupportLogo()) {
$logo = $settings->label2_asset_logo ?
(
!empty($asset->company->image) ?
Storage::disk('public')->path('companies/'.e($asset->company->image)) :
null
) :
(
!empty($settings->label_logo) ?
Storage::disk('public')->path(''.e($settings->label_logo)) :
null
);
if (!empty($logo)) $assetData->put('logo', $logo);

$logo = null;

// Should we be trying to use a logo at all?
if ($settings->label2_asset_logo='1') {

// If we don't have a company image, fall back to the general site label image
if (!empty($settings->label_logo)) {
$logo = Storage::disk('public')->path('/'.e($settings->label_logo));
}

// If we have a company logo, use that first
if (($asset->company) && ($asset->company->image!='')) {
$logo = Storage::disk('public')->path('companies/'.e($asset->company->image));
}

}

if (!empty($logo)) {
$assetData->put('logo', $logo);
}
}

if ($template->getSupport1DBarcode()) {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/settings/labels.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class="table table-striped snipe-table"

<label class="form-control">
<input type="checkbox" value="1" name="label2_asset_logo"{{ ((old('label2_asset_logo') == '1') || ($setting->label2_asset_logo) == '1') ? ' checked="checked"' : '' }} aria-label="label2_asset_logo">
{{ trans('general.yes') }}
{{ Form::label('label2_asset_logo', trans('admin/settings/general.label2_asset_logo')) }}
</label>
<p class="help-block">
{!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.label_logo')]) !!}
Expand Down