src/Entity/Affectation.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  4. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  5. use ApiPlatform\Metadata\ApiFilter;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Delete;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use App\Controller\Action\AffectationController;
  13. use App\Controller\Action\AffectationListController;
  14. use App\Controller\Action\DesaffectDocumentsSiteAction;
  15. use App\Filter\AffectationOrderFilter;
  16. use App\Traits\AutoTimestampTrait;
  17. use Doctrine\DBAL\Types\Types;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. #[ORM\Table(name'affectation')]
  21. #[ORM\Index(name'document_id'columns: ['document_id'])]
  22. #[ORM\Index(name'site_id'columns: ['site_id'])]
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     normalizationContext: ['skip_null_values'=> false'groups' => ['document.affectation.get''affectation.get''document.get']],
  26.     denormalizationContext: ['skip_null_values'=> false,'groups' => ['document.write']],
  27.     paginationEnabledfalse,
  28.     operations: [
  29.         new GetCollection(),
  30.         new GetCollection(
  31.             name'_api_/affectations_list',
  32.             uriTemplate'/affectations_list',
  33.             controllerAffectationListController::class,
  34.             writefalse,
  35.             readfalse
  36.         ),
  37.         new Post(
  38.             name'_api_/affecations/documents_report',
  39.             uriTemplate'/affectations/documents_report',
  40.             controllerAffectationController::class,
  41.             writefalse,
  42.             readfalse
  43.         ),
  44.         new Post(
  45.             security'user.isMasterAdmin()',
  46.         ),
  47.         new Post(
  48.             name'_api_/desaffecation_documents/site',
  49.             uriTemplate'/desaffecation_documents/site',
  50.             controllerDesaffectDocumentsSiteAction::class,
  51.             writefalse,
  52.             readfalse
  53.         ),
  54.         new Get(),
  55.         new Put(
  56.             security'user.isMasterAdmin()',
  57.         ),
  58.         new Delete(
  59.             security'user.isMasterAdmin()',
  60.         ),
  61.     ]
  62. )]
  63. #[ApiFilter(
  64.     SearchFilter::class, properties: [
  65.         'document' => 'exact',
  66.         'site' => 'exact',
  67.         'isApplicable' => 'exact',
  68.     ]
  69. )]
  70. #[ApiFilter(AffectationOrderFilter::class)]
  71. #[ORM\HasLifecycleCallbacks]
  72. class Affectation
  73. {
  74.     use AutoTimestampTrait;
  75.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  76.     #[ORM\Id]
  77.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  78.     #[Groups(['site.get','site.write','document.affectation.get','document.write''affectation.get'])]
  79.     private int $id;
  80.     #[ORM\Column(name'is_applicable'type'boolean')]
  81.     #[Groups(['site.get','site.write','document.affectation.get','document.write''affectation.get'])]
  82.     private bool $isApplicable true;
  83.     #[ORM\ManyToOne(inversedBy'affectations')]
  84.     #[ORM\JoinColumn(nullablefalse)]
  85.     #[Groups(['site.get','site.write','document.write''affectation.get'])]
  86.     private ?Document $document;
  87.     #[ORM\ManyToOne(inversedBy'affectations')]
  88.     #[ORM\JoinColumn(nullablefalse)]
  89.     #[Groups(['site.write','document.affectation.get','document.write','document.get''affectation.get'])]
  90.     private ?Site $site;
  91.     #[ORM\ManyToOne(inversedBy'affectations')]
  92.     #[Groups(['site.write','document.affectation.get','document.write','document.get''affectation.get'])]
  93.     private ?User $createdBy null;
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function isIsApplicable(): bool
  99.     {
  100.         return $this->isApplicable;
  101.     }
  102.     public function setIsApplicable(bool $isApplicable): self
  103.     {
  104.         $this->isApplicable $isApplicable;
  105.         return $this;
  106.     }
  107.     public function getDocument(): Document
  108.     {
  109.         return $this->document;
  110.     }
  111.     public function setDocument(Document $document=null): self
  112.     {
  113.         $this->document $document;
  114.         return $this;
  115.     }
  116.     public function getSite(): Site
  117.     {
  118.         return $this->site;
  119.     }
  120.     public function setSite(Site $site=null): self
  121.     {
  122.         $this->site $site;
  123.         return $this;
  124.     }
  125.     public function getCreatedBy(): ?User
  126.     {
  127.         return $this->createdBy;
  128.     }
  129.     public function setCreatedBy(?User $createdBy): self
  130.     {
  131.         $this->createdBy $createdBy;
  132.         return $this;
  133.     }
  134. }