118 lines
2.5 KiB
PHP
118 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
/*
|
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*/
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* @ORM\Entity()
|
|
*/
|
|
class Entry
|
|
{
|
|
/**
|
|
* @ORM\Id()
|
|
* @ORM\GeneratedValue()
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var string
|
|
* @ORM\Column(type="string", length=255)
|
|
*/
|
|
private $title = '';
|
|
|
|
/**
|
|
* @var \DateTimeImmutable|null
|
|
* @ORM\Column(type="datetime")
|
|
*/
|
|
private $start;
|
|
|
|
/**
|
|
* @var \DateTimeImmutable|null
|
|
* @ORM\Column(type="datetime")
|
|
*/
|
|
private $end;
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
private $running = false;
|
|
|
|
public function __construct(
|
|
string $title = ''
|
|
) {
|
|
$this->title = $title;
|
|
}
|
|
|
|
public static function fromPersistence(
|
|
string $title,
|
|
\DateTimeImmutable $start,
|
|
\DateTimeImmutable $end
|
|
): self {
|
|
$entry = new static();
|
|
|
|
$entry->title = $title;
|
|
$entry->start = $start;
|
|
$entry->end = $end;
|
|
|
|
return $entry;
|
|
}
|
|
|
|
public function start(): void
|
|
{
|
|
$this->start = new \DateTimeImmutable();
|
|
$this->running = true;
|
|
}
|
|
|
|
public function stop(): void
|
|
{
|
|
$this->end = new \DateTimeImmutable();
|
|
$this->running = false;
|
|
}
|
|
|
|
public function isRunning(): bool
|
|
{
|
|
return $this->running;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function getBegan(): ?\DateTimeImmutable
|
|
{
|
|
return $this->start;
|
|
}
|
|
|
|
public function getEnded(): ?\DateTimeImmutable
|
|
{
|
|
return $this->end;
|
|
}
|
|
|
|
public function getDuration(): \DateInterval
|
|
{
|
|
return $this->start->diff($this->end);
|
|
}
|
|
}
|