src/AtechNet/CoreBundle/Entity/Nanobar.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping\Column;
  5. use Doctrine\ORM\Mapping\Entity;
  6. use Doctrine\ORM\Mapping\JoinColumn;
  7. use Doctrine\ORM\Mapping\ManyToOne;
  8. use Doctrine\ORM\Mapping\Table as Table;
  9. /**
  10.  * Nanobar
  11.  *
  12.  * @Table(name="nanobar")
  13.  * @Entity
  14.  */
  15. class Nanobar extends AbstractSignedEntity
  16. {
  17.     public const COLORS = ["#121212", "#00aeef", "#fe6a00", "#e52635", "#25c1d9"];
  18.     /**
  19.      * @return array
  20.      */
  21.     public static function getColorChoices(): array
  22.     {
  23.         return [
  24.             '#121212' => '#121212 - Gray 7',
  25.             '#00aeef' => '#00aeef - Deep Sky Blue',
  26.             '#fe6a00' => '#fe6a00 - Golden Poppy',
  27.             '#e52635' => '#e52635 - Alizarin Crimson',
  28.             '#25c1d9' => '#25c1d9 - Lapis Lazuli',
  29.         ];
  30.     }
  31.     /**
  32.      * @var Domain
  33.      *
  34.      * @ManyToOne(targetEntity="Domain", inversedBy="nanobars")
  35.      * @JoinColumn(name="domain_id", referencedColumnName="id", nullable=false)
  36.      */
  37.     private $domain;
  38.     /**
  39.      * @var DomainNavigation
  40.      *
  41.      * @ManyToOne(targetEntity="DomainNavigation", inversedBy="nanobars")
  42.      * @JoinColumn(name="domain_navigation_id", referencedColumnName="id", nullable=true)
  43.      */
  44.     private $domainNavigation;
  45.     /**
  46.      * @var string
  47.      *
  48.      * @Column(name="color", type="string", length=7)
  49.      */
  50.     private $color;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @Column(name="message", type="string", length=155)
  55.      */
  56.     private $message;
  57.     /**
  58.      * @var DateTime|null
  59.      *
  60.      * @Column(name="startDate", type="datetime", nullable=true)
  61.      */
  62.     private $startDate;
  63.     /**
  64.      * @var DateTime|null
  65.      *
  66.      * @Column(name="endDate", type="datetime", nullable=true)
  67.      */
  68.     private $endDate;
  69.     /**
  70.      * @var bool
  71.      *
  72.      * @Column(name="enabled", type="boolean")
  73.      */
  74.     private $enabled = false;
  75.     public function setDomain(Domain $domain): Nanobar
  76.     {
  77.         $this->domain = $domain;
  78.         return $this;
  79.     }
  80.     public function getDomain(): ?Domain
  81.     {
  82.         return $this->domain;
  83.     }
  84.     /**
  85.      * @return DomainNavigation|null
  86.      */
  87.     public function getDomainNavigation(): ?DomainNavigation
  88.     {
  89.         return $this->domainNavigation;
  90.     }
  91.     /**
  92.      * @param DomainNavigation|null $domainNavigation
  93.      * @return void
  94.      */
  95.     public function setDomainNavigation(?DomainNavigation $domainNavigation): void
  96.     {
  97.         $this->domainNavigation = $domainNavigation;
  98.     }
  99.     public function setColor(string $color): Nanobar
  100.     {
  101.         $this->color = $color;
  102.         return $this;
  103.     }
  104.     public function getColor(): ?string
  105.     {
  106.         return $this->color;
  107.     }
  108.     public function setMessage(string $message): Nanobar
  109.     {
  110.         $this->message = $message;
  111.         return $this;
  112.     }
  113.     public function getMessage(): ?string
  114.     {
  115.         return $this->message;
  116.     }
  117.     public function setStartDate(DateTime $startDate = null): Nanobar
  118.     {
  119.         $this->startDate = $startDate;
  120.         return $this;
  121.     }
  122.     public function getStartDate(): ?DateTime
  123.     {
  124.         return $this->startDate;
  125.     }
  126.     public function setEndDate(DateTime $endDate = null): Nanobar
  127.     {
  128.         $this->endDate = $endDate;
  129.         return $this;
  130.     }
  131.     public function getEndDate(): ?DateTime
  132.     {
  133.         return $this->endDate;
  134.     }
  135.     public function setEnabled(bool $enabled): Nanobar
  136.     {
  137.         $this->enabled = $enabled;
  138.         return $this;
  139.     }
  140.     public function getEnabled(): bool
  141.     {
  142.         return $this->enabled;
  143.     }
  144.     public function isActive(): bool
  145.     {
  146.         $active = false;
  147.         $now = new DateTime();
  148.         if ($this->enabled) {
  149.             if ($this->startDate && $this->endDate) {
  150.                 $active = $now >= $this->startDate && $now <= $this->endDate;
  151.             } elseif ($this->startDate && !$this->endDate) {
  152.                 $active = $now >= $this->startDate;
  153.             } elseif (!$this->startDate && $this->endDate) {
  154.                 $active = $now <= $this->endDate;
  155.             } else {
  156.                 $active = true;
  157.             }
  158.         }
  159.         return $active;
  160.     }
  161. }