<?php
namespace App\AtechNet\CoreBundle\Entity;
use DateTime;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table as Table;
/**
* Nanobar
*
* @Table(name="nanobar")
* @Entity
*/
class Nanobar extends AbstractSignedEntity
{
public const COLORS = ["#121212", "#00aeef", "#fe6a00", "#e52635", "#25c1d9"];
/**
* @return array
*/
public static function getColorChoices(): array
{
return [
'#121212' => '#121212 - Gray 7',
'#00aeef' => '#00aeef - Deep Sky Blue',
'#fe6a00' => '#fe6a00 - Golden Poppy',
'#e52635' => '#e52635 - Alizarin Crimson',
'#25c1d9' => '#25c1d9 - Lapis Lazuli',
];
}
/**
* @var Domain
*
* @ManyToOne(targetEntity="Domain", inversedBy="nanobars")
* @JoinColumn(name="domain_id", referencedColumnName="id", nullable=false)
*/
private $domain;
/**
* @var DomainNavigation
*
* @ManyToOne(targetEntity="DomainNavigation", inversedBy="nanobars")
* @JoinColumn(name="domain_navigation_id", referencedColumnName="id", nullable=true)
*/
private $domainNavigation;
/**
* @var string
*
* @Column(name="color", type="string", length=7)
*/
private $color;
/**
* @var string
*
* @Column(name="message", type="string", length=155)
*/
private $message;
/**
* @var DateTime|null
*
* @Column(name="startDate", type="datetime", nullable=true)
*/
private $startDate;
/**
* @var DateTime|null
*
* @Column(name="endDate", type="datetime", nullable=true)
*/
private $endDate;
/**
* @var bool
*
* @Column(name="enabled", type="boolean")
*/
private $enabled = false;
public function setDomain(Domain $domain): Nanobar
{
$this->domain = $domain;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
/**
* @return DomainNavigation|null
*/
public function getDomainNavigation(): ?DomainNavigation
{
return $this->domainNavigation;
}
/**
* @param DomainNavigation|null $domainNavigation
* @return void
*/
public function setDomainNavigation(?DomainNavigation $domainNavigation): void
{
$this->domainNavigation = $domainNavigation;
}
public function setColor(string $color): Nanobar
{
$this->color = $color;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setMessage(string $message): Nanobar
{
$this->message = $message;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setStartDate(DateTime $startDate = null): Nanobar
{
$this->startDate = $startDate;
return $this;
}
public function getStartDate(): ?DateTime
{
return $this->startDate;
}
public function setEndDate(DateTime $endDate = null): Nanobar
{
$this->endDate = $endDate;
return $this;
}
public function getEndDate(): ?DateTime
{
return $this->endDate;
}
public function setEnabled(bool $enabled): Nanobar
{
$this->enabled = $enabled;
return $this;
}
public function getEnabled(): bool
{
return $this->enabled;
}
public function isActive(): bool
{
$active = false;
$now = new DateTime();
if ($this->enabled) {
if ($this->startDate && $this->endDate) {
$active = $now >= $this->startDate && $now <= $this->endDate;
} elseif ($this->startDate && !$this->endDate) {
$active = $now >= $this->startDate;
} elseif (!$this->startDate && $this->endDate) {
$active = $now <= $this->endDate;
} else {
$active = true;
}
}
return $active;
}
}