2016-12-23 17:52:00 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Presenters;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AssetModelPresenter
|
|
|
|
*/
|
|
|
|
class AssetModelPresenter extends Presenter
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public static function dataTableLayout()
|
|
|
|
{
|
2021-01-27 17:44:05 -08:00
|
|
|
$layout = [
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'checkbox',
|
|
|
|
'checkbox' => true,
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'id',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.id'),
|
|
|
|
'visible' => false,
|
2021-01-27 17:44:05 -08:00
|
|
|
], [
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'company',
|
|
|
|
'searchable' => true,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('admin/companies/table.title'),
|
|
|
|
'visible' => false,
|
|
|
|
'formatter' => 'companiesLinkObjFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
], [
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'name',
|
|
|
|
'searchable' => true,
|
|
|
|
'sortable' => true,
|
|
|
|
'visible' => true,
|
|
|
|
'title' => trans('general.name'),
|
|
|
|
'formatter' => 'modelsLinkFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'image',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.image'),
|
|
|
|
'visible' => true,
|
|
|
|
'formatter' => 'imageFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'manufacturer',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.manufacturer'),
|
|
|
|
'visible' => false,
|
|
|
|
'formatter' => 'manufacturersLinkObjFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'model_number',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('admin/models/table.modelnumber'),
|
|
|
|
'visible' => true,
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'assets_count',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('admin/models/table.numassets'),
|
|
|
|
'visible' => true,
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'depreciation',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.depreciation'),
|
|
|
|
'visible' => false,
|
|
|
|
'formatter' => 'depreciationsLinkObjFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'category',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.category'),
|
|
|
|
'visible' => false,
|
|
|
|
'formatter' => 'categoriesLinkObjFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'eol',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.eol'),
|
|
|
|
'visible' => true,
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'fieldset',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('admin/models/general.fieldset'),
|
|
|
|
'visible' => true,
|
|
|
|
'formatter' => 'fieldsetsLinkObjFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'notes',
|
|
|
|
'searchable' => true,
|
|
|
|
'sortable' => true,
|
|
|
|
'switchable' => true,
|
|
|
|
'title' => trans('general.notes'),
|
|
|
|
'visible' => false,
|
2021-01-27 17:44:05 -08:00
|
|
|
],
|
2021-03-30 08:57:20 -07:00
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'created_at',
|
|
|
|
'searchable' => true,
|
|
|
|
'sortable' => true,
|
|
|
|
'visible' => false,
|
|
|
|
'title' => trans('general.created_at'),
|
|
|
|
'formatter' => 'dateDisplayFormatter',
|
2021-03-30 08:57:20 -07:00
|
|
|
],
|
|
|
|
[
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'updated_at',
|
|
|
|
'searchable' => true,
|
|
|
|
'sortable' => true,
|
|
|
|
'visible' => false,
|
|
|
|
'title' => trans('general.updated_at'),
|
|
|
|
'formatter' => 'dateDisplayFormatter',
|
2021-03-30 08:57:20 -07:00
|
|
|
],
|
|
|
|
|
2021-01-27 17:44:05 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$layout[] = [
|
2021-06-10 13:15:52 -07:00
|
|
|
'field' => 'actions',
|
|
|
|
'searchable' => false,
|
|
|
|
'sortable' => false,
|
|
|
|
'switchable' => false,
|
|
|
|
'title' => trans('table.actions'),
|
|
|
|
'formatter' => 'modelsActionsFormatter',
|
2021-01-27 17:44:05 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
return json_encode($layout);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Formatted note for this model
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function note()
|
|
|
|
{
|
|
|
|
$Parsedown = new \Parsedown();
|
|
|
|
|
|
|
|
if ($this->model->note) {
|
|
|
|
return $Parsedown->text($this->model->note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
public function eolText()
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($this->eol) {
|
2016-12-23 19:23:07 -08:00
|
|
|
return $this->eol.' '.trans('general.months');
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
/**
|
|
|
|
* Pretty name for this model
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function modelName()
|
|
|
|
{
|
2017-10-26 21:50:39 -07:00
|
|
|
$name = '';
|
|
|
|
if ($this->model->manufacturer) {
|
2017-12-20 12:32:55 -08:00
|
|
|
$name .= $this->model->manufacturer->name.' ';
|
2017-10-26 21:50:39 -07:00
|
|
|
}
|
|
|
|
$name .= $this->name;
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
if ($this->model_number) {
|
2021-06-10 13:15:52 -07:00
|
|
|
$name .= ' (#'.$this->model_number.')';
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard url for use to view page.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function nameUrl()
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
return (string) link_to_route('models.show', $this->name, $this->id);
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate img tag to this models image.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function imageUrl()
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
if (! empty($this->image)) {
|
|
|
|
return '<img src="'.url('/').'/uploads/models/'.$this->image.'" alt="'.$this->name.'" height="50" width="50">';
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
return '';
|
|
|
|
}
|
2016-12-26 15:19:04 -08:00
|
|
|
|
2017-11-02 04:15:09 -07:00
|
|
|
/**
|
|
|
|
* Generate img tag to this models image.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function imageSrc()
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
if (! empty($this->image)) {
|
|
|
|
return url('/').'/uploads/models/'.$this->image;
|
2017-11-02 04:15:09 -07:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-11-02 04:15:09 -07:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:19:04 -08:00
|
|
|
/**
|
|
|
|
* Url to view this item.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function viewUrl()
|
|
|
|
{
|
|
|
|
return route('models.show', $this->id);
|
|
|
|
}
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|