<?php
namespace App\Entity;
use App\Repository\InterestActivityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: InterestActivityRepository::class)]
#[ORM\Table(name: 'interest_activity')]
#[ORM\Index(name: 'IDX_INTEREST_ACTIVITY_CATEGORY', columns: ['category'])]
#[ORM\Index(name: 'IDX_INTEREST_ACTIVITY_CITY', columns: ['city'])]
#[ORM\Index(name: 'IDX_INTEREST_ACTIVITY_STATUS_START', columns: ['status', 'start_at'])]
class InterestActivity
{
public const STATUS_OPEN = 'open';
public const STATUS_CLOSED = 'closed';
public const STATUS_CANCELED = 'canceled';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?User $organizer = null;
#[ORM\OneToOne]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL', unique: true)]
private ?Conversation $conversation = null;
#[ORM\Column(length: 140)]
private string $title = '';
#[ORM\Column(length: 80)]
private string $category = '';
#[ORM\Column(length: 120)]
private string $city = '';
#[ORM\Column(type: Types::TEXT)]
private string $description = '';
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $startAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $endAt = null;
#[ORM\Column]
private int $capacity = 20;
#[ORM\Column(length: 20)]
private string $status = self::STATUS_OPEN;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
/**
* @var Collection<int, InterestActivityRegistration>
*/
#[ORM\OneToMany(mappedBy: 'activity', targetEntity: InterestActivityRegistration::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $registrations;
public function __construct()
{
$this->registrations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getOrganizer(): ?User
{
return $this->organizer;
}
public function setOrganizer(?User $organizer): self
{
$this->organizer = $organizer;
return $this;
}
public function getConversation(): ?Conversation
{
return $this->conversation;
}
public function setConversation(?Conversation $conversation): self
{
$this->conversation = $conversation;
return $this;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = mb_substr(trim($title), 0, 140);
return $this;
}
public function getCategory(): string
{
return $this->category;
}
public function setCategory(string $category): self
{
$this->category = mb_substr(trim($category), 0, 80);
return $this;
}
public function getCity(): string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = mb_substr(trim($city), 0, 120);
return $this;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = mb_substr(trim($description), 0, 5000);
return $this;
}
public function getStartAt(): ?\DateTimeImmutable
{
return $this->startAt;
}
public function setStartAt(?\DateTimeImmutable $startAt): self
{
$this->startAt = $startAt;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->endAt;
}
public function setEndAt(?\DateTimeImmutable $endAt): self
{
$this->endAt = $endAt;
return $this;
}
public function getCapacity(): int
{
return $this->capacity;
}
public function setCapacity(int $capacity): self
{
$this->capacity = max(2, min(300, $capacity));
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, InterestActivityRegistration>
*/
public function getRegistrations(): Collection
{
return $this->registrations;
}
}