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