1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/Presenters/EntityPresenter.php

69 lines
1.5 KiB
PHP
Raw Normal View History

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
class EntityPresenter extends Presenter
{
/**
* @return string
*/
2016-05-23 11:26:08 +02:00
public function url()
{
2017-06-04 17:14:53 +02:00
return SITE_URL . $this->path();
}
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;
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';
}
public function statusLabel($label = false)
2016-10-18 16:55:07 +02:00
{
$class = $text = '';
if ($this->entity->is_deleted) {
$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();
$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
}
/**
* @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
}