src/Entity/Olympiad/Online/Event.php line 21
<?php
namespace App\Entity\Olympiad\Online;
use App\Entity\Common\DateInterval;
use App\Entity\Common\Owner;
use App\Entity\Traits\ActiveTrait;
use App\Entity\Traits\TrackerFields;
use App\Entity\Traits\UserCreatedInterface;
use App\Entity\Traits\UserUpdatedInterface;
use App\Model\Common\HaveOwnerInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use function Clue\StreamFilter\fun;
#[ORM\Table(name: 'olymp_online')]
#[ORM\Entity(repositoryClass: 'App\Repository\Olympiad\Online\EventRepository')]
#[ORM\HasLifecycleCallbacks]
class Event implements UserCreatedInterface, UserUpdatedInterface, HaveOwnerInterface
{
use TrackerFields;
use ActiveTrait;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
private int $id;
#[ORM\Embedded(class: 'App\Entity\Common\Owner')]
private Owner $owner;
#[ORM\OneToMany(targetEntity: 'App\Entity\Olympiad\Online\Direction', mappedBy: 'event')]
private Collection $directions;
#[ORM\OneToMany(targetEntity: 'App\Entity\Olympiad\Online\Category', mappedBy: 'event')]
private Collection $categories;
/**
* @var DateInterval
*/
#[ORM\Embedded(class: 'App\Entity\Common\DateInterval', columnPrefix: 'ri_')]
private DateInterval $regInterval;
/**
* @var DateInterval
*/
#[ORM\Embedded(class: 'App\Entity\Common\DateInterval')]
private DateInterval $interval;
/**
* @var string
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $callbackEmail = null;
public function __construct()
{
$this->interval = new DateInterval();
$this->regInterval = new DateInterval();
$this->owner = new Owner();
$this->directions = new ArrayCollection();
$this->categories = new ArrayCollection();
}
/**
* @return Owner
*/
public function getOwner(): Owner
{
return $this->owner;
}
/**
* @param Owner $owner
*/
public function setOwner(Owner $owner): void
{
$this->owner = $owner;
}
/**
* @return Collection
*/
public function getDirections(): Collection
{
return $this->directions;
}
/**
* @return Collection
*/
public function getActiveDirections(): Collection
{
return $this->directions->filter(function (Direction $d) {
return $d->isActive() && (false==$d->isDeleted());
});
}
/**
* @param Collection $directions
*/
public function setDirections(Collection $directions): void
{
$this->directions = $directions;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return DateInterval
*/
public function getRegInterval(): DateInterval
{
return $this->regInterval;
}
/**
* @param DateInterval $regInterval
*/
public function setRegInterval(DateInterval $regInterval): void
{
$this->regInterval = $regInterval;
}
/**
* @return string
*/
public function getCallbackEmail(): ?string
{
return $this->callbackEmail;
}
/**
* @param string $callbackEmail
*/
public function setCallbackEmail(?string $callbackEmail): void
{
$this->callbackEmail = $callbackEmail;
}
/**
* @return ArrayCollection|Collection
*/
public function getCategories()
{
return $this->categories;
}
/**
* @param ArrayCollection|Collection $categories
*/
public function setCategories($categories): void
{
$this->categories = $categories;
}
public function isInPast(): bool
{
$to = $this->getInterval()->getTo();
if (is_null($to)) {
return false;
}
$end = \DateTimeImmutable::createFromMutable($to)->setTime(0, 0, 0);
$now = (new \DateTimeImmutable())->setTime(0, 0, 0);
return $now > $end;
}
/**
* @return DateInterval
*/
public function getInterval(): DateInterval
{
return $this->interval;
}
/**
* @param DateInterval $interval
*/
public function setInterval(DateInterval $interval): void
{
$this->interval = $interval;
}
}