<?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: 'BrokerUser')]
class BrokerUser
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToOne(targetEntity: Broker::class, inversedBy: 'users')]
#[ApiProperty()]
#[Groups([
'user:collection:post',
'user:item:get',
'user:item:put',
])]
#[MaxDepth(1)]
private $broker;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'brokers')]
#[Groups([
'broker:item:get',
])]
private $user;
#[ApiProperty()]
#[Groups([
'broker:item:get',
])]
private $userIdentifier;
#[ApiProperty()]
#[Groups([
'broker:item:get',
])]
private $roles;
#[ApiProperty()]
#[Groups([
'broker:item:get',
])]
private $avatar;
public function getId(): ?int
{
return $this->id;
}
public function getBroker(): ?Broker
{
return $this->broker;
}
public function setBroker(?Broker $broker): self
{
$this->broker = $broker;
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 getRoles(): array
{
return $this->getUser()->getRoles();
}
public function getAvatar(): ?string
{
return $this->getUser()->getAvatar() ? $this->getUser()->getAvatar()->getContentUrl() : false;
}
}