2019-07-18 13:44:19 +02:00
|
|
|
<?php
|
2021-01-07 08:50:43 +01:00
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-11-09 10:27:43 +01:00
|
|
|
namespace WerkraumMedia\Events\Domain\Model;
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
use DateTime;
|
|
|
|
use DateTimeImmutable;
|
|
|
|
use DateTimeZone;
|
2021-01-07 08:47:15 +01:00
|
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
2021-01-07 08:50:43 +01:00
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
/**
|
|
|
|
* Date
|
|
|
|
*/
|
2021-01-07 08:47:15 +01:00
|
|
|
class Date extends AbstractEntity
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
2023-11-27 10:04:42 +01:00
|
|
|
protected DateTime $start;
|
|
|
|
|
|
|
|
protected ?DateTime $end = null;
|
|
|
|
|
|
|
|
protected string $canceled = 'no';
|
|
|
|
|
|
|
|
protected ?Date $postponedDate = null;
|
|
|
|
|
|
|
|
protected ?Date $originalDate = null;
|
|
|
|
|
2023-11-29 10:36:59 +01:00
|
|
|
/**
|
|
|
|
* Can not be null in theory.
|
|
|
|
* But editors might disable an event.
|
|
|
|
* The date might still be available by Extbase, but without event.
|
|
|
|
* This needs to be handled properly by consuming code for now.
|
|
|
|
*/
|
|
|
|
protected ?Event $event;
|
2023-11-27 10:04:42 +01:00
|
|
|
|
|
|
|
protected string $canceledLink = '';
|
|
|
|
|
|
|
|
public function getStart(): DateTime
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
return $this->start;
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function setStart(DateTime $start): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->start = $start;
|
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
public function getHasUsefulStartTime(): bool
|
|
|
|
{
|
|
|
|
return $this->getStart()->format('H:i') !== '00:00';
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function getEnd(): ?DateTime
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
return $this->end;
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function setEnd(?DateTime $end): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->end = $end;
|
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
public function getHasUsefulEndTime(): bool
|
|
|
|
{
|
2023-08-10 14:20:37 +02:00
|
|
|
$end = $this->getEnd();
|
|
|
|
return $end && $end->format('H:i') !== '23:59';
|
2022-06-28 11:38:55 +02:00
|
|
|
}
|
2021-03-11 17:39:15 +01:00
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
public function getEndsOnSameDay(): bool
|
|
|
|
{
|
2023-08-10 14:20:37 +02:00
|
|
|
$end = $this->getEnd();
|
|
|
|
return $end && $this->getStart()->format('Y-m-d') === $end->format('Y-m-d');
|
2022-06-28 11:38:55 +02:00
|
|
|
}
|
2021-01-12 16:42:58 +01:00
|
|
|
|
2023-11-29 10:36:59 +01:00
|
|
|
public function getEvent(): ?Event
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
return $this->event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEvent(Event $event): self
|
|
|
|
{
|
|
|
|
$this->event = $event;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function setLanguageUid(int $languageUid): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2020-10-01 08:56:44 +02:00
|
|
|
$this->_languageUid = $languageUid;
|
2020-10-01 08:34:13 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function getLanguageUid(): int
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2020-10-01 08:56:44 +02:00
|
|
|
return $this->_languageUid;
|
2020-10-01 08:34:13 +02:00
|
|
|
}
|
2021-03-11 17:39:15 +01:00
|
|
|
|
|
|
|
public function getCanceled(): string
|
|
|
|
{
|
|
|
|
return $this->canceled;
|
|
|
|
}
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
public function setCanceled(string $canceled): void
|
2021-03-11 17:39:15 +01:00
|
|
|
{
|
|
|
|
$this->canceled = $canceled;
|
|
|
|
}
|
2021-03-16 12:10:07 +01:00
|
|
|
|
|
|
|
public function getPostponedDate(): ?Date
|
|
|
|
{
|
|
|
|
if ($this->getCanceled() === 'postponed') {
|
|
|
|
return $this->postponedDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2021-03-16 16:05:39 +01:00
|
|
|
|
2021-06-17 12:08:09 +02:00
|
|
|
public function getOriginalDate(): ?Date
|
|
|
|
{
|
|
|
|
return $this->originalDate;
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:05:39 +01:00
|
|
|
public function getCanceledLink(): string
|
|
|
|
{
|
|
|
|
if ($this->getCanceled() === 'canceled') {
|
|
|
|
return $this->canceledLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
2021-09-07 08:36:48 +02:00
|
|
|
|
2022-04-21 08:07:25 +02:00
|
|
|
public static function createFromDestinationDataDate(
|
|
|
|
array $date,
|
|
|
|
bool $canceled
|
|
|
|
): self {
|
|
|
|
return self::createFromDestinationData(
|
2023-11-27 10:04:42 +01:00
|
|
|
new DateTimeImmutable($date['start'], new DateTimeZone($date['tz'])),
|
|
|
|
new DateTimeImmutable($date['end'], new DateTimeZone($date['tz'])),
|
2022-04-21 08:07:25 +02:00
|
|
|
$canceled
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-07 08:36:48 +02:00
|
|
|
public static function createFromDestinationData(
|
2023-11-27 10:04:42 +01:00
|
|
|
DateTimeImmutable $start,
|
|
|
|
DateTimeImmutable $end,
|
2021-09-07 08:36:48 +02:00
|
|
|
bool $canceled
|
|
|
|
): self {
|
|
|
|
$date = new Date();
|
|
|
|
$date->setLanguageUid(-1);
|
|
|
|
|
2023-11-27 10:04:42 +01:00
|
|
|
$date->setStart(new DateTime($start->format(DateTime::W3C), $start->getTimezone()));
|
|
|
|
$date->setEnd(new DateTime($end->format(DateTime::W3C), $end->getTimezone()));
|
2021-09-07 08:36:48 +02:00
|
|
|
|
|
|
|
if ($canceled) {
|
|
|
|
$date->setCanceled('canceled');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
}
|
2019-07-18 13:44:19 +02:00
|
|
|
}
|