src/Entity/EducationLevel.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\EducationLevelRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. #[ApiResource(
  15.     attributes: ['security' => "is_granted('ROLE_USER')"],
  16.     collectionOperations: [
  17.         'get',
  18.         'post' => ['security' => "is_granted('ROLE_ADMIN')"],
  19.     ],
  20.     itemOperations: [
  21.         'get',
  22.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  23.     ],
  24. )]
  25. #[ApiFilter(PropertyFilter::class)]
  26. #[ApiFilter(SearchFilter::class, properties: ['id''name' => 'partial'])]
  27. #[ApiFilter(OrderFilter::class, properties: ['id''name'], arguments: ['orderParameterName' => 'order'])]
  28. class EducationLevel
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(type="string", length=128)
  38.      * @Assert\NotBlank()
  39.      * @Assert\Length(max=128)
  40.      */
  41.     private $name;
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): ?string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function __toString(): string
  56.     {
  57.         return $this->getName();
  58.     }
  59. }