<?php
namespace App\Entity;
use App\Repository\TeamRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups; // Add this use statement
#[ORM\Entity(repositoryClass: TeamRepository::class)]
class Team
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["chat:channel:list", "chat_message"])] // Add group
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(["chat:channel:list", "chat_message"])] // Add group
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $logo = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\OneToMany(mappedBy: 'team', targetEntity: UserTeam::class, orphanRemoval: true)]
private Collection $userTeams;
#[ORM\OneToMany(mappedBy: 'team', targetEntity: TeamSeason::class, orphanRemoval: true)]
private Collection $teamSeasons;
#[ORM\OneToMany(mappedBy: 'team', targetEntity: ChatMessage::class)]
private Collection $chatMessages;
public function __toString(): string
{
return $this->getName();
}
public function __construct()
{
$this->userTeams = new ArrayCollection();
$this->teamSeasons = new ArrayCollection();
$this->chatMessages = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): static
{
$this->logo = $logo;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, UserTeam>
*/
public function getUserTeams(): Collection
{
return $this->userTeams;
}
public function addUserTeam(UserTeam $userTeam): static
{
if (!$this->userTeams->contains($userTeam)) {
$this->userTeams->add($userTeam);
$userTeam->setTeam($this);
}
return $this;
}
public function removeUserTeam(UserTeam $userTeam): static
{
if ($this->userTeams->removeElement($userTeam)) {
// set the owning side to null (unless already changed)
if ($userTeam->getTeam() === $this) {
$userTeam->setTeam(null);
}
}
return $this;
}
/**
* @return Collection<int, TeamSeason>
*/
public function getTeamSeasons(): Collection
{
return $this->teamSeasons;
}
public function addTeamSeason(TeamSeason $teamSeason): static
{
if (!$this->teamSeasons->contains($teamSeason)) {
$this->teamSeasons->add($teamSeason);
$teamSeason->setTeam($this);
}
return $this;
}
public function removeTeamSeason(TeamSeason $teamSeason): static
{
if ($this->teamSeasons->removeElement($teamSeason)) {
// set the owning side to null (unless already changed)
if ($teamSeason->getTeam() === $this) {
$teamSeason->setTeam(null);
}
}
return $this;
}
/**
* @return Collection<int, ChatMessage>
*/
public function getChatMessages(): Collection
{
return $this->chatMessages;
}
public function addChatMessage(ChatMessage $chatMessage): static
{
if (!$this->chatMessages->contains($chatMessage)) {
$this->chatMessages->add($chatMessage);
$chatMessage->setTeam($this);
}
return $this;
}
public function removeChatMessage(ChatMessage $chatMessage): static
{
if ($this->chatMessages->removeElement($chatMessage)) {
// set the owning side to null (unless already changed)
if ($chatMessage->getTeam() === $this) {
$chatMessage->setTeam(null);
}
}
return $this;
}
/**
* Get all users that are members of this team
*
* @return Collection<int, User>
*/
public function getMembers(): Collection
{
$members = new ArrayCollection();
foreach ($this->userTeams as $userTeam) {
$members->add($userTeam->getUser());
}
return $members;
}
}