<?php
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Action\AffectationController;
use App\Controller\Action\AffectationListController;
use App\Controller\Action\DesaffectDocumentsSiteAction;
use App\Filter\AffectationOrderFilter;
use App\Traits\AutoTimestampTrait;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Table(name: 'affectation')]
#[ORM\Index(name: 'document_id', columns: ['document_id'])]
#[ORM\Index(name: 'site_id', columns: ['site_id'])]
#[ORM\Entity]
#[ApiResource(
normalizationContext: ['skip_null_values'=> false, 'groups' => ['document.affectation.get', 'affectation.get', 'document.get']],
denormalizationContext: ['skip_null_values'=> false,'groups' => ['document.write']],
paginationEnabled: false,
operations: [
new GetCollection(),
new GetCollection(
name: '_api_/affectations_list',
uriTemplate: '/affectations_list',
controller: AffectationListController::class,
write: false,
read: false
),
new Post(
name: '_api_/affecations/documents_report',
uriTemplate: '/affectations/documents_report',
controller: AffectationController::class,
write: false,
read: false
),
new Post(
security: 'user.isMasterAdmin()',
),
new Post(
name: '_api_/desaffecation_documents/site',
uriTemplate: '/desaffecation_documents/site',
controller: DesaffectDocumentsSiteAction::class,
write: false,
read: false
),
new Get(),
new Put(
security: 'user.isMasterAdmin()',
),
new Delete(
security: 'user.isMasterAdmin()',
),
]
)]
#[ApiFilter(
SearchFilter::class, properties: [
'document' => 'exact',
'site' => 'exact',
'isApplicable' => 'exact',
]
)]
#[ApiFilter(AffectationOrderFilter::class)]
#[ORM\HasLifecycleCallbacks]
class Affectation
{
use AutoTimestampTrait;
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[Groups(['site.get','site.write','document.affectation.get','document.write', 'affectation.get'])]
private int $id;
#[ORM\Column(name: 'is_applicable', type: 'boolean')]
#[Groups(['site.get','site.write','document.affectation.get','document.write', 'affectation.get'])]
private bool $isApplicable = true;
#[ORM\ManyToOne(inversedBy: 'affectations')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['site.get','site.write','document.write', 'affectation.get'])]
private ?Document $document;
#[ORM\ManyToOne(inversedBy: 'affectations')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['site.write','document.affectation.get','document.write','document.get', 'affectation.get'])]
private ?Site $site;
#[ORM\ManyToOne(inversedBy: 'affectations')]
#[Groups(['site.write','document.affectation.get','document.write','document.get', 'affectation.get'])]
private ?User $createdBy = null;
public function getId(): ?int
{
return $this->id;
}
public function isIsApplicable(): bool
{
return $this->isApplicable;
}
public function setIsApplicable(bool $isApplicable): self
{
$this->isApplicable = $isApplicable;
return $this;
}
public function getDocument(): Document
{
return $this->document;
}
public function setDocument(Document $document=null): self
{
$this->document = $document;
return $this;
}
public function getSite(): Site
{
return $this->site;
}
public function setSite(Site $site=null): self
{
$this->site = $site;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
}