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;
|
2017-09-12 12:43:59 +02:00
|
|
|
use stdClass;
|
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
|
|
|
}
|
|
|
|
|
2017-09-13 13:40:07 +02:00
|
|
|
public function statusColor()
|
|
|
|
{
|
|
|
|
$class = $this->entity->statusClass();
|
|
|
|
|
|
|
|
switch ($class) {
|
|
|
|
case 'success':
|
|
|
|
return '#5cb85c';
|
|
|
|
case 'warning':
|
|
|
|
return '#f0ad4e';
|
|
|
|
case 'primary':
|
|
|
|
return '#337ab7';
|
|
|
|
case 'info':
|
|
|
|
return '#5bc0de';
|
|
|
|
default:
|
|
|
|
return '#777';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2018-01-25 10:26:53 +01:00
|
|
|
return sprintf('%s: %s', trans('texts.' . $entityType), $entity->getDisplayName());
|
2016-08-31 21:10:41 +02:00
|
|
|
}
|
2017-09-12 12:43:59 +02:00
|
|
|
|
2017-09-12 23:20:18 +02:00
|
|
|
public function calendarEvent($subColors = false)
|
2017-09-12 12:43:59 +02:00
|
|
|
{
|
|
|
|
$entity = $this->entity;
|
|
|
|
|
|
|
|
$data = new stdClass();
|
|
|
|
$data->id = $entity->getEntityType() . ':' . $entity->public_id;
|
|
|
|
$data->allDay = true;
|
|
|
|
$data->url = $this->url();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2016-05-23 11:26:08 +02:00
|
|
|
}
|