src/Evo/Infrastructure/MappingORM/Letter.php line 65

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\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  12. use App\Controller\Api\CreateOrUpdateLetterAction;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use Symfony\Component\HttpFoundation\File\File;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  21. /**
  22.  * @ApiResource(
  23.  *     attributes={
  24.  *         "normalization_context"={"groups"={"read_letter"}},
  25.  *         "denormalization_context"={"groups"={"write_letter"}}
  26.  *     },
  27.  *     collectionOperations={
  28.  *         "post"={
  29.  *             "controller"=CreateOrUpdateLetterAction::class,
  30.  *         },
  31.  *         "get",
  32.  *     },
  33.  *     itemOperations={
  34.  *          "get",
  35.  *          "put"={
  36.  *              "controller"=CreateOrUpdateLetterAction::class,
  37.  *          },
  38.  *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
  39.  *      }
  40.  *  )
  41.  * @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
  42.  * @ApiFilter(
  43.  *     SearchFilter::class,
  44.  *     properties={
  45.  *          "status": "exact",
  46.  *          "organization": "exact",
  47.  *          "type": "exact",
  48.  *          "organization.status": "exact",
  49.  *          "id": "partial",
  50.  *          "isRead": "exact",
  51.  *          "organization.store": "exact",
  52.  *          "organization.id": "exact"
  53.  * })
  54.  * @ApiFilter(BooleanFilter::class, properties={"isRead", "isScanned", "isImportant", "isArchived"})
  55.  * @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true})
  56.  * @ApiFilter(ExistsFilter::class, properties={"contentUrl"})
  57.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  58.  * @ORM\Entity(repositoryClass="App\Repository\LetterRepository")
  59.  * @ORM\Table(name="letter")
  60.  * @Vich\Uploadable
  61.  */
  62. class Letter
  63. {
  64.     /**
  65.      * @Groups({"read_letter", "read_letter_forward", "admin:read:letter", "read_npai", "admin:filter:letter", "read_letter_signature", "read_letter_tag"})
  66.      * @ORM\Id()
  67.      * @ORM\GeneratedValue()
  68.      * @ORM\Column(type="integer")
  69.      */
  70.     private ?int $id null;
  71.     /**
  72.      * @Groups({"read_letter", "write_letter", "read_letter_forward", "admin:read:letter", "read_letter_signature"})
  73.      * @ORM\Column(type="boolean")
  74.      */
  75.     private $isRead;
  76.     /**
  77.      * @Groups({"read_letter", "write_letter", "read_letter_forward", "admin:read:letter", "read_letter_signature"})
  78.      * @ORM\Column(type="string", length=255)
  79.      */
  80.     private ?string $status null;
  81.     /**
  82.      * @Groups({"read_letter", "admin:read:letter"})
  83.      *
  84.      * @var string The url
  85.      */
  86.     private $envelopeBackUrl;
  87.     /**
  88.      * @Groups({"read_letter", "write_letter","read_zappier_letter", "admin:read:letter"})
  89.      * @ORM\Column(type="string", nullable=true)
  90.      */
  91.     private $contentUrl;
  92.     /**
  93.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  94.      *
  95.      * @Vich\UploadableField(mapping="letter", fileNameProperty="contentPath")
  96.      * @Assert\File(
  97.      *     maxSize = "5M",
  98.      *     mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
  99.      *     mimeTypesMessage = "Please upload a valid Image or PDF file"
  100.      * )
  101.      */
  102.     private ?File $contentFile null;
  103.     /**
  104.      * @var string The content letter file path
  105.      *
  106.      * @ApiProperty(writable=false)
  107.      * @Groups({"read_letter", "admin:read:letter"})
  108.      * @ORM\Column(type="string", nullable=true)
  109.      */
  110.     private ?string $contentPath null;
  111.     /**
  112.      * @Groups({"read_letter", "write_letter", "admin:read:letter", "read_zappier_letter"})
  113.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="letters")
  114.      */
  115.     private ?Organization $organization null;
  116.     /**
  117.      * @Groups({"read_letter","read_zappier_letter", "write_letter", "read_letter_forward", "admin:read:letter", "admin:filter:letter", "read_letter_signature"})
  118.      * @ORM\Column(type="string", length=255)
  119.      */
  120.     private ?string $type null;
  121.     /**
  122.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  123.      *
  124.      * @Vich\UploadableField(mapping="letter", fileNameProperty="envelopeFrontPath")
  125.      * @Assert\File(
  126.      *     maxSize = "5M",
  127.      *     mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
  128.      *     mimeTypesMessage = "Please upload a valid Image or PDF file"
  129.      * )
  130.      */
  131.     private ?File $envelopeFrontFile null;
  132.     /**
  133.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  134.      *
  135.      * @Vich\UploadableField(mapping="letter", fileNameProperty="envelopeBackPath")
  136.      * @Assert\File(
  137.      *     maxSize = "5M",
  138.      *     mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
  139.      *     mimeTypesMessage = "Please upload a valid Image or PDF file"
  140.      * )
  141.      */
  142.     private ?File $envelopeBackFile null;
  143.     /**
  144.      * @var string The envelopeFront letter file path
  145.      *
  146.      * @ApiProperty(writable=false)
  147.      * @Groups({"read_letter", "admin:read:letter"})
  148.      * @ORM\Column(type="string", nullable=true)
  149.      */
  150.     private ?string $envelopeFrontPath null;
  151.     /**
  152.      * @var string The envelopeFront letter file path
  153.      *
  154.      * @ApiProperty(writable=false)
  155.      * @Groups({"read_letter", "admin:read:letter"})
  156.      * @ORM\Column(type="string", nullable=true)
  157.      */
  158.     private ?string $envelopeBackPath null;
  159.     /**
  160.      * @var \DateTime
  161.      *
  162.      * @Groups({"read_letter", "admin:read:letter"})
  163.      * @Gedmo\Timestampable(on="update")
  164.      * @ORM\Column(type="datetime")
  165.      */
  166.     private $updatedAt;
  167.     /**
  168.      * @Groups({"read_letter", "write_letter", "read_zappier_letter", "admin:read:letter"})
  169.      * @ORM\Column(type="datetime")
  170.      */
  171.     private \DateTimeInterface $createdAt;
  172.     /**
  173.      * @Groups({"read_letter", "write_letter", "write_letter_signature", "admin:read:letter"})
  174.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\LetterSignature", inversedBy="letters", cascade={"persist"})
  175.      */
  176.     private ?LetterSignature $letterSignature null;
  177.     /**
  178.      * @Groups({"read_letter", "write_letter", "write_letter_forward", "admin:read:letter"})
  179.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\LetterForward", inversedBy="letters", cascade={"persist"})
  180.      */
  181.     private ?LetterForward $letterForward null;
  182.     /**
  183.      * @ApiProperty(writable=false)
  184.      * @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
  185.      * @ORM\Column(type="string", length=255, nullable=true)
  186.      */
  187.     private ?string $envelopeFrontPathAWS null;
  188.     /**
  189.      * @ApiProperty(writable=false)
  190.      * @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
  191.      * @ORM\Column(type="string", length=255, nullable=true)
  192.      */
  193.     private ?string $envelopeBackPathAWS null;
  194.     /**
  195.      * @ApiProperty(writable=false)
  196.      * @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
  197.      * @ORM\Column(type="string", length=255, nullable=true)
  198.      */
  199.     private ?string $contentPathAWS null;
  200.     /**
  201.      * @Groups({"read_letter", "write_letter", "admin:read:letter"})
  202.      * @ORM\Column(type="boolean", nullable=true)
  203.      */
  204.     private $isScanned;
  205.     /**
  206.      * @Groups({"read_letter", "write_letter", "admin:read:letter"})
  207.      * @ORM\Column(type="boolean", nullable=true)
  208.      */
  209.     private $isImportant;
  210.     /**
  211.      * @Groups({"read_letter", "write_letter", "admin:read:letter"})
  212.      * @ORM\Column(type="boolean", options={"default": false})
  213.      */
  214.     private bool $isArchived false;
  215.     /**
  216.      * @Groups({"read_letter", "write_letter", "admin:read:letter"})
  217.      * @ORM\Column(type="datetime", nullable=true)
  218.      */
  219.     private ?\DateTimeInterface $deletedAt null;
  220.     /**
  221.      * @Groups({"read_letter", "write_letter"})
  222.      * @ORM\ManyToMany(targetEntity="LetterTag", inversedBy="letters")
  223.      */
  224.     private ?Collection $tags;
  225.     public function __construct()
  226.     {
  227.         $this->setIsArchived(false);
  228.         $this->setIsRead(false);
  229.         $this->setIsScanned(false);
  230.         $this->createdAt = new \DateTime();
  231.         $this->tags = new ArrayCollection();
  232.     }
  233.     public function getId(): ?int
  234.     {
  235.         return $this->id;
  236.     }
  237.     public function getCreatedAt(): \DateTimeInterface
  238.     {
  239.         return $this->createdAt;
  240.     }
  241.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  242.     {
  243.         $this->createdAt $createdAt;
  244.         return $this;
  245.     }
  246.     public function getIsRead(): ?bool
  247.     {
  248.         return $this->isRead;
  249.     }
  250.     public function setIsRead(bool $isRead): self
  251.     {
  252.         $this->isRead $isRead;
  253.         return $this;
  254.     }
  255.     public function getStatus(): ?string
  256.     {
  257.         return $this->status;
  258.     }
  259.     public function setStatus(string $status): self
  260.     {
  261.         $this->status $status;
  262.         return $this;
  263.     }
  264.     public function getOrganization(): ?Organization
  265.     {
  266.         return $this->organization;
  267.     }
  268.     public function setOrganization(?Organization $organization): self
  269.     {
  270.         $this->organization $organization;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return mixed
  275.      */
  276.     public function getEnvelopeBackUrl()
  277.     {
  278.         return $this->envelopeBackUrl;
  279.     }
  280.     /**
  281.      * @param mixed $envelopeBackUrl
  282.      */
  283.     public function setEnvelopeBackUrl($envelopeBackUrl): void
  284.     {
  285.         $this->envelopeBackUrl $envelopeBackUrl;
  286.     }
  287.     /**
  288.      * @return mixed
  289.      */
  290.     public function getContentUrl()
  291.     {
  292.         return $this->contentUrl;
  293.     }
  294.     /**
  295.      * @param mixed $contentUrl
  296.      */
  297.     public function setContentUrl($contentUrl): void
  298.     {
  299.         $this->contentUrl $contentUrl;
  300.     }
  301.     public function getType(): ?string
  302.     {
  303.         return $this->type;
  304.     }
  305.     public function setType(string $type): self
  306.     {
  307.         $this->type $type;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return File
  312.      */
  313.     public function getEnvelopeFrontFile(): ?File
  314.     {
  315.         return $this->envelopeFrontFile;
  316.     }
  317.     /**
  318.      * @param File $envelopeFrontFile
  319.      */
  320.     public function setEnvelopeFrontFile(?File $envelopeFrontFile): Letter
  321.     {
  322.         $this->envelopeFrontFile $envelopeFrontFile;
  323.         if (null !== $envelopeFrontFile) {
  324.             // It is required that at least one field changes if you are using doctrine
  325.             // otherwise the event listeners won't be called and the file is lost
  326.             $this->updatedAt = new \DateTime();
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return File
  332.      */
  333.     public function getContentFile(): ?File
  334.     {
  335.         return $this->contentFile;
  336.     }
  337.     /**
  338.      * @param File $contentFile
  339.      */
  340.     public function setContentFile(?File $contentFile): Letter
  341.     {
  342.         $this->contentFile $contentFile;
  343.         if (null !== $contentFile) {
  344.             // It is required that at least one field changes if you are using doctrine
  345.             // otherwise the event listeners won't be called and the file is lost
  346.             $this->updatedAt = new \DateTime();
  347.         }
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return File
  352.      */
  353.     public function getEnvelopeBackFile(): ?File
  354.     {
  355.         return $this->envelopeBackFile;
  356.     }
  357.     /**
  358.      * @param File $envelopeBackFile
  359.      */
  360.     public function setEnvelopeBackFile(?File $envelopeBackFile): Letter
  361.     {
  362.         $this->envelopeBackFile $envelopeBackFile;
  363.         if (null !== $envelopeBackFile) {
  364.             // It is required that at least one field changes if you are using doctrine
  365.             // otherwise the event listeners won't be called and the file is lost
  366.             $this->updatedAt = new \DateTime();
  367.         }
  368.         return $this;
  369.     }
  370.     /**
  371.      * @return string
  372.      */
  373.     public function getContentPath()
  374.     {
  375.         return $this->contentPath;
  376.     }
  377.     /**
  378.      * @param string $contentPath
  379.      */
  380.     public function setContentPath(?string $contentPath): Letter
  381.     {
  382.         $this->contentPath $contentPath;
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return string
  387.      */
  388.     public function getEnvelopeFrontPath()
  389.     {
  390.         return $this->envelopeFrontPath;
  391.     }
  392.     /**
  393.      * @param string $envelopeFrontPath
  394.      */
  395.     public function setEnvelopeFrontPath(?string $envelopeFrontPath): Letter
  396.     {
  397.         $this->envelopeFrontPath $envelopeFrontPath;
  398.         return $this;
  399.     }
  400.     /**
  401.      * @return string
  402.      */
  403.     public function getEnvelopeBackPath()
  404.     {
  405.         return $this->envelopeBackPath;
  406.     }
  407.     /**
  408.      * @param string $envelopeBackPath
  409.      */
  410.     public function setEnvelopeBackPath(?string $envelopeBackPath): Letter
  411.     {
  412.         $this->envelopeBackPath $envelopeBackPath;
  413.         return $this;
  414.     }
  415.     /**
  416.      * @return \DateTime|\DateTimeImmutable|null
  417.      */
  418.     public function getUpdatedAt(): ?\DateTimeInterface
  419.     {
  420.         return $this->updatedAt;
  421.     }
  422.     /**
  423.      * @param \DateTime|\DateTimeImmutable|null $updatedAt
  424.      */
  425.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): Letter
  426.     {
  427.         $this->updatedAt $updatedAt;
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return LetterSignature
  432.      */
  433.     public function getLetterSignature()
  434.     {
  435.         return $this->letterSignature;
  436.     }
  437.     /**
  438.      * @param LetterSignature $letterSignature
  439.      *
  440.      * @return Letter
  441.      */
  442.     public function setLetterSignature(?LetterSignature $letterSignature)
  443.     {
  444.         $this->letterSignature $letterSignature;
  445.         return $this;
  446.     }
  447.     public function getLetterForward(): ?LetterForward
  448.     {
  449.         return $this->letterForward;
  450.     }
  451.     public function setLetterForward(?LetterForward $letterForward): self
  452.     {
  453.         $this->letterForward $letterForward;
  454.         return $this;
  455.     }
  456.     public function __toString()
  457.     {
  458.         return '#'.$this->getId();
  459.     }
  460.     public function getEnvelopeFrontPathAWS(): ?string
  461.     {
  462.         return $this->envelopeFrontPathAWS;
  463.     }
  464.     public function setEnvelopeFrontPathAWS(?string $envelopeFrontPathAWS): self
  465.     {
  466.         $this->envelopeFrontPathAWS $envelopeFrontPathAWS;
  467.         return $this;
  468.     }
  469.     public function getEnvelopeBackPathAWS(): ?string
  470.     {
  471.         return $this->envelopeBackPathAWS;
  472.     }
  473.     public function setEnvelopeBackPathAWS(?string $envelopeBackPathAWS): self
  474.     {
  475.         $this->envelopeBackPathAWS $envelopeBackPathAWS;
  476.         return $this;
  477.     }
  478.     public function getContentPathAWS(): ?string
  479.     {
  480.         return $this->contentPathAWS;
  481.     }
  482.     public function setContentPathAWS(?string $contentPathAWS): self
  483.     {
  484.         $this->contentPathAWS $contentPathAWS;
  485.         return $this;
  486.     }
  487.     public function getIsScanned(): ?bool
  488.     {
  489.         return $this->isScanned;
  490.     }
  491.     public function setIsScanned(?bool $isScanned): self
  492.     {
  493.         $this->isScanned $isScanned;
  494.         return $this;
  495.     }
  496.     public function getIsImportant(): ?bool
  497.     {
  498.         return $this->isImportant;
  499.     }
  500.     public function setIsImportant(?bool $isImportant): self
  501.     {
  502.         $this->isImportant $isImportant;
  503.         return $this;
  504.     }
  505.     public function getTags(): ?Collection
  506.     {
  507.         return $this->tags;
  508.     }
  509.     public function addTag(LetterTag $tag): self
  510.     {
  511.         if (!$this->tags->contains($tag)) {
  512.             $this->tags[] = $tag;
  513.         }
  514.         return $this;
  515.     }
  516.     public function removeTag(LetterTag $tag): self
  517.     {
  518.         $this->tags->removeElement($tag);
  519.         return $this;
  520.     }
  521.     public function getIsArchived(): bool
  522.     {
  523.         return $this->isArchived;
  524.     }
  525.     public function setIsArchived(bool $isArchived): self
  526.     {
  527.         $this->isArchived $isArchived;
  528.         return $this;
  529.     }
  530.     public function getDeletedAt(): ?\DateTimeInterface
  531.     {
  532.         return $this->deletedAt;
  533.     }
  534.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  535.     {
  536.         $this->deletedAt $deletedAt;
  537.         return $this;
  538.     }
  539.     public function isDeleted(): bool
  540.     {
  541.         return null !== $this->deletedAt;
  542.     }
  543. }