src/Evo/Infrastructure/MappingORM/Document.php line 55

Open in your IDE?
  1. <?php
  2. namespace Evo\Infrastructure\MappingORM;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  10. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  11. use App\Controller\Api\CreateOrUpdateDocumentAction;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\HttpFoundation\File\File;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\MaxDepth;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  20. /**
  21.  * @ApiResource(
  22.  *     attributes={
  23.  *         "normalization_context"={"groups"={"read_document", "admin:doc:list"}},
  24.  *         "denormalization_context"={"groups"={"write_document"}}
  25.  *     },
  26.  *     collectionOperations={
  27.  *         "post"={
  28.  *             "controller"=CreateOrUpdateDocumentAction::class,
  29.  *             "deserialize"=false,
  30.  *         },
  31.  *         "get"
  32.  *     },
  33.  *     itemOperations={
  34.  *      "get",
  35.  *      "put"={
  36.  *          "controller"=CreateOrUpdateDocumentAction::class,
  37.  *          "deserialize"=false,
  38.  *      },
  39.  *      "delete"={"security"="is_granted('ROLE_ADMIN')"}
  40.  *      }
  41.  *  )
  42.  * @ORM\Entity
  43.  * @ORM\Table(name="document")
  44.  * @Vich\Uploadable
  45.  * @ApiFilter(OrderFilter::class, properties={"id", "createdAt", "signedBy", "status"}, arguments={"orderParameterName"="order"})
  46.  * @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true})
  47.  * @ApiFilter(SearchFilter::class, properties={"person": "exact", "organization": "exact", "organization.status": "exact", "potentialCase.id": "exact", "status": "exact", "type":"exact", "person.legalRepresentatives.organizations.id": "exact"})
  48.  * @ApiFilter(PropertyFilter::class)
  49.  * @ApiFilter(ExistsFilter::class, properties={"signedBy", "signature", "rejectionMessage"})
  50.  * @ORM\Entity(repositoryClass="App\Repository\DocumentRepository")
  51.  */
  52. class Document
  53. {
  54.     /**
  55.      * @var int The entity Id
  56.      *
  57.      * @ORM\Column(type="integer")
  58.      * @ORM\Id
  59.      * @ORM\GeneratedValue()
  60.      * @Groups({"read_document", "admin:doc:list", "read_organization","read_person","legal_representative", "associate"})
  61.      */
  62.     private ?int $id null;
  63.     /**
  64.      * @Groups({"read_document", "admin:doc:list", "write_document", "read_organization", "associate"})
  65.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="documents")
  66.      * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", nullable=true)
  67.      */
  68.     private ?Organization $organization null;
  69.     /**
  70.      * @var string The document name
  71.      *
  72.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  73.      * @ORM\Column(type="string", nullable=true)
  74.      * @Assert\NotBlank()
  75.      */
  76.     private ?string $name null;
  77.     /**
  78.      * @var string The document type
  79.      *
  80.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  81.      * @ORM\Column(type="string", length=50)
  82.      * @Assert\NotBlank()
  83.      */
  84.     private ?string $type null;
  85.     /**
  86.      * @var string The document status
  87.      *
  88.      * @Assert\Choice(callback={"App\Enum\DocumentStatusEnum", "getChoices"})
  89.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  90.      * @ORM\Column(type="string", length=20, nullable=true)
  91.      * @Assert\NotBlank()
  92.      */
  93.     private ?string $status null;
  94.     /**
  95.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  96.      * @ORM\Column(type="text", nullable=true)
  97.      */
  98.     private ?string $reasonNotApproved null;
  99.     /**
  100.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  101.      *
  102.      * @Vich\UploadableField(mapping="document", fileNameProperty="path")
  103.      * @Assert\File(
  104.      *     maxSize = "5M",
  105.      *     mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
  106.      *     mimeTypesMessage = "error.vivh.format.imagePdf"
  107.      * )
  108.      */
  109.     private ?File $documentFile null;
  110.     /**
  111.      * @var string The document file path
  112.      *
  113.      * @ApiProperty(writable=false)
  114.      * @Groups({"read_document", "admin:doc:list", "read_organization","read_person","legal_representative", "associate"})
  115.      * @ORM\Column(type="string", nullable=true)
  116.      */
  117.     private ?string $path null;
  118.     /**
  119.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  120.      * @ORM\Column(type="datetime", nullable=true)
  121.      */
  122.     private ?\DateTimeInterface $expirationDate null;
  123.     /**
  124.      * @var \DateTimeInterface
  125.      *
  126.      * @Groups({"read_document", "admin:doc:list", "read_organization", "associate"})
  127.      * @ORM\Column(type="datetime")
  128.      */
  129.     private $createdAt;
  130.     /**
  131.      * @Groups({"read_document", "write_organization", "read_organization", "write_document", "associate"})
  132.      * @MaxDepth(1)
  133.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\DocumentRejectionMessage", cascade={"persist"})
  134.      * @ORM\JoinColumn(nullable=true)
  135.      */
  136.     private ?DocumentRejectionMessage $rejectionMessage null;
  137.     /**
  138.      * @Groups({"read_document", "admin:doc:list", "write_document", "read_organization","read_person", "associate"})
  139.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Person", inversedBy="documents", cascade={"persist"})
  140.      */
  141.     private ?Person $person null;
  142.     /**
  143.      * @ApiProperty(writable=false)
  144.      * @Groups({"read_document", "admin:doc:list", "read_organization","read_person", "associate"})
  145.      * @ORM\Column(type="string", length=255, nullable=true)
  146.      */
  147.     private ?string $awsPath null;
  148.     /**
  149.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  150.      * @ORM\ManyToMany(targetEntity="Evo\Infrastructure\MappingORM\ProcessYousign", mappedBy="documents", cascade={"persist"})
  151.      */
  152.     private ?Collection $processYousigns;
  153.     /**
  154.      * @Assert\Choice(callback={"App\Enum\SignatoryEnum", "getChoices"})
  155.      * @Groups({"read_document", "admin:doc:list", "write_document", "read_organization","read_person"})
  156.      * @ORM\Column(type="string", length=255, nullable=true)
  157.      */
  158.     private ?string $signedBy null;
  159.     /**
  160.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative"})
  161.      * @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Signature", mappedBy="document", cascade={"persist","remove"})
  162.      */
  163.     private ?Collection $signature;
  164.     /**
  165.      * @Groups({"admin:doc:list"})
  166.      * @ORM\Column(type="text", nullable=true)
  167.      */
  168.     private ?string $yousignLink null;
  169.     /**
  170.      * @Groups({"read_document", "write_document", "admin:doc:list", "read_organization", "read_person"})
  171.      * @ORM\Column(type="datetime", nullable=true)
  172.      */
  173.     private ?\DateTimeInterface $awaitingValidationDate null;
  174.     /**
  175.      * @ORM\Column(type="string", length=255, nullable=true)
  176.      */
  177.     private ?string $yousignError null;
  178.     /**
  179.      * @Groups({"read_document", "admin:doc:list"})
  180.      * @ORM\Column(type="text", nullable=true)
  181.      */
  182.     private ?string $htmlDocument null;
  183.     /**
  184.      * @Groups({"read_document","write_document", "admin:doc:list"})
  185.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\PotentialCase", inversedBy="documents")
  186.      */
  187.     private ?PotentialCase $potentialCase null;
  188.     /**
  189.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  190.      * @ORM\Column(type="string", length=255, nullable=true)
  191.      */
  192.     private ?string $label null;
  193.     /**
  194.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  195.      * @ORM\Column(type="string", length=255, nullable=true)
  196.      */
  197.     private ?string $rejectionMessageTitle null;
  198.     /**
  199.      * @Groups({"read_document", "admin:doc:list", "write_document", "write_organization", "read_organization","read_person","legal_representative", "associate"})
  200.      * @ORM\Column(type="text", nullable=true)
  201.      */
  202.     private ?string $rejectionMessageDescription null;
  203.     /**
  204.      * @Groups({"read_document"})
  205.      * @ORM\Column(type="boolean", options={"default": false})
  206.      */
  207.     private bool $isFromPappers false;
  208.     private bool $temporaryFileForPappers false;
  209.     private bool $bypassSubscriber false;
  210.     public function __construct()
  211.     {
  212.         $this->processYousigns = new ArrayCollection();
  213.         $this->signature = new ArrayCollection();
  214.         $this->createdAt = new \DateTime();
  215.     }
  216.     public function __toString()
  217.     {
  218.         return ('' !== $this->name && '0' !== $this->name) ? $this->getName() : 'Document';
  219.     }
  220.     public function getName(): ?string
  221.     {
  222.         return $this->name;
  223.     }
  224.     public function setName(string $name): Document
  225.     {
  226.         $this->name $name;
  227.         return $this;
  228.     }
  229.     public function getId(): ?int
  230.     {
  231.         return $this->id;
  232.     }
  233.     public function resetId()
  234.     {
  235.         $this->id null;
  236.         return $this;
  237.     }
  238.     public function getOrganization(): ?Organization
  239.     {
  240.         return $this->organization;
  241.     }
  242.     public function setOrganization(?Organization $organization): Document
  243.     {
  244.         $this->organization $organization;
  245.         return $this;
  246.     }
  247.     public function getType(): string
  248.     {
  249.         return $this->type;
  250.     }
  251.     public function setType(string $type): Document
  252.     {
  253.         $this->type $type;
  254.         return $this;
  255.     }
  256.     public function getStatus(): ?string
  257.     {
  258.         return $this->status;
  259.     }
  260.     public function setStatus(?string $status): Document
  261.     {
  262.         $this->status $status;
  263.         return $this;
  264.     }
  265.     public function getReasonNotApproved(): ?string
  266.     {
  267.         return $this->reasonNotApproved;
  268.     }
  269.     public function setReasonNotApproved(?string $reasonNotApproved): Document
  270.     {
  271.         $this->reasonNotApproved $reasonNotApproved;
  272.         return $this;
  273.     }
  274.     public function getDocumentFile(): ?File
  275.     {
  276.         return $this->documentFile;
  277.     }
  278.     public function setDocumentFile(?File $documentFile): Document
  279.     {
  280.         $this->documentFile $documentFile;
  281.         return $this;
  282.     }
  283.     public function getPath(): ?string
  284.     {
  285.         return $this->path;
  286.     }
  287.     public function setPath(?string $path): Document
  288.     {
  289.         $this->path $path;
  290.         return $this;
  291.     }
  292.     public function getExpirationDate(): ?\DateTimeInterface
  293.     {
  294.         return $this->expirationDate;
  295.     }
  296.     public function setExpirationDate(?\DateTimeInterface $expirationDate): Document
  297.     {
  298.         $this->expirationDate $expirationDate;
  299.         return $this;
  300.     }
  301.     public function getCreatedAt(): ?\DateTimeInterface
  302.     {
  303.         return $this->createdAt;
  304.     }
  305.     public function setCreatedAt(\DateTimeInterface $createdAt): Document
  306.     {
  307.         $this->createdAt $createdAt;
  308.         return $this;
  309.     }
  310.     public function getRejectionMessage(): ?DocumentRejectionMessage
  311.     {
  312.         return $this->rejectionMessage;
  313.     }
  314.     public function setRejectionMessage(?DocumentRejectionMessage $rejectionMessage): self
  315.     {
  316.         $this->rejectionMessage $rejectionMessage;
  317.         return $this;
  318.     }
  319.     public function getPerson(): ?Person
  320.     {
  321.         return $this->person;
  322.     }
  323.     public function setPerson(?Person $person): self
  324.     {
  325.         $this->person $person;
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection|ProcessYousign[]
  330.      */
  331.     public function getProcessYousigns(): Collection
  332.     {
  333.         return $this->processYousigns;
  334.     }
  335.     public function addProcessYousign(ProcessYousign $processYousign): self
  336.     {
  337.         if (!$this->processYousigns->contains($processYousign)) {
  338.             $this->processYousigns[] = $processYousign;
  339.             $processYousign->addDocument($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeProcessYousign(ProcessYousign $processYousign): self
  344.     {
  345.         if ($this->processYousigns->contains($processYousign)) {
  346.             $this->processYousigns->removeElement($processYousign);
  347.             $processYousign->removeDocument($this);
  348.         }
  349.         return $this;
  350.     }
  351.     public function getSignedBy(): ?string
  352.     {
  353.         return $this->signedBy;
  354.     }
  355.     public function setSignedBy(?string $signedBy): self
  356.     {
  357.         $this->signedBy $signedBy;
  358.         return $this;
  359.     }
  360.     /**
  361.      * @return Collection|Signature[]
  362.      */
  363.     public function getSignature(): Collection
  364.     {
  365.         return $this->signature;
  366.     }
  367.     public function addSignature(Signature $signature): self
  368.     {
  369.         if (!$this->signature->contains($signature)) {
  370.             $this->signature[] = $signature;
  371.             $signature->setDocument($this);
  372.         }
  373.         return $this;
  374.     }
  375.     public function removeSignature(Signature $signature): self
  376.     {
  377.         if ($this->signature->contains($signature)) {
  378.             $this->signature->removeElement($signature);
  379.             // set the owning side to null (unless already changed)
  380.             if ($signature->getDocument() === $this) {
  381.                 $signature->setDocument(null);
  382.             }
  383.         }
  384.         return $this;
  385.     }
  386.     public function getExtension()
  387.     {
  388.         if ($this->getAwsPath()) {
  389.             $tmp explode('.'$this->getAwsPath());
  390.             return (isset($tmp[0])) ? end($tmp) : null;
  391.         }
  392.         return null;
  393.     }
  394.     public function getAwsPath(): ?string
  395.     {
  396.         return $this->awsPath;
  397.     }
  398.     public function setAwsPath(?string $awsPath): self
  399.     {
  400.         $this->awsPath $awsPath;
  401.         return $this;
  402.     }
  403.     public function getYousignLink(): ?string
  404.     {
  405.         return $this->yousignLink;
  406.     }
  407.     public function setYousignLink(?string $yousignLink): self
  408.     {
  409.         $this->yousignLink $yousignLink;
  410.         return $this;
  411.     }
  412.     public function getAwaitingValidationDate(): ?\DateTimeInterface
  413.     {
  414.         return $this->awaitingValidationDate;
  415.     }
  416.     public function setAwaitingValidationDate(?\DateTimeInterface $awaitingValidationDate): self
  417.     {
  418.         $this->awaitingValidationDate $awaitingValidationDate;
  419.         return $this;
  420.     }
  421.     public function getYousignError(): ?string
  422.     {
  423.         return $this->yousignError;
  424.     }
  425.     public function setYousignError(?string $yousignError): self
  426.     {
  427.         $this->yousignError $yousignError;
  428.         return $this;
  429.     }
  430.     public function getHtmlDocument(): ?string
  431.     {
  432.         return $this->htmlDocument;
  433.     }
  434.     public function setHtmlDocument(?string $htmlDocument): self
  435.     {
  436.         $this->htmlDocument $htmlDocument;
  437.         return $this;
  438.     }
  439.     public function getPotentialCase(): ?PotentialCase
  440.     {
  441.         return $this->potentialCase;
  442.     }
  443.     public function setPotentialCase(?PotentialCase $potentialCase): self
  444.     {
  445.         $this->potentialCase $potentialCase;
  446.         return $this;
  447.     }
  448.     public function getLabel(): ?string
  449.     {
  450.         return $this->label;
  451.     }
  452.     public function setLabel(?string $label): self
  453.     {
  454.         $this->label $label;
  455.         return $this;
  456.     }
  457.     public function getIsFromPappers(): bool
  458.     {
  459.         return $this->isFromPappers;
  460.     }
  461.     public function setIsFromPappers(bool $isFromPappers): self
  462.     {
  463.         $this->isFromPappers $isFromPappers;
  464.         return $this;
  465.     }
  466.     public function isDocumentOfPerson(): bool
  467.     {
  468.         return null !== $this->getPerson();
  469.     }
  470.     public function isDocumentOfOrganization(): bool
  471.     {
  472.         return null !== $this->getOrganization();
  473.     }
  474.     public function isTemporaryFileForPappers(): bool
  475.     {
  476.         return $this->temporaryFileForPappers;
  477.     }
  478.     public function setTemporaryFileForPappers(bool $temporaryFileForPappers): self
  479.     {
  480.         $this->temporaryFileForPappers $temporaryFileForPappers;
  481.         return $this;
  482.     }
  483.     public function isBypassSubscriber(): bool
  484.     {
  485.         return $this->bypassSubscriber;
  486.     }
  487.     public function setBypassSubscriber(bool $bypassSubscriber): self
  488.     {
  489.         $this->bypassSubscriber $bypassSubscriber;
  490.         return $this;
  491.     }
  492.     public function getRejectionMessageDescription(): ?string
  493.     {
  494.         return $this->rejectionMessageDescription;
  495.     }
  496.     public function setRejectionMessageDescription(?string $rejectionMessageDescription): self
  497.     {
  498.         $this->rejectionMessageDescription $rejectionMessageDescription;
  499.         return $this;
  500.     }
  501.     public function getRejectionMessageTitle(): ?string
  502.     {
  503.         return $this->rejectionMessageTitle;
  504.     }
  505.     public function setRejectionMessageTitle(?string $rejectionMessageTitle): self
  506.     {
  507.         $this->rejectionMessageTitle $rejectionMessageTitle;
  508.         return $this;
  509.     }
  510.     public static function create(array $data): Document
  511.     {
  512.         return (new self())
  513.             ->setType($data['type'])
  514.             ->setIsFromPappers($data['isFromPappers'])
  515.             ->setOrganization($data['organization'] ?? null)
  516.             ->setExpirationDate($data['expirationDate'] ?? null)
  517.             ->setStatus($data['status'])
  518.             ->setPath($data['path'] ?? null)
  519.             ->setPerson($data['person'] ?? null)
  520.             ->setSignedBy($data['signedBy'] ?? null)
  521.             ->setTemporaryFileForPappers($data['temporaryFileForPappers'] ?? false)
  522.         ;
  523.     }
  524.     public function resetDocumentRejectionMessage(): self
  525.     {
  526.         $this->rejectionMessageTitle null;
  527.         $this->rejectionMessageDescription null;
  528.         return $this;
  529.     }
  530. }