src/Entity/Olympiad/Online/Event.php line 21

  1. <?php
  2. namespace App\Entity\Olympiad\Online;
  3. use App\Entity\Common\DateInterval;
  4. use App\Entity\Common\Owner;
  5. use App\Entity\Traits\ActiveTrait;
  6. use App\Entity\Traits\TrackerFields;
  7. use App\Entity\Traits\UserCreatedInterface;
  8. use App\Entity\Traits\UserUpdatedInterface;
  9. use App\Model\Common\HaveOwnerInterface;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use function Clue\StreamFilter\fun;
  14. #[ORM\Table(name'olymp_online')]
  15. #[ORM\Entity(repositoryClass'App\Repository\Olympiad\Online\EventRepository')]
  16. #[ORM\HasLifecycleCallbacks]
  17. class Event implements UserCreatedInterfaceUserUpdatedInterfaceHaveOwnerInterface
  18. {
  19.     use TrackerFields;
  20.     use ActiveTrait;
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue(strategy'AUTO')]
  23.     #[ORM\Column(type'integer')]
  24.     private int $id;
  25.     #[ORM\Embedded(class: 'App\Entity\Common\Owner')]
  26.     private Owner $owner;
  27.     #[ORM\OneToMany(targetEntity'App\Entity\Olympiad\Online\Direction'mappedBy'event')]
  28.     private Collection $directions;
  29.     #[ORM\OneToMany(targetEntity'App\Entity\Olympiad\Online\Category'mappedBy'event')]
  30.     private Collection $categories;
  31.     /**
  32.      * @var DateInterval
  33.      */
  34.     #[ORM\Embedded(class: 'App\Entity\Common\DateInterval'columnPrefix'ri_')]
  35.     private DateInterval $regInterval;
  36.     /**
  37.      * @var DateInterval
  38.      */
  39.     #[ORM\Embedded(class: 'App\Entity\Common\DateInterval')]
  40.     private DateInterval $interval;
  41.     /**
  42.      * @var string
  43.      */
  44.     #[ORM\Column(type'string'nullabletrue)]
  45.     private ?string $callbackEmail null;
  46.     public function __construct()
  47.     {
  48.         $this->interval = new DateInterval();
  49.         $this->regInterval = new DateInterval();
  50.         $this->owner = new Owner();
  51.         $this->directions = new ArrayCollection();
  52.         $this->categories = new ArrayCollection();
  53.     }
  54.     /**
  55.      * @return Owner
  56.      */
  57.     public function getOwner(): Owner
  58.     {
  59.         return $this->owner;
  60.     }
  61.     /**
  62.      * @param Owner $owner
  63.      */
  64.     public function setOwner(Owner $owner): void
  65.     {
  66.         $this->owner $owner;
  67.     }
  68.     /**
  69.      * @return Collection
  70.      */
  71.     public function getDirections(): Collection
  72.     {
  73.         return $this->directions;
  74.     }
  75.     /**
  76.      * @return Collection
  77.      */
  78.     public function getActiveDirections(): Collection
  79.     {
  80.         return $this->directions->filter(function (Direction $d) {
  81.             return $d->isActive() && (false==$d->isDeleted());
  82.         });
  83.     }
  84.     /**
  85.      * @param Collection $directions
  86.      */
  87.     public function setDirections(Collection $directions): void
  88.     {
  89.         $this->directions $directions;
  90.     }
  91.     /**
  92.      * @return int
  93.      */
  94.     public function getId(): int
  95.     {
  96.         return $this->id;
  97.     }
  98.     /**
  99.      * @param int $id
  100.      */
  101.     public function setId(int $id): void
  102.     {
  103.         $this->id $id;
  104.     }
  105.     /**
  106.      * @return DateInterval
  107.      */
  108.     public function getRegInterval(): DateInterval
  109.     {
  110.         return $this->regInterval;
  111.     }
  112.     /**
  113.      * @param DateInterval $regInterval
  114.      */
  115.     public function setRegInterval(DateInterval $regInterval): void
  116.     {
  117.         $this->regInterval $regInterval;
  118.     }
  119.     /**
  120.      * @return string
  121.      */
  122.     public function getCallbackEmail(): ?string
  123.     {
  124.         return $this->callbackEmail;
  125.     }
  126.     /**
  127.      * @param string $callbackEmail
  128.      */
  129.     public function setCallbackEmail(?string $callbackEmail): void
  130.     {
  131.         $this->callbackEmail $callbackEmail;
  132.     }
  133.     /**
  134.      * @return ArrayCollection|Collection
  135.      */
  136.     public function getCategories()
  137.     {
  138.         return $this->categories;
  139.     }
  140.     /**
  141.      * @param ArrayCollection|Collection $categories
  142.      */
  143.     public function setCategories($categories): void
  144.     {
  145.         $this->categories $categories;
  146.     }
  147.     public function isInPast(): bool
  148.     {
  149.         $to $this->getInterval()->getTo();
  150.         if (is_null($to)) {
  151.             return false;
  152.         }
  153.         $end \DateTimeImmutable::createFromMutable($to)->setTime(000);
  154.         $now = (new \DateTimeImmutable())->setTime(000);
  155.         return $now $end;
  156.     }
  157.     /**
  158.      * @return DateInterval
  159.      */
  160.     public function getInterval(): DateInterval
  161.     {
  162.         return $this->interval;
  163.     }
  164.     /**
  165.      * @param DateInterval $interval
  166.      */
  167.     public function setInterval(DateInterval $interval): void
  168.     {
  169.         $this->interval $interval;
  170.     }
  171. }