src/Entity/Team.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TeamRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups// Add this use statement
  8. #[ORM\Entity(repositoryClassTeamRepository::class)]
  9. class Team
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     #[Groups(["chat:channel:list""chat_message"])] // Add group
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     #[Groups(["chat:channel:list""chat_message"])] // Add group
  18.     private ?string $name null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $logo null;
  21.     #[ORM\Column]
  22.     private ?\DateTimeImmutable $createdAt null;
  23.     #[ORM\OneToMany(mappedBy'team'targetEntityUserTeam::class, orphanRemovaltrue)]
  24.     private Collection $userTeams;
  25.     #[ORM\OneToMany(mappedBy'team'targetEntityTeamSeason::class, orphanRemovaltrue)]
  26.     private Collection $teamSeasons;
  27.     #[ORM\OneToMany(mappedBy'team'targetEntityChatMessage::class)]
  28.     private Collection $chatMessages;
  29.     public function __toString(): string
  30.     {
  31.         return $this->getName();
  32.     }
  33.     public function __construct()
  34.     {
  35.         $this->userTeams = new ArrayCollection();
  36.         $this->teamSeasons = new ArrayCollection();
  37.         $this->chatMessages = new ArrayCollection();
  38.         $this->createdAt = new \DateTimeImmutable();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): static
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getLogo(): ?string
  54.     {
  55.         return $this->logo;
  56.     }
  57.     public function setLogo(?string $logo): static
  58.     {
  59.         $this->logo $logo;
  60.         return $this;
  61.     }
  62.     public function getCreatedAt(): ?\DateTimeImmutable
  63.     {
  64.         return $this->createdAt;
  65.     }
  66.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  67.     {
  68.         $this->createdAt $createdAt;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, UserTeam>
  73.      */
  74.     public function getUserTeams(): Collection
  75.     {
  76.         return $this->userTeams;
  77.     }
  78.     public function addUserTeam(UserTeam $userTeam): static
  79.     {
  80.         if (!$this->userTeams->contains($userTeam)) {
  81.             $this->userTeams->add($userTeam);
  82.             $userTeam->setTeam($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeUserTeam(UserTeam $userTeam): static
  87.     {
  88.         if ($this->userTeams->removeElement($userTeam)) {
  89.             // set the owning side to null (unless already changed)
  90.             if ($userTeam->getTeam() === $this) {
  91.                 $userTeam->setTeam(null);
  92.             }
  93.         }
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return Collection<int, TeamSeason>
  98.      */
  99.     public function getTeamSeasons(): Collection
  100.     {
  101.         return $this->teamSeasons;
  102.     }
  103.     public function addTeamSeason(TeamSeason $teamSeason): static
  104.     {
  105.         if (!$this->teamSeasons->contains($teamSeason)) {
  106.             $this->teamSeasons->add($teamSeason);
  107.             $teamSeason->setTeam($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeTeamSeason(TeamSeason $teamSeason): static
  112.     {
  113.         if ($this->teamSeasons->removeElement($teamSeason)) {
  114.             // set the owning side to null (unless already changed)
  115.             if ($teamSeason->getTeam() === $this) {
  116.                 $teamSeason->setTeam(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection<int, ChatMessage>
  123.      */
  124.     public function getChatMessages(): Collection
  125.     {
  126.         return $this->chatMessages;
  127.     }
  128.     public function addChatMessage(ChatMessage $chatMessage): static
  129.     {
  130.         if (!$this->chatMessages->contains($chatMessage)) {
  131.             $this->chatMessages->add($chatMessage);
  132.             $chatMessage->setTeam($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeChatMessage(ChatMessage $chatMessage): static
  137.     {
  138.         if ($this->chatMessages->removeElement($chatMessage)) {
  139.             // set the owning side to null (unless already changed)
  140.             if ($chatMessage->getTeam() === $this) {
  141.                 $chatMessage->setTeam(null);
  142.             }
  143.         }
  144.         return $this;
  145.     }
  146.     /**
  147.      * Get all users that are members of this team
  148.      * 
  149.      * @return Collection<int, User>
  150.      */
  151.     public function getMembers(): Collection
  152.     {
  153.         $members = new ArrayCollection();
  154.         
  155.         foreach ($this->userTeams as $userTeam) {
  156.             $members->add($userTeam->getUser());
  157.         }
  158.         
  159.         return $members;
  160.     }
  161. }