2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Presenters;
|
2016-05-23 11:26:08 +02:00
|
|
|
|
|
|
|
use Laracasts\Presenter\Presenter;
|
2017-01-30 20:40:43 +01:00
|
|
|
use URL;
|
|
|
|
use Utils;
|
2016-05-23 11:26:08 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
class EntityPresenter extends Presenter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-05-23 11:26:08 +02:00
|
|
|
public function url()
|
2017-01-29 21:07:44 +01:00
|
|
|
{
|
2017-06-04 17:14:53 +02:00
|
|
|
return SITE_URL . $this->path();
|
2017-01-29 21:07:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function path()
|
2016-05-23 11:26:08 +02:00
|
|
|
{
|
2016-12-08 21:39:15 +01:00
|
|
|
$type = Utils::pluralizeEntityType($this->entity->getEntityType());
|
2016-05-23 11:26:08 +02:00
|
|
|
$id = $this->entity->public_id;
|
|
|
|
|
2017-01-29 21:07:44 +01:00
|
|
|
return sprintf('/%s/%s', $type, $id);
|
2016-05-23 11:26:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-08 21:39:15 +01:00
|
|
|
public function editUrl()
|
|
|
|
{
|
|
|
|
return $this->url() . '/edit';
|
|
|
|
}
|
|
|
|
|
2017-01-31 13:59:20 +01:00
|
|
|
public function statusLabel($label = false)
|
2016-10-18 16:55:07 +02:00
|
|
|
{
|
|
|
|
$class = $text = '';
|
|
|
|
|
2017-07-20 17:03:05 +02:00
|
|
|
if (! $this->entity->id) {
|
|
|
|
return '';
|
|
|
|
} elseif ($this->entity->is_deleted) {
|
2016-10-18 16:55:07 +02:00
|
|
|
$class = 'danger';
|
2016-12-26 20:43:53 +01:00
|
|
|
$label = trans('texts.deleted');
|
2016-10-18 16:55:07 +02:00
|
|
|
} elseif ($this->entity->trashed()) {
|
|
|
|
$class = 'warning';
|
2016-12-26 20:43:53 +01:00
|
|
|
$label = trans('texts.archived');
|
2016-10-18 16:55:07 +02:00
|
|
|
} else {
|
2016-12-26 20:43:53 +01:00
|
|
|
$class = $this->entity->statusClass();
|
2017-01-31 13:59:20 +01:00
|
|
|
$label = $label ?: $this->entity->statusLabel();
|
2016-10-18 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
2016-12-26 20:43:53 +01:00
|
|
|
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
|
2016-10-18 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-05-23 11:26:08 +02:00
|
|
|
public function link()
|
|
|
|
{
|
|
|
|
$name = $this->entity->getDisplayName();
|
|
|
|
$link = $this->url();
|
|
|
|
|
|
|
|
return link_to($link, $name)->toHtml();
|
|
|
|
}
|
2016-08-31 21:10:41 +02:00
|
|
|
|
|
|
|
public function titledName()
|
|
|
|
{
|
|
|
|
$entity = $this->entity;
|
|
|
|
$entityType = $entity->getEntityType();
|
|
|
|
|
|
|
|
return sprintf('%s: %s', trans('texts.' . $entityType), $entity->getDisplayName());
|
|
|
|
}
|
2016-05-23 11:26:08 +02:00
|
|
|
}
|