invoiceninja/app/Ninja/Presenters/TaskPresenter.php

61 lines
1.3 KiB
PHP
Raw Normal View History

2015-11-12 22:36:28 +02:00
<?php namespace App\Ninja\Presenters;
/**
* Class TaskPresenter
*/
class TaskPresenter extends EntityPresenter
{
/**
* @return string
*/
2015-11-12 22:36:28 +02:00
public function client()
{
return $this->entity->client ? $this->entity->client->getDisplayName() : '';
}
/**
* @return mixed
*/
2015-11-12 22:36:28 +02:00
public function user()
{
return $this->entity->user->getDisplayName();
}
2016-09-18 22:28:37 +03:00
public function description()
{
return substr($this->entity->description, 0, 40) . (strlen($this->entity->description) > 40 ? '...' : '');
}
public function project()
{
return $this->entity->project ? $this->entity->project->name : '';
}
/**
* @param $account
* @return mixed
*/
2015-12-13 22:12:54 +02:00
public function times($account)
{
$parts = json_decode($this->entity->time_log) ?: [];
$times = [];
foreach ($parts as $part) {
$start = $part[0];
if (count($part) == 1 || !$part[1]) {
$end = time();
} else {
$end = $part[1];
}
$start = $account->formatDateTime("@{$start}");
$end = $account->formatTime("@{$end}");
2015-12-31 10:04:12 +02:00
$times[] = "### {$start} - {$end}";
2015-12-13 22:12:54 +02:00
}
return implode("\n", $times);
}
2016-02-04 20:36:39 +02:00
2016-05-23 12:26:08 +03:00
}