<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
#[ORM\Entity]
#[ApiResource(iri: 'ChannelUser')]
class ChannelUser
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToOne(targetEntity: Channel::class, inversedBy: 'users')]
#[ApiProperty()]
#[Groups([
'user:collection:post',
'user:item:get',
'user:item:put',
])]
#[MaxDepth(1)]
private $channel;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'channels')]
#[Groups([
'channel:item:get',
])]
private $user;
#[ApiProperty()]
#[Groups([
'channel:item:get',
])]
private $userIdentifier;
#[ApiProperty()]
#[Groups([
'channel:item:get',
])]
private $avatar;
public function getId(): ?int
{
return $this->id;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): self
{
$this->channel = $channel;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUserIdentifier(): ?string
{
return $this->getUser()->getUserIdentifier();
}
public function getAvatar(): ?string
{
return $this->getUser()->getAvatar() ? $this->getUser()->getAvatar()->getContentUrl() : false;
}
}