Refactor presenters

This commit is contained in:
Hillel Coren 2016-12-26 21:43:53 +02:00
parent ffd7e7bdc6
commit 0f37d5f618
6 changed files with 16 additions and 59 deletions

View File

@ -335,4 +335,15 @@ class EntityModel extends Eloquent
return $class::getStatuses($entityType);
}
public function statusClass()
{
return '';
}
public function statusLabel()
{
return '';
}
}

View File

@ -29,15 +29,16 @@ class EntityPresenter extends Presenter
if ($this->entity->is_deleted) {
$class = 'danger';
$text = trans('texts.deleted');
$label = trans('texts.deleted');
} elseif ($this->entity->trashed()) {
$class = 'warning';
$text = trans('texts.archived');
$label = trans('texts.archived');
} else {
return '';
$class = $this->entity->statusClass();
$label = $this->entity->statusLabel();
}
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$text}</span>";
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
}
/**

View File

@ -34,19 +34,4 @@ class ExpensePresenter extends EntityPresenter
return $this->entity->expense_category ? $this->entity->expense_category->name : '';
}
/**
* @return string
*/
public function statusLabel()
{
if ($label = parent::statusLabel()) {
return $label;
}
$class = $this->entity->statusClass();
$label = $this->entity->statusLabel();
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
}
}

View File

@ -90,18 +90,6 @@ class InvoicePresenter extends EntityPresenter {
}
}
public function statusLabel()
{
if ($label = parent::statusLabel()) {
return $label;
}
$class = $this->entity->statusClass();
$label = $this->entity->statusLabel();
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
}
public function invoice_date()
{
return Utils::fromSqlDate($this->entity->invoice_date);

View File

@ -27,16 +27,4 @@ class PaymentPresenter extends EntityPresenter {
return $this->entity->payment_type->name;
}
}
public function statusLabel()
{
if ($label = parent::statusLabel()) {
return $label;
}
$class = $this->entity->statusClass();
$label = $this->entity->statusLabel();
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
}
}

View File

@ -57,20 +57,4 @@ class TaskPresenter extends EntityPresenter
return implode("\n", $times);
}
/**
* @return string
*/
public function statusLabel()
{
if ($label = parent::statusLabel()) {
return $label;
}
$class = $this->entity->statusClass();
$label = $this->entity->statusLabel();
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
}
}