src/Entity/UserTeam.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserTeamRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassUserTeamRepository::class)]
  6. class UserTeam
  7. {
  8.     #[ORM\Id]
  9.     #[ORM\GeneratedValue]
  10.     #[ORM\Column]
  11.     private ?int $id null;
  12.     #[ORM\ManyToOne(inversedBy'userTeams')]
  13.     #[ORM\JoinColumn(nullablefalse)]
  14.     private ?User $user null;
  15.     #[ORM\ManyToOne(inversedBy'userTeams')]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private ?Team $team null;
  18.     #[ORM\Column(length50)]
  19.     private ?string $role null;
  20.     #[ORM\Column]
  21.     private ?\DateTimeImmutable $joinedAt null;
  22.     /**
  23.      * Available team roles
  24.      */
  25.     public const ROLE_MEMBER 'member';
  26.     public const ROLE_CAPTAIN 'captain';
  27.     /**
  28.      * Get all available team roles
  29.      *
  30.      * @return array<string, string>
  31.      */
  32.     public static function getAvailableRoles(): array
  33.     {
  34.         return [
  35.             'Team Member' => self::ROLE_MEMBER,
  36.             'Team Captain' => self::ROLE_CAPTAIN,
  37.         ];
  38.     }
  39.     public function __construct()
  40.     {
  41.         $this->joinedAt = new \DateTimeImmutable();
  42.         $this->role self::ROLE_MEMBER;
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getUser(): ?User
  49.     {
  50.         return $this->user;
  51.     }
  52.     public function setUser(?User $user): static
  53.     {
  54.         $this->user $user;
  55.         return $this;
  56.     }
  57.     public function getTeam(): ?Team
  58.     {
  59.         return $this->team;
  60.     }
  61.     public function setTeam(?Team $team): static
  62.     {
  63.         $this->team $team;
  64.         return $this;
  65.     }
  66.     public function getRole(): ?string
  67.     {
  68.         return $this->role;
  69.     }
  70.     public function setRole(string $role): static
  71.     {
  72.         $this->role $role;
  73.         return $this;
  74.     }
  75.     public function getJoinedAt(): ?\DateTimeImmutable
  76.     {
  77.         return $this->joinedAt;
  78.     }
  79.     public function setJoinedAt(\DateTimeImmutable $joinedAt): static
  80.     {
  81.         $this->joinedAt $joinedAt;
  82.         return $this;
  83.     }
  84.     /**
  85.      * Check if user is a team captain
  86.      */
  87.     public function isTeamLeader(): bool
  88.     {
  89.         return $this->role === self::ROLE_CAPTAIN;
  90.     }
  91.     /**
  92.      * Check if user has a specific team role
  93.      */
  94.     public function hasRole(string $role): bool
  95.     {
  96.         return $this->role === $role;
  97.     }
  98.     /**
  99.      * Check if user can manage team members
  100.      */
  101.     public function canManageMembers(): bool
  102.     {
  103.         return $this->role === self::ROLE_CAPTAIN;
  104.     }
  105.     /**
  106.      * Check if user can manage team settings
  107.      */
  108.     public function canManageTeam(): bool
  109.     {
  110.         return $this->role === self::ROLE_CAPTAIN;
  111.     }
  112. }