snipe-it/app/Presenters/Presenter.php
Daniel Meltzer ae0573b3da Fix asset create (#3929)
* Fix accidental commit of ImporterTest.

* Move the name() method to the presenter

This fixes some weird collisions between laravels voodoo and our
presenter voodoo that confused php.  It's also probably a cleaner place
to put it.  Should fix #3927

* Add missing parenthesis

* Add heading to tables on locations/view page.
2017-09-06 16:24:43 -07:00

87 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 name()
{
return $this->model->name;
}
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);
}
}