<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CompanyTagRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\ClientMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"CompanyTag:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"CompanyTag:Write"}},
* collectionOperations={
* "post",
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "get_for_public_page"={
* "route_name"="api_pub_company_tags_get_for_public_page_collection",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"CompanyTag:PRead"}, "skip_null_values"=false}
* }
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "put"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "patch"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "delete"={"security"="is_granted('IS_CLIENT_OWNER', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"name": "partial", "client.id": "exact"})
* @ApiFilter(OrderFilter::class, properties={"id": "ASC", "name"})
* @ORM\Entity(repositoryClass=CompanyTagRepository::class)
* @UniqueEntity(
* fields={"client", "name"},
* errorPath="name"
* )
*/
class CompanyTag implements ClientMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"CompanyTag:Read", "Company:Read", "CompanyTag:PRead", "Company:PRead"})
*/
private $id;
/**
* @ORM\Column(type="string", length=64)
* @Groups({"CompanyTag:Read", "CompanyTag:Write", "Company:Read", "Company:Write", "CompanyTag:PRead", "Company:PRead"})
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity=Company::class, inversedBy="companyTags")
* @Groups({"CompanyTag:Write", "Company:Write"})
*/
private $companies;
/**
* @ORM\ManyToOne(targetEntity=Client::class)
* @ORM\JoinColumn(nullable=false)
* @Groups({"CompanyTag:Write"})
*/
private $client;
public function __construct()
{
$this->companies = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
}
return $this;
}
public function removeCompany(Company $company): self
{
$this->companies->removeElement($company);
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
}