Files
kimai/src/Calendar/TimesheetEntry.php
Kevin Papst 0dba83d8e9 Budget graph in project details (#3406)
* do not copy description if restarting via calendar
* added support to display negative durations
* fix charts for larger numbers
2022-07-13 17:21:36 +02:00

82 lines
2.1 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Calendar;
use App\Entity\Activity;
use App\Entity\Project;
use App\Entity\Timesheet;
final class TimesheetEntry implements DragAndDropEntry
{
/**
* @var Timesheet
*/
private $timesheet;
/**
* @var string
*/
private $color;
public function __construct(Timesheet $timesheet, string $color)
{
$this->timesheet = $timesheet;
$this->color = $color;
}
public function getData(): array
{
$tags = null;
if (!empty($this->timesheet->getTagsAsArray())) {
$tags = implode(',', $this->timesheet->getTagsAsArray());
}
return [
// restarting a timesheet should not copy the description - @version 1.21
//'description' => $this->timesheet->getDescription(),
'activity' => $this->timesheet->getActivity() !== null ? $this->timesheet->getActivity()->getId() : null,
'project' => $this->timesheet->getProject() !== null ? $this->timesheet->getProject()->getId() : null,
'tags' => $tags,
];
}
public function getTitle(): string
{
if ($this->timesheet->getActivity() !== null && $this->timesheet->getActivity()->getName() !== null) {
return $this->timesheet->getActivity()->getName();
}
if (null !== $this->timesheet->getProject() && $this->timesheet->getProject()->getName() !== null) {
return $this->timesheet->getProject()->getName();
}
return $this->timesheet->getDescription() ?? '';
}
public function getColor(): string
{
return $this->color;
}
public function getBlockName(): ?string
{
return 'dd_timesheet';
}
public function getActivity(): ?Activity
{
return $this->timesheet->getActivity();
}
public function getProject(): ?Project
{
return $this->timesheet->getProject();
}
}