mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
02c1a45025
* Add presenters for models. Move bootstrap table JSON generation to these presenters, which cleans up controllers a lot. Move view specific modifications from the models to the presenters as well. * Fix some issues found by travis and codacy * Fix a few more issues found while testing. * Attempt another acceptance test fix * Try something else * Maybe.. * Move conditionals out of the datatable method and into dedicated url methods.
84 lines
1.7 KiB
PHP
84 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Presenters;
|
|
|
|
|
|
use App\Models\SnipeModel;
|
|
|
|
abstract class Presenter
|
|
{
|
|
|
|
/**
|
|
* @var SnipeModel
|
|
*/
|
|
protected $model;
|
|
|
|
/**
|
|
* Presenter constructor.
|
|
* @param SnipeModel $model
|
|
*/
|
|
public function __construct(SnipeModel $model)
|
|
{
|
|
$this->model = $model;
|
|
}
|
|
|
|
// Convenience functions for datatables stuff
|
|
public function categoryUrl()
|
|
{
|
|
$model = $this->model;
|
|
// Category of Asset belongs to model.
|
|
if($model->model) {
|
|
$model = $this->model->model;
|
|
}
|
|
|
|
if($model->category) {
|
|
return $model->category->present()->nameUrl();
|
|
}
|
|
return '';
|
|
}
|
|
|
|
public function locationUrl()
|
|
{
|
|
if ($this->model->location) {
|
|
return $this->model->location->present()->nameUrl();
|
|
}
|
|
return '';
|
|
}
|
|
|
|
public function companyUrl()
|
|
{
|
|
if ($this->model->company) {
|
|
return $this->model->company->present()->nameUrl();
|
|
}
|
|
return '';
|
|
}
|
|
public function manufacturerUrl()
|
|
{
|
|
$model = $this->model;
|
|
// Category of Asset belongs to model.
|
|
if($model->model) {
|
|
$model = $this->model->model;
|
|
}
|
|
|
|
if ($model->manufacturer) {
|
|
return $model->manufacturer->present()->nameUrl();
|
|
}
|
|
return '';
|
|
}
|
|
|
|
public function __get($property)
|
|
{
|
|
if( method_exists($this, $property)) {
|
|
return $this->{$property}();
|
|
}
|
|
|
|
return e($this->model->{$property});
|
|
}
|
|
|
|
public function __call($method, $args)
|
|
{
|
|
return $this->model->$method($args);
|
|
}
|
|
|
|
}
|