2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Ninja\Presenters;
|
2015-11-12 22:36:28 +02:00
|
|
|
|
2017-09-13 00:20:18 +03:00
|
|
|
use Utils;
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 21:40:43 +02:00
|
|
|
* Class TaskPresenter.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
|
|
|
|
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() : '';
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @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 ? '...' : '');
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 20:39:48 +02: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 21:49:42 +02:00
|
|
|
* @param mixed $showProject
|
2017-01-30 21:40:43 +02:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-01-15 22:11:04 +02:00
|
|
|
public function invoiceDescription($account, $showProject)
|
2015-12-13 22:12:54 +02:00
|
|
|
{
|
2017-01-15 22:11:04 +02:00
|
|
|
$str = '';
|
|
|
|
|
|
|
|
|
|
if ($showProject && $project = $this->project()) {
|
2017-01-16 11:30:31 +02:00
|
|
|
$str .= "## {$project}\n\n";
|
2017-01-15 22:11:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($description = trim($this->entity->description)) {
|
|
|
|
|
$str .= $description . "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-13 22:12:54 +02:00
|
|
|
$parts = json_decode($this->entity->time_log) ?: [];
|
|
|
|
|
$times = [];
|
|
|
|
|
|
|
|
|
|
foreach ($parts as $part) {
|
|
|
|
|
$start = $part[0];
|
2017-01-30 21:40:43 +02:00
|
|
|
if (count($part) == 1 || ! $part[1]) {
|
2015-12-13 22:12:54 +02:00
|
|
|
$end = time();
|
|
|
|
|
} else {
|
|
|
|
|
$end = $part[1];
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-27 21:12:34 +03:00
|
|
|
$start = $account->formatDateTime('@' . intval($start));
|
|
|
|
|
$end = $account->formatTime('@' . intval($end));
|
2015-12-13 22:12:54 +02:00
|
|
|
|
2015-12-31 10:04:12 +02:00
|
|
|
$times[] = "### {$start} - {$end}";
|
2015-12-13 22:12:54 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-15 22:11:04 +02:00
|
|
|
return $str . implode("\n", $times);
|
2015-12-13 22:12:54 +02:00
|
|
|
}
|
2017-09-12 13:43:59 +03:00
|
|
|
|
2017-09-13 00:20:18 +03:00
|
|
|
public function calendarEvent($subColors = false)
|
2017-09-12 13:43:59 +03:00
|
|
|
{
|
|
|
|
|
$data = parent::calendarEvent();
|
|
|
|
|
$task = $this->entity;
|
2017-09-12 23:25:41 +03:00
|
|
|
$account = $task->account;
|
|
|
|
|
$date = $account->getDateTime();
|
2017-09-12 13:43:59 +03:00
|
|
|
|
|
|
|
|
$data->title = trans('texts.task');
|
|
|
|
|
if ($project = $this->project()) {
|
|
|
|
|
$data->title .= ' | ' . $project;
|
|
|
|
|
}
|
2017-09-13 00:20:18 +03:00
|
|
|
if ($description = $this->description()) {
|
|
|
|
|
$data->title .= ' | ' . $description;
|
2017-09-18 08:27:40 +03:00
|
|
|
}
|
2017-09-12 13:43:59 +03:00
|
|
|
$data->allDay = false;
|
2017-09-13 00:20:18 +03:00
|
|
|
|
|
|
|
|
if ($subColors && $task->project_id) {
|
|
|
|
|
$data->borderColor = $data->backgroundColor = Utils::brewerColor($task->project->public_id);
|
|
|
|
|
} else {
|
2017-09-18 08:27:40 +03:00
|
|
|
$data->borderColor = $data->backgroundColor = '#a87821';
|
2017-09-13 00:20:18 +03:00
|
|
|
}
|
2017-09-12 13:43:59 +03:00
|
|
|
|
|
|
|
|
$parts = json_decode($task->time_log) ?: [];
|
|
|
|
|
if (count($parts)) {
|
|
|
|
|
$first = $parts[0];
|
|
|
|
|
$start = $first[0];
|
2017-09-12 23:25:41 +03:00
|
|
|
$date->setTimestamp($start);
|
|
|
|
|
$data->start = $date->format('Y-m-d H:i:m');
|
2017-09-12 13:43:59 +03:00
|
|
|
|
|
|
|
|
$last = $parts[count($parts) - 1];
|
|
|
|
|
$end = count($last) == 2 ? $last[1] : $last[0];
|
2017-09-12 23:25:41 +03:00
|
|
|
$date->setTimestamp($end);
|
|
|
|
|
$data->end = $date->format('Y-m-d H:i:m');
|
2017-09-12 13:43:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2016-05-23 12:26:08 +03:00
|
|
|
}
|