3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 11:15:42 +00:00
Files
snipe-it/app/Presenters/DepartmentPresenter.php
2026-07-20 14:58:19 +01:00

178 lines
6.2 KiB
PHP

<?php
namespace App\Presenters;
/**
* Class DepartmentPresenter
*/
class DepartmentPresenter extends Presenter
{
/**
* Json Column Layout for bootstrap table
*
* @return string
*/
public static function dataTableLayout()
{
$layout = [
[
'field' => 'checkbox',
'scope' => 'col',
'checkbox' => true,
'formatter' => 'checkboxEnabledFormatter',
'titleTooltip' => trans('general.select_all_none'),
'printIgnore' => true,
'class' => 'hidden-print',
], [
'field' => 'id',
'scope' => 'col',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.id'),
'visible' => false,
], [
'field' => 'name',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'switchable' => false,
'title' => trans('general.name'),
'visible' => true,
'formatter' => 'departmentsLinkFormatter',
], [
'field' => 'company',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.company'),
'visible' => false,
'formatter' => 'companiesLinkObjFormatter',
], [
'field' => 'image',
'scope' => 'col',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.image'),
'visible' => true,
'formatter' => 'imageFormatter',
], [
'field' => 'manager',
'scope' => 'col',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/departments/table.manager'),
'visible' => true,
'formatter' => 'usersLinkObjFormatter',
], [
'field' => 'location',
'scope' => 'col',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.location'),
'visible' => true,
'formatter' => 'locationsLinkObjFormatter',
], [
'field' => 'users_count',
'scope' => 'col',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.people'),
'titleTooltip' => trans('general.people'),
'visible' => true,
'class' => 'css-house-user',
], [
'field' => 'tag_color',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.tag_color'),
'visible' => false,
'formatter' => 'colorTagFormatter',
], [
'field' => 'notes',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'visible' => false,
'title' => trans('general.notes'),
], [
'field' => 'created_at',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
],
[
'field' => 'created_by',
'scope' => 'col',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_by'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
], [
'field' => 'actions',
'scope' => 'col',
'searchable' => false,
'sortable' => false,
'switchable' => false,
'title' => trans('table.actions'),
'visible' => true,
'formatter' => 'departmentsActionsFormatter',
'printIgnore' => true,
'class' => 'hidden-print',
],
];
return json_encode($layout);
}
/**
* Url to view this item.
*
* @return string
*/
public function viewUrl()
{
if (auth()->user()->can('view', ['\App\Models\Department', $this])) {
return '<a href="'.route('departments.show', $this->id).'">'.e($this->display_name).'</a>';
}
// Escape the fallback too. Current callers pipe this into Slack/webhook
// payloads where XSS does not apply, but a future caller rendering it
// into a Blade {!! !!} context would reintroduce the same class of bug
// fixed in formattedNameLink (FD-56438).
return e($this->display_name);
}
public function formattedNameLink()
{
if (auth()->user()->can('view', ['\App\Models\Department', $this])) {
return ($this->tag_color ? "<i class='fa-solid fa-fw fa-square' style='color: ".e($this->tag_color)."' aria-hidden='true'></i>" : '').'<a href="'.route('departments.show', e($this->id)).'">'.e($this->name).'</a>';
}
return ($this->tag_color ? "<i class='fa-solid fa-fw fa-square' style='color: ".e($this->tag_color)."' aria-hidden='true'></i>" : '').e($this->name);
}
public function nameUrl()
{
if (auth()->user()->can('view', ['\App\Models\Department', $this])) {
return '<a href="'.route('departments.show', $this->id).'">'.e($this->display_name).'</a>';
} else {
return e($this->display_name);
}
}
}