mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-30 07:59:50 -08:00
934afa036f
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
91 lines
1.7 KiB
PHP
91 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);
|
|
}
|
|
}
|