2016-12-23 17:52:00 -08:00
|
|
|
<?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;
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
// Convenience functions for datatables stuff
|
|
|
|
public function categoryUrl()
|
|
|
|
{
|
|
|
|
$model = $this->model;
|
|
|
|
// Category of Asset belongs to model.
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($model->model) {
|
2016-12-23 19:23:07 -08:00
|
|
|
$model = $this->model->model;
|
|
|
|
}
|
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($model->category) {
|
2016-12-23 19:23:07 -08:00
|
|
|
return $model->category->present()->nameUrl();
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function locationUrl()
|
|
|
|
{
|
|
|
|
if ($this->model->location) {
|
|
|
|
return $this->model->location->present()->nameUrl();
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function companyUrl()
|
|
|
|
{
|
|
|
|
if ($this->model->company) {
|
|
|
|
return $this->model->company->present()->nameUrl();
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
return '';
|
2016-12-29 14:02:18 -08:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
public function manufacturerUrl()
|
|
|
|
{
|
|
|
|
$model = $this->model;
|
|
|
|
// Category of Asset belongs to model.
|
2016-12-29 14:02:18 -08:00
|
|
|
if ($model->model) {
|
2016-12-23 19:23:07 -08:00
|
|
|
$model = $this->model->model;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($model->manufacturer) {
|
|
|
|
return $model->manufacturer->present()->nameUrl();
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-23 19:23:07 -08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-09-06 16:24:43 -07:00
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->model->name;
|
|
|
|
}
|
|
|
|
|
2016-12-23 17:52:00 -08:00
|
|
|
public function __get($property)
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
if (method_exists($this, $property)) {
|
2016-12-23 17:52:00 -08:00
|
|
|
return $this->{$property}();
|
|
|
|
}
|
|
|
|
|
|
|
|
return e($this->model->{$property});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __call($method, $args)
|
|
|
|
{
|
|
|
|
return $this->model->$method($args);
|
|
|
|
}
|
|
|
|
}
|