Files
snipe-it/app/Presenters/CategoryPresenter.php
2026-03-10 13:06:46 -07:00

176 lines
6.4 KiB
PHP

<?php
namespace App\Presenters;
/**
* Class CategoryPresenter
*/
class CategoryPresenter extends Presenter
{
/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableLayout()
{
$layout = [
[
'field' => 'checkbox',
'checkbox' => true,
'titleTooltip' => trans('general.select_all_none'),
'printIgnore' => true,
'class' => 'hidden-print',
],
[
'field' => 'id',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.id'),
'visible' => false,
], [
'field' => 'name',
'searchable' => true,
'sortable' => true,
'switchable' => false,
'title' => trans('general.name'),
'visible' => true,
'formatter' => 'categoriesLinkFormatter',
], [
'field' => 'image',
'searchable' => false,
'sortable' => true,
'title' => trans('general.image'),
'visible' => true,
'formatter' => 'imageFormatter',
], [
'field' => 'category_type',
'searchable' => true,
'sortable' => true,
'title' => trans('general.type'),
'visible' => true,
], [
'field' => 'item_count',
'searchable' => false,
'sortable' => true,
'title' => trans('general.qty'),
'visible' => true,
], [
'field' => 'has_eula',
'searchable' => false,
'sortable' => false,
'title' => trans('admin/categories/table.eula_text'),
'visible' => false,
'formatter' => 'trueFalseFormatter',
], [
'field' => 'checkin_email',
'searchable' => false,
'sortable' => true,
'class' => 'css-envelope',
'title' => 'Send Email',
'visible' => true,
'formatter' => 'trueFalseFormatter',
], [
'field' => 'require_acceptance',
'searchable' => false,
'sortable' => true,
'title' => trans('admin/categories/table.require_acceptance'),
'visible' => true,
'formatter' => 'trueFalseFormatter',
], [
"field" => "use_default_eula",
"searchable" => false,
"sortable" => true,
"title" => trans('admin/categories/general.use_default_eula_column'),
'visible' => true,
"formatter" => 'trueFalseFormatter',
], [
'field' => 'tag_color',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.tag_color'),
'visible' => false,
'formatter' => 'colorTagFormatter',
], [
'field' => 'notes',
'searchable' => true,
'sortable' => true,
'visible' => false,
'title' => trans('general.notes'),
], [
'field' => 'created_by',
'searchable' => false,
'sortable' => true,
'title' => trans('general.created_by'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
], [
'field' => 'created_at',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
], [
'field' => 'updated_at',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.updated_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
], [
'field' => 'actions',
'searchable' => false,
'sortable' => false,
'switchable' => false,
'title' => trans('table.actions'),
'formatter' => 'categoriesActionsFormatter',
'printIgnore' => true,
'class' => 'hidden-print',
],
];
return json_encode($layout);
}
/**
* Link to this categories name
* @return string
*/
public function nameUrl()
{
if (auth()->user()->can('view', ['\App\Models\Category', $this])) {
return '<a href="' . route('categories.show', $this->id) . '">' . e($this->display_name) . '</a>';
} else {
return e($this->display_name);
}
}
/**
* Url to view this item.
* @return string
*/
public function viewUrl()
{
return route('categories.show', $this->id);
}
public function formattedNameLink() {
// We use soft-deletes for categories, but we don't give you a way to restore them right now. This would be the method we'd use when that happens
// if (auth()->user()->can('view', ['\App\Models\Category', $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('models.show', e($this->id)).'" class="'. (($this->deleted_at!='') ? 'deleted' : '').'">'.e($this->display_name).'</a>';
// }
if ((auth()->user()->can('view', ['\App\Models\Category', $this])) && ($this->deleted_at=='')) {
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('categories.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>" : '').'<span class="'. (($this->deleted_at!='') ? 'deleted' : '').'">'.e($this->display_name).'</span>';
}
}