<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\ContainerMappedInterface;
use App\Repository\LanguageRepository;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Traits\TimestampableEntity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_OPERATOR')"},
* normalizationContext={"groups"={"Language:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"Language:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "get_global_all"={
* "path"="/languages/get-global-all",
* "method"="GET",
* "pagination_enabled"=false,
* "normalization_context"={"groups"={"Language:GlobalAll"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "get_global_all_by_client"={
* "path"="/languages/get-global-all-by-client",
* "method"="GET",
* "pagination_enabled"=false,
* "normalization_context"={"groups"={"Language:GlobalAll"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "get_for_public_page"={
* "route_name"="api_pub_languages_get_for_public_page_collection",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"Language:PRead"}, "skip_null_values"=false},
* "pagination_enabled"=false
* },
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CO_OPR', object)"},
* "put"={"security"="is_granted('IS_CO_OPR', object)"},
* "patch"={"security"="is_granted('IS_CO_OPR', object)"},
* "delete"={"security"="is_granted('IS_CO_OPR', object)"},
* "patch_set_default"={
* "route_name"="api_language_set_default_collection",
* "method"="PATCH",
* "denormalization_context"={"groups"={"Language:SetDefault"}},
* "security"="is_granted('IS_CO_OPR', object)"
* },
* }
* )
* @ApiFilter(SearchFilter::class, properties={"container.client.id": "exact", "container.id": "exact", "name": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id", "isDefault": "DESC", "name"})
* @ORM\Entity(repositoryClass=LanguageRepository::class)
* @UniqueEntity(
* fields={"container", "name", "locale"},
* errorPath="name"
* )
* @ORM\Table(name="language",indexes={@ORM\Index(name="language_search_idx", columns={"name"})})
*/
class Language implements ContainerMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"Language:Read", "Container:MyContainer", "Client:MyClient"})
*/
private $id;
/**
* @ORM\Column(type="string", length=64)
* @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient", "Language:PRead"})
* @Assert\NotBlank(message="validation.language:name.notBlank")
* @Assert\Length(
* min = 2,
* max = 64,
* minMessage="validation.language:name.min",
* maxMessage="validation.language:name.max",
* )
*/
private $name;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient"})
* @Assert\Type(type="bool", message="validation.language:isActive.typeBool")
*/
private $isActive;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"Language:Read", "Container:MyContainer", "Client:MyClient"})
* @Assert\Type(type="bool", message="validation.language:isDefault.typeBool")
*/
private $isDefault = false;
/**
* @ORM\Column(type="string", length=16)
* @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient", "Language:GlobalAll", "Language:PRead"})
* @Assert\NotBlank(message="validation.language:locale.notBlank")
* @Assert\Length(
* min = 2,
* max = 16,
* minMessage="validation.language:locale.min",
* maxMessage="validation.language:locale.max",
* )
*/
private $locale;
/**
* @ORM\ManyToOne(targetEntity=Container::class, inversedBy="languages")
* @Groups({"Language:Read", "Language:Write"})
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $container;
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;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getIsDefault(): ?bool
{
return $this->isDefault;
}
public function setIsDefault(?bool $isDefault): self
{
$this->isDefault = $isDefault;
return $this;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(string $locale): self
{
$this->locale = $locale;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
}