<?php
namespace App\Database\Domain\Entity\Sessions;
use App\Database\Domain\Entity\AbstractEntity;
use App\Database\Domain\Entity\User\User;
use App\Database\Domain\Traits\CreationDateTrait;
use App\Database\Domain\Traits\OrderIndexTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Database\Domain\Repository\ToastSessionRepository")
*/
class ToastSession extends AbstractEntity
{
use CreationDateTrait;
use OrderIndexTrait;
/**
* @ORM\ManyToOne(targetEntity="App\Database\Domain\Entity\User\User", inversedBy="sessions")
*
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private User $user;
/**
* @ORM\Column(type="string")
*
* @Assert\Length(max="255")
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity="App\Database\Domain\Entity\Sessions\ToastSessionLink", mappedBy="session", fetch="EXTRA_LAZY", cascade={"all"})
*
* @ORM\OrderBy({"orderIndex": "ASC"})
*
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="write_rare")
*
* @var Collection<int, ToastSessionLink>
*/
private Collection $links;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $browserId;
/**
* @ORM\Column(type="boolean")
*/
private bool $isEnabled;
/**
* @ORM\Column(type="string", nullable=false, unique=true)
*/
private string $shareSlug;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 0})
*/
private bool $enabledForCollaboration;
/**
* @ORM\ManyToOne(targetEntity="App\Database\Domain\Entity\Sessions\ToastSessionSection", inversedBy="sessions")
*
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?ToastSessionSection $section = null;
/**
* @ORM\Column(type="string", nullable=true)
*
* @Assert\Length(max="5")
*/
private ?string $emoji = null;
public function __construct(
string $id,
string $name,
string $shareSlug,
User $user,
?string $browserId = null,
bool $isEnabled = true
) {
$this->id = $id;
$this->name = $name;
$this->shareSlug = $shareSlug;
$this->user = $user;
$this->browserId = $browserId;
$this->isEnabled = $isEnabled;
$this->creationDate = new \DateTimeImmutable();
$this->links = new ArrayCollection();
$this->orderIndex = 0;
$this->enabledForCollaboration = false;
}
public function __toString(): string
{
return $this->id;
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return ToastSessionLink[]
*/
public function getLinks(): Collection
{
return $this->links;
}
public function addLink(ToastSessionLink $link): self
{
$this->links[] = $link;
return $this;
}
public function getBrowserId(): ?string
{
return $this->browserId;
}
public function setBrowserId(?string $browserId): self
{
$this->browserId = $browserId;
return $this;
}
public function isEnabled(): bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
public function getShareSlug(): string
{
return $this->shareSlug;
}
public function setShareSlug(string $shareSlug): self
{
$this->shareSlug = $shareSlug;
return $this;
}
public function isEnabledForCollaboration(): bool
{
return $this->enabledForCollaboration;
}
public function setEnabledForCollaboration(bool $enabledForCollaboration): void
{
$this->enabledForCollaboration = $enabledForCollaboration;
}
public function getEmoji(): ?string
{
return $this->emoji;
}
public function setEmoji(?string $emoji): void
{
$this->emoji = $emoji;
}
public function getSection(): ?ToastSessionSection
{
return $this->section;
}
public function setSection(?ToastSessionSection $section): void
{
$this->section = $section;
}
}