src/Entity/Language.php line 69

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Interfaces\ContainerMappedInterface;
  5. use App\Repository\LanguageRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Traits\TimestampableEntity;
  8. use ApiPlatform\Core\Annotation\ApiFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. /**
  15.  * @ApiResource(
  16.  *      attributes={"security"="is_granted('ROLE_OPERATOR')"},
  17.  *      normalizationContext={"groups"={"Language:Read"}, "skip_null_values"=false},
  18.  *      denormalizationContext={"groups"={"Language:Write"}},
  19.  *      collectionOperations={
  20.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  21.  *          "get_global_all"={
  22.  *              "path"="/languages/get-global-all",
  23.  *              "method"="GET",
  24.  *              "pagination_enabled"=false,
  25.  *              "normalization_context"={"groups"={"Language:GlobalAll"}, "skip_null_values"=false},
  26.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  27.  *          },
  28.  *          "get_global_all_by_client"={
  29.  *              "path"="/languages/get-global-all-by-client",
  30.  *              "method"="GET",
  31.  *              "pagination_enabled"=false,
  32.  *              "normalization_context"={"groups"={"Language:GlobalAll"}, "skip_null_values"=false},
  33.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  34.  *          },
  35.  *          "get_for_public_page"={
  36.  *              "route_name"="api_pub_languages_get_for_public_page_collection",
  37.  *              "method"="GET",
  38.  *              "security"="is_granted('PUBLIC_ACCESS')",
  39.  *              "normalization_context"={"groups"={"Language:PRead"}, "skip_null_values"=false},
  40.  *              "pagination_enabled"=false
  41.  *          },
  42.  *          "post"
  43.  *      },
  44.  *      itemOperations={
  45.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  46.  *          "put"={"security"="is_granted('IS_CO_OPR', object)"},
  47.  *          "patch"={"security"="is_granted('IS_CO_OPR', object)"},
  48.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"},
  49.  *          "patch_set_default"={
  50.  *              "route_name"="api_language_set_default_collection",
  51.  *              "method"="PATCH",
  52.  *              "denormalization_context"={"groups"={"Language:SetDefault"}},
  53.  *              "security"="is_granted('IS_CO_OPR', object)"
  54.  *          },
  55.  *     }
  56.  * )
  57.  * @ApiFilter(SearchFilter::class, properties={"container.client.id": "exact", "container.id": "exact", "name": "partial"})
  58.  * @ApiFilter(OrderFilter::class, properties={"id", "isDefault": "DESC", "name"})
  59.  * @ORM\Entity(repositoryClass=LanguageRepository::class)
  60.  * @UniqueEntity(
  61.  *     fields={"container", "name", "locale"},
  62.  *     errorPath="name"
  63.  * )
  64.  * @ORM\Table(name="language",indexes={@ORM\Index(name="language_search_idx", columns={"name"})})
  65.  */
  66. class Language implements ContainerMappedInterface
  67. {
  68.     /**
  69.      * Hook timestampable behavior
  70.      * updates createdAt, updatedAt fields
  71.      */
  72.     use TimestampableEntity;
  73.     /**
  74.      * @ORM\Id
  75.      * @ORM\GeneratedValue
  76.      * @ORM\Column(type="integer")
  77.      * @Groups({"Language:Read", "Container:MyContainer", "Client:MyClient"})
  78.      */
  79.     private $id;
  80.     /**
  81.      * @ORM\Column(type="string", length=64)
  82.      * @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient", "Language:PRead"})
  83.      * @Assert\NotBlank(message="validation.language:name.notBlank")
  84.      * @Assert\Length(
  85.      *      min = 2,
  86.      *      max = 64,
  87.      *      minMessage="validation.language:name.min",
  88.      *      maxMessage="validation.language:name.max",
  89.      * )
  90.      */
  91.     private $name;
  92.     /**
  93.      * @ORM\Column(type="boolean", nullable=true)
  94.      * @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient"})
  95.      * @Assert\Type(type="bool", message="validation.language:isActive.typeBool")
  96.      */
  97.     private $isActive;
  98.     /**
  99.      * @ORM\Column(type="boolean", nullable=true)
  100.      * @Groups({"Language:Read", "Container:MyContainer", "Client:MyClient"})
  101.      * @Assert\Type(type="bool", message="validation.language:isDefault.typeBool")
  102.      */
  103.     private $isDefault false;
  104.     /**
  105.      * @ORM\Column(type="string", length=16)
  106.      * @Groups({"Language:Read", "Language:Write", "Container:MyContainer", "Client:MyClient", "Language:GlobalAll", "Language:PRead"})
  107.      * @Assert\NotBlank(message="validation.language:locale.notBlank")
  108.      * @Assert\Length(
  109.      *      min = 2,
  110.      *      max = 16,
  111.      *      minMessage="validation.language:locale.min",
  112.      *      maxMessage="validation.language:locale.max",
  113.      * )
  114.      */
  115.     private $locale;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity=Container::class, inversedBy="languages")
  118.      * @Groups({"Language:Read", "Language:Write"})
  119.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  120.      */
  121.     private $container;
  122.     public function getId(): ?int
  123.     {
  124.         return $this->id;
  125.     }
  126.     public function getName(): ?string
  127.     {
  128.         return $this->name;
  129.     }
  130.     public function setName(string $name): self
  131.     {
  132.         $this->name $name;
  133.         return $this;
  134.     }
  135.     public function getIsActive(): ?bool
  136.     {
  137.         return $this->isActive;
  138.     }
  139.     public function setIsActive(?bool $isActive): self
  140.     {
  141.         $this->isActive $isActive;
  142.         return $this;
  143.     }
  144.     public function getIsDefault(): ?bool
  145.     {
  146.         return $this->isDefault;
  147.     }
  148.     public function setIsDefault(?bool $isDefault): self
  149.     {
  150.         $this->isDefault $isDefault;
  151.         return $this;
  152.     }
  153.     public function getLocale(): ?string
  154.     {
  155.         return $this->locale;
  156.     }
  157.     public function setLocale(string $locale): self
  158.     {
  159.         $this->locale $locale;
  160.         return $this;
  161.     }
  162.     public function getContainer(): ?Container
  163.     {
  164.         return $this->container;
  165.     }
  166.     public function setContainer(?Container $container): self
  167.     {
  168.         $this->container $container;
  169.         return $this;
  170.     }
  171. }