<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
/**
* An organization such as a school, NGO, corporation, club, etc.
*
* @see https://schema.org/Organization
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Channel',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'channel:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'channel:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'channel:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['channel:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'channel:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'channel:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'taxID' => 'start',
'name' => 'partial',
'legalName' => 'partial',
'createdAt' => 'start',
'type' => 'exact',
'broker' => 'exact',
])]
#[ApiFilter(OrderFilter::class, properties: [
'name',
'taxID',
'legalName',
'createdAt'
])]
class Channel
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'channel:collection:get',
'channel:item:get',
'user:collection:post',
'user:item:put',
'broker:item:get',
])]
private ?int $id = null;
/**
* The name of the item.
*
* @see https://schema.org/name
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\Type('string')]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
'user:item:get',
'broker:item:get',
])]
private ?string $name = null;
/**
* Email address.
*
* @see https://schema.org/email
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/email')]
#[Assert\Email]
#[Groups([
'channel:collection:post',
'channel:item:get',
'channel:item:put',
])]
private ?string $email = null;
/**
* The official name of the organization, e.g. the registered company name.
*
* @see https://schema.org/legalName
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/legalName')]
#[Assert\Type('string')]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
])]
private ?string $legalName = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
])]
private ?string $taxIDType = null;
/**
* The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
*
* @see https://schema.org/taxID
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/taxID')]
#[Assert\Type('string')]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
'user:item:get',
'broker:item:get',
])]
private ?string $taxID = null;
/**
* The telephone number.
*
* @see https://schema.org/telephone
*/
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/telephone')]
#[Assert\Type('string')]
#[Groups([
'channel:collection:post',
'channel:item:get',
'channel:item:put',
])]
private ?string $telephone = null;
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
'user:item:get',
'broker:item:get',
])]
private ?string $type = null;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelUser::class)]
#[Groups([
'channel:item:get',
])]
#[MaxDepth(1)]
private $users;
#[ORM\ManyToOne(targetEntity: Broker::class, inversedBy: 'channels')]
#[ApiProperty()]
#[Groups([
'channel:collection:get',
'channel:collection:post',
'channel:item:get',
'channel:item:put',
])]
#[MaxDepth(1)]
private $broker;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setName(?string $name): void
{
$this->name = $name;
}
public function getName(): ?string
{
return $this->name;
}
public function setEmail(?string $email): void
{
$this->email = $email;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setLegalName(?string $legalName): void
{
$this->legalName = $legalName;
}
public function getLegalName(): ?string
{
return $this->legalName;
}
public function setTaxID(?string $taxID): void
{
$this->taxID = $taxID;
}
public function getTaxID(): ?string
{
return $this->taxID;
}
public function setTaxIDType(?string $taxIDType): void
{
$this->taxIDType = $taxIDType;
}
public function getTaxIDType(): ?string
{
return $this->taxIDType;
}
public function setTelephone(?string $telephone): void
{
$this->telephone = $telephone;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
/**
* @return Collection|ChannelUser[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(ChannelUser $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setChannel($this);
}
return $this;
}
public function removeUser(ChannelUser $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getChannel() === $this) {
$user->setChannel(null);
}
}
return $this;
}
public function getBroker(): ?Broker
{
return $this->broker;
}
public function setBroker(?Broker $broker): self
{
$this->broker = $broker;
return $this;
}
/**
* @param string|null $type
*/
public function setType(?string $type): void
{
$this->type = $type;
}
public function getType(): ?string
{
return $this->type;
}
}