src/Entity/Document.php line 112

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  4. use App\Controller\Action\AttachFileController;
  5. use App\Controller\Action\DocumentDeleteFileController;
  6. use App\Controller\Action\DocumentRecapEvalStatController;
  7. use App\Controller\Action\DocumentSiteDeleteActionController;
  8. use App\Controller\Action\UploadFileController;
  9. use App\Filter\DocumentFilter;
  10. use App\Repository\EvaluationRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use ApiPlatform\Metadata\ApiResource;
  16. use App\Traits\AutoTimestampTrait;
  17. use Doctrine\ORM\Mapping\PreUpdate;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  20. use ApiPlatform\Metadata\ApiFilter;
  21. use ApiPlatform\Metadata\ApiProperty;
  22. use ApiPlatform\Metadata\Delete;
  23. use ApiPlatform\Metadata\Get;
  24. use ApiPlatform\Metadata\GetCollection;
  25. use ApiPlatform\Metadata\Post;
  26. use ApiPlatform\Metadata\Put;
  27. use App\Controller\Action\DocumentWithEvaluationStatAction;
  28. use App\Controller\Action\DocumentWithSiteStatActionController;
  29. use Doctrine\DBAL\Types\Types;
  30. use Doctrine\ORM\Mapping\PrePersist;
  31. #[ORM\Table(name'document')]
  32. #[ORM\Entity]
  33. #[ApiResource(
  34.     normalizationContext: ['skip_null_values' => false'datetime_format' => 'Y-m-d''groups' => ['document.get']],
  35.     denormalizationContext: ['skip_null_values' => false'groups' => ['document.write']],
  36.     operations: [
  37.         new GetCollection(),
  38.         new GetCollection(
  39.             name'_api_/documents/with_stat',
  40.             uriTemplate'/documents/with_stat',
  41.             controllerDocumentWithEvaluationStatAction::class,
  42.             writefalse,
  43.             readfalse
  44.         ),
  45.         new GetCollection(
  46.             name'_api_/documents/recap_eval_stat',
  47.             uriTemplate'/documents/recap_eval_stat',
  48.             controllerDocumentRecapEvalStatController::class,
  49.             writefalse,
  50.             readfalse
  51.         ),
  52.         new Post(
  53.             name'_api_/documents/with_site_stat',
  54.             uriTemplate'/documents/with_site_stat',
  55.             controllerDocumentWithSiteStatActionController::class,
  56.             writefalse,
  57.             readfalse
  58.         ),
  59.         new GetCollection(
  60.             name'_api_/documents/attach_files',
  61.             uriTemplate'/documents/attach_files',
  62.             controllerAttachFileController::class,
  63.             writefalse,
  64.             readfalse
  65.         ),
  66.         new Post(
  67.             security'user.isMasterAdmin()',
  68.         ),
  69.         new Post(
  70.             name'_api_/delete_document_site',
  71.             uriTemplate'/delete_document_site',
  72.             controllerDocumentSiteDeleteActionController::class,
  73.             writefalse,
  74.             readfalse
  75.         ),
  76.         new Get(),
  77.         new Put(
  78.             security'user.isMasterAdmin()',
  79.         ),
  80.         new Delete(
  81.             name'_api_/documents/delete_file',
  82.             uriTemplate'/documents/delete_file',
  83.             controllerDocumentDeleteFileController::class,
  84.             writefalse,
  85.             readfalse
  86.         ),
  87.         new Delete(
  88.             security'user.isMasterAdmin()',
  89.         ),
  90.     ]
  91. )]
  92. #[ApiFilter(
  93.     SearchFilter::class,
  94.     properties: [
  95.         'id' => 'exact',
  96.         'evaluations.site' => 'exact',
  97.        // 'term' => 'partial',
  98.         'affectations.site' => 'exact',
  99.         'theme' => 'exact',
  100.         'domain' => 'exact',
  101.         'subDomain' => 'exact',
  102.         'isConfidential' => 'exact'
  103.     ]
  104. )]
  105. #[ApiFilter(DocumentFilter::class)]
  106. #[ORM\HasLifecycleCallbacks]
  107. class Document
  108. {
  109.     use AutoTimestampTrait;
  110.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  111.     #[ORM\Id]
  112.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  113.     #[Groups(['document.get''plan.get'])]
  114.     private int $id;
  115.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  116.     private ?string $oldId null;
  117.     #[ORM\Column(name'title'typeTypes::TEXTlength16777215nullabletrue)]
  118.     #[Groups(['document.get''document.write''plan.get'])]
  119.     private ?string $title null;
  120.     #[ORM\Column(name'description'type'text'nullabletrue)]
  121.     #[Groups(['document.get''document.write'])]
  122.     private ?string $description null;
  123.     #[ORM\Column(name'document_type'type'string'length255nullabletrue)]
  124.     #[Groups(['document.get''document.write'])]
  125.     private ?string $documentType null;
  126.     #[ORM\Column(name'is_confidential'type'boolean'nullabletrue)]
  127.     #[Groups(['document.get''document.write'])]
  128.     private ?bool $isConfidential false;
  129.     #[ORM\Column(name'comment'type'text'nullabletrue)]
  130.     #[Groups(['document.get''document.write'])]
  131.     private ?string $comment null;
  132.     #[ORM\Column(name'application_fields'type'text'nullabletrue)]
  133.     #[Groups(['document.get''document.write'])]
  134.     private ?string $applicationFields null;
  135.     #[ORM\Column(name'last_updated_at'type'datetime'nullabletrue)]
  136.     #[Groups(['document.get''document.write'])]
  137.     #[ApiFilter(DateFilter::class)]
  138.     private $lastUpdatedAt;
  139.     #[ORM\Column(name'dated_at'type'datetime'nullabletrue)]
  140.     #[Groups(['document.get''document.write'])]
  141.     #[ApiFilter(DateFilter::class)]
  142.     private $datedAt;
  143.     #[ORM\Column(name'update_reason'type'text'nullabletrue)]
  144.     #[Groups(['document.get''document.write'])]
  145.     private ?string $updateReason null;
  146.     #[ORM\Column(name'summary_file_name'type'string'length255nullabletrue)]
  147.     #[Groups(['document.get''document.write'])]
  148.     private ?string $summaryFileName null;
  149.     #[ORM\Column(name'illustrations_file_name'type'string'length255nullabletrue)]
  150.     #[Groups(['document.get''document.write'])]
  151.     private ?string $illustrationsFileName null;
  152.     #[ORM\Column(name'url'type'text'nullabletrue)]
  153.     #[Groups(['document.get''document.write'])]
  154.     private ?string $url null;
  155.     #[ORM\Column(name'is_applicable'type'boolean'nullabletrue)]
  156.     #[Groups(['document.get''document.write'])]
  157.     private ?bool $isApplicable null;
  158.     #[ORM\ManyToOne]
  159.     #[ORM\JoinColumn(nullabletrue)]
  160.     #[Groups(['document.get''document.write'])]
  161.     private ?Category $theme null;
  162.     #[ORM\ManyToOne]
  163.     #[ORM\JoinColumn(nullabletrue)]
  164.     #[Groups(['document.get''document.write'])]
  165.     private ?Category $domain null;
  166.     #[ORM\ManyToOne]
  167.     #[ORM\JoinColumn(nullabletrue)]
  168.     #[Groups(['document.get''document.write'])]
  169.     private ?Category $subDomain null;
  170.     #[ORM\ManyToOne]
  171.     #[Groups(['document.get''document.write'])]
  172.     private ?Country $country null;
  173.     #[ORM\OneToMany(mappedBy'document'targetEntityAffectation::class, cascade: ['persist'], orphanRemovaltrue)]
  174.     #[Groups(['document.write''document.affectation.get'])]
  175.     private Collection $affectations;
  176.     #[ORM\OneToMany(mappedBy'document'targetEntityCompliance::class)]
  177.     private Collection $compliances;
  178.     #[Groups(['document.get'])]
  179.     #[ORM\Column(type'datetime')]
  180.     protected $updatedAt;
  181.     #[Groups(['document.get'])]
  182.     #[ORM\Column(type'datetime')]
  183.     protected $createdAt;
  184.     #[ORM\Column(type'datetime'nullabletrue)]
  185.     #[Groups(['document.get''document.write'])]
  186.     #[ApiFilter(DateFilter::class)]
  187.     private $creationAt null;
  188.     #[ORM\Column(name'status'type'integer'nullabletrue)]
  189.     #[Groups(['document.get''document.write'])]
  190.     private ?int $status null;
  191.     #[ORM\OneToMany(mappedBy'document'targetEntityEvaluation::class)]
  192.     private Collection $evaluations;
  193.     #[ApiProperty()]
  194.     #[Groups(['document.get'])]
  195.     private int $conformity;
  196.     #[ApiProperty()]
  197.     #[Groups(['document.get'])]
  198.     private int $progression;
  199.     #[ORM\OneToMany(mappedBy'document'targetEntitySection::class)]
  200.     private Collection $sections;
  201.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  202.     private ?string $term null;
  203.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  204.     #[Groups(['document.get''document.write'])]
  205.     private ?string $annotationNovallia null;
  206.     #[ORM\ManyToOne(inversedBy'illustrationsFile')]
  207.     #[Groups(['document.get''document.write'])]
  208.     private ?Media $illustrationsFile null;
  209.     #[ORM\ManyToOne(inversedBy'summaryFile')]
  210.     #[Groups(['document.get''document.write'])]
  211.     private ?Media $summaryFile null;
  212.     #[ORM\Column(name'last_update_compliance'type'datetime'nullabletrue)]
  213.     #[Groups(['document.get''document.write'])]
  214.     private ?\DateTimeInterface $lastUpdateCompliance null;
  215.     #[ORM\OneToMany(mappedBy'document'targetEntityDiscussion::class)]
  216.     private Collection $discussions;
  217.     #[ORM\Column(nullabletrue)]
  218.     #[Groups(['document.get''document.write'])]
  219.     private ?bool $localTextRte null;
  220.     #[ORM\ManyToOne]
  221.     #[Groups(['document.get''document.write'])]
  222.     private ?User $updatedBy null;
  223.     #[ORM\Column(nullabletrue)]
  224.     #[Groups(['document.get''document.write'])]
  225.     private ?bool $dashboardRatp null;
  226.     public function __construct()
  227.     {
  228.         $this->affectations = new ArrayCollection();
  229.         $this->evaluations = new ArrayCollection();
  230.         $this->sections = new ArrayCollection();
  231.         $this->discussions = new ArrayCollection();
  232.     }
  233.     public function getId(): ?int
  234.     {
  235.         return $this->id;
  236.     }
  237.     public function getOldId(): ?string
  238.     {
  239.         return $this->oldId;
  240.     }
  241.     public function setOldId(?string $oldId): self
  242.     {
  243.         $this->oldId $oldId;
  244.         return $this;
  245.     }
  246.     public function getTitle(): ?string
  247.     {
  248.         return $this->title;
  249.     }
  250.     public function setTitle(?string $title): self
  251.     {
  252.         $this->title $title;
  253.         return $this;
  254.     }
  255.     public function getDescription(): ?string
  256.     {
  257.         return $this->description;
  258.     }
  259.     public function setDescription(?string $description): self
  260.     {
  261.         $this->description $description;
  262.         return $this;
  263.     }
  264.     public function getDocumentType(): ?string
  265.     {
  266.         return $this->documentType;
  267.     }
  268.     public function setDocumentType(?string $documentType): self
  269.     {
  270.         $this->documentType $documentType;
  271.         return $this;
  272.     }
  273.     public function isIsConfidential(): ?bool
  274.     {
  275.         return $this->isConfidential;
  276.     }
  277.     public function setIsConfidential(?bool $isConfidential): self
  278.     {
  279.         $this->isConfidential $isConfidential;
  280.         return $this;
  281.     }
  282.     public function getComment(): ?string
  283.     {
  284.         return $this->comment;
  285.     }
  286.     public function setComment(?string $comment): self
  287.     {
  288.         $this->comment $comment;
  289.         return $this;
  290.     }
  291.     public function getApplicationFields(): ?string
  292.     {
  293.         return $this->applicationFields;
  294.     }
  295.     public function setApplicationFields(?string $applicationFields): self
  296.     {
  297.         $this->applicationFields $applicationFields;
  298.         return $this;
  299.     }
  300.     public function getLastUpdatedAt(): ?\DateTimeInterface
  301.     {
  302.         return $this->lastUpdatedAt;
  303.     }
  304.     public function setLastUpdatedAt(?\DateTimeInterface $lastUpdatedAt): self
  305.     {
  306.         $this->lastUpdatedAt $lastUpdatedAt;
  307.         return $this;
  308.     }
  309.     public function getDatedAt(): ?\DateTimeInterface
  310.     {
  311.         return $this->datedAt;
  312.     }
  313.     public function setDatedAt(?\DateTimeInterface $datedAt): self
  314.     {
  315.         $this->datedAt $datedAt;
  316.         return $this;
  317.     }
  318.     public function getUpdateReason(): ?string
  319.     {
  320.         return $this->updateReason;
  321.     }
  322.     public function setUpdateReason(?string $updateReason): self
  323.     {
  324.         $this->updateReason $updateReason;
  325.         return $this;
  326.     }
  327.     public function getSummaryFileName(): ?string
  328.     {
  329.         return $this->summaryFileName;
  330.     }
  331.     public function setSummaryFileName(?string $summaryFileName): self
  332.     {
  333.         $this->summaryFileName $summaryFileName;
  334.         return $this;
  335.     }
  336.     public function getIllustrationsFileName(): ?string
  337.     {
  338.         return $this->illustrationsFileName;
  339.     }
  340.     public function setIllustrationsFileName(?string $illustrationsFileName): self
  341.     {
  342.         $this->illustrationsFileName $illustrationsFileName;
  343.         return $this;
  344.     }
  345.     public function getUrl(): ?string
  346.     {
  347.         return $this->url;
  348.     }
  349.     public function setUrl(?string $url): self
  350.     {
  351.         $this->url $url;
  352.         return $this;
  353.     }
  354.     public function isIsApplicable(): ?bool
  355.     {
  356.         return $this->isApplicable;
  357.     }
  358.     public function setIsApplicable(?bool $isApplicable): self
  359.     {
  360.         $this->isApplicable $isApplicable;
  361.         return $this;
  362.     }
  363.     public function getTheme(): ?Category
  364.     {
  365.         return $this->theme;
  366.     }
  367.     public function setTheme(?Category $theme): self
  368.     {
  369.         $this->theme $theme;
  370.         return $this;
  371.     }
  372.     public function getDomain(): ?Category
  373.     {
  374.         return $this->domain;
  375.     }
  376.     public function setDomain(?Category $domain): self
  377.     {
  378.         $this->domain $domain;
  379.         return $this;
  380.     }
  381.     public function getSubDomain(): ?Category
  382.     {
  383.         return $this->subDomain;
  384.     }
  385.     public function setSubDomain(?Category $subDomain): self
  386.     {
  387.         $this->subDomain $subDomain;
  388.         return $this;
  389.     }
  390.     public function getCountry(): ?Country
  391.     {
  392.         return $this->country;
  393.     }
  394.     public function setCountry(?Country $country): self
  395.     {
  396.         $this->country $country;
  397.         return $this;
  398.     }
  399.     public function getStatus(): ?string
  400.     {
  401.         return $this->status;
  402.     }
  403.     public function setStatus(?string $status): self
  404.     {
  405.         $this->status $status;
  406.         return $this;
  407.     }
  408.     /**
  409.      * @return Collection<int, Affectation>
  410.      */
  411.     public function getAffectations(): Collection
  412.     {
  413.         return $this->affectations;
  414.     }
  415.     public function addAffectation(Affectation $affectation): self
  416.     {
  417.         if (!$this->affectations->contains($affectation)) {
  418.             $this->affectations->add($affectation);
  419.             $affectation->setDocument($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removeAffectation(Affectation $affectation): self
  424.     {
  425.         if ($this->affectations->removeElement($affectation)) {
  426.             if ($affectation->getDocument() === $this) {
  427.                 $affectation->setDocument(null);
  428.             }
  429.         }
  430.         return $this;
  431.     }
  432.     public function getCreationAt()
  433.     {
  434.         return $this->creationAt;
  435.     }
  436.     public function setCreationAt($creationAt): self
  437.     {
  438.         $this->creationAt $creationAt;
  439.         return $this;
  440.     }
  441.     /**
  442.      * @return Collection<int, Compliance>
  443.      */
  444.     public function getCompliances(): Collection
  445.     {
  446.         return $this->compliances;
  447.     }
  448.     public function getDocumentStatus(): ?int
  449.     {
  450.         return $this->documentStatus;
  451.     }
  452.     public function setDocumentStatus(?int $documentStatus): self
  453.     {
  454.         $this->documentStatus $documentStatus;
  455.         return $this;
  456.     }
  457.     /**
  458.      * @return Collection<int, Evaluation>
  459.      */
  460.     public function getEvaluations(): Collection
  461.     {
  462.         return $this->evaluations;
  463.     }
  464.     public function addEvaluation(Evaluation $evaluation): self
  465.     {
  466.         if (!$this->evaluations->contains($evaluation)) {
  467.             $this->evaluations->add($evaluation);
  468.             $evaluation->setDocument($this);
  469.         }
  470.         return $this;
  471.     }
  472.     public function removeEvaluation(Evaluation $evaluation): self
  473.     {
  474.         if ($this->evaluations->removeElement($evaluation)) {
  475.             // set the owning side to null (unless already changed)
  476.             if ($evaluation->getDocument() === $this) {
  477.                 $evaluation->setDocument(null);
  478.             }
  479.         }
  480.         return $this;
  481.     }
  482.     public function getConformity(): int
  483.     {
  484.         return $this->conformity;
  485.     }
  486.     public function setConformity(int $conformity): self
  487.     {
  488.         $this->conformity $conformity;
  489.         return $this;
  490.     }
  491.     public function getProgression(): int
  492.     {
  493.         return $this->progression;
  494.     }
  495.     public function setProgression(int $progression): self
  496.     {
  497.         $this->progression $progression;
  498.         return $this;
  499.     }
  500.     /**
  501.      * @return Collection
  502.      */
  503.     public function getSections(): Collection
  504.     {
  505.         return $this->sections;
  506.     }
  507.     #[Groups(['document.get'])]
  508.     public function getLiveStatus()
  509.     {
  510.         $updatedDaysAgo false;
  511.         $lastUpdateComplianceAgo false;
  512.         $createdDaysAgo 365;
  513.         if ($this->status) {
  514.             $status $this->status;
  515.         } else {
  516.             $status 39;
  517.         }
  518.         if (!empty($this->datedAt))
  519.             $createdDaysAgo = (new \DateTimeImmutable('now'))->diff($this->datedAt)->format('%a');
  520.         if (!empty($this->lastUpdatedAt))
  521.             $updatedDaysAgo = (new \DateTimeImmutable('now'))->diff($this->lastUpdatedAt)->format('%a');
  522.         if (!empty($this->lastUpdateCompliance))
  523.             $lastUpdateComplianceAgo = (new \DateTimeImmutable('now'))->diff($this->lastUpdateCompliance)->format('%a');
  524.         $documentStatusDaysAgo EvaluationRepository::DOCUMENT_STATUS_DAYS_AGO;
  525.         if (($this->status === DocumentStatus::UNDER_PROJECT_STATUS)
  526.             || ($this->status === DocumentStatus::UNDER_PROJECT_STATUS)
  527.         ) {
  528.             $status $this->status;
  529.         }
  530.         else if ($this->status === DocumentStatus::REPEALED_STATUS){
  531.             $status $this->status;
  532.         }
  533.         else if (isset($createdDaysAgo) && ($createdDaysAgo === || $createdDaysAgo === "0" || !empty($createdDaysAgo)) && $createdDaysAgo $documentStatusDaysAgo) {
  534.             $status DocumentStatus::NEW_STATUS;
  535.         } else if ((isset($updatedDaysAgo) && ($updatedDaysAgo === || $updatedDaysAgo === "0" || !empty($updatedDaysAgo)) && $updatedDaysAgo $documentStatusDaysAgo)
  536.             || (isset($lastUpdateComplianceAgo) && ($lastUpdateComplianceAgo === || $lastUpdateComplianceAgo === "0" || !empty($lastUpdateComplianceAgo)) && $lastUpdateComplianceAgo $documentStatusDaysAgo)) {
  537.             $status DocumentStatus::EDITED_STATUS;
  538.         }
  539.         return DocumentStatus::STATUSES[$status];
  540.     }
  541.     public function getTerm(): ?string
  542.     {
  543.         return $this->term;
  544.     }
  545.     public function setTerm(?string $term): self
  546.     {
  547.         $this->term $term;
  548.         return $this;
  549.     }
  550.     #[PrePersist]
  551.     #[PreUpdate]
  552.     public function updateTerm()
  553.     {
  554.         $this->term $this->title " " $this->description;
  555.     }
  556.     public function getAnnotationNovallia(): ?string
  557.     {
  558.         return $this->annotationNovallia;
  559.     }
  560.     public function setAnnotationNovallia(?string $annotationNovallia): self
  561.     {
  562.         $this->annotationNovallia $annotationNovallia;
  563.         return $this;
  564.     }
  565.     public function getIllustrationsFile(): ?Media
  566.     {
  567.         return $this->illustrationsFile;
  568.     }
  569.     public function setIllustrationsFile(?Media $illustrationsFile): self
  570.     {
  571.         $this->illustrationsFile $illustrationsFile;
  572.         return $this;
  573.     }
  574.     public function getSummaryFile(): ?Media
  575.     {
  576.         return $this->summaryFile;
  577.     }
  578.     public function setSummaryFile(?Media $summaryFile): self
  579.     {
  580.         $this->summaryFile $summaryFile;
  581.         return $this;
  582.     }
  583.     public function getLastUpdateCompliance(): ?\DateTimeInterface
  584.     {
  585.         return $this->lastUpdateCompliance;
  586.     }
  587.     public function setLastUpdateCompliance(?\DateTimeInterface $lastUpdateCompliance): self
  588.     {
  589.         $this->lastUpdateCompliance $lastUpdateCompliance;
  590.         return $this;
  591.     }
  592.     /**
  593.      * @return Collection<int, Discussion>
  594.      */
  595.     public function getDiscussions(): Collection
  596.     {
  597.         return $this->discussions;
  598.     }
  599.     public function addDiscussion(Discussion $discussion): self
  600.     {
  601.         if (!$this->discussions->contains($discussion)) {
  602.             $this->discussions->add($discussion);
  603.             $discussion->setDocument($this);
  604.         }
  605.         return $this;
  606.     }
  607.     public function removeDiscussion(Discussion $discussion): self
  608.     {
  609.         if ($this->discussions->removeElement($discussion)) {
  610.             // set the owning side to null (unless already changed)
  611.             if ($discussion->getDocument() === $this) {
  612.                 $discussion->setDocument(null);
  613.             }
  614.         }
  615.         return $this;
  616.     }
  617.     public function isLocalTextRte(): ?bool
  618.     {
  619.         return $this->localTextRte;
  620.     }
  621.     public function setLocalTextRte(?bool $localTextRte): self
  622.     {
  623.         $this->localTextRte $localTextRte;
  624.         return $this;
  625.     }
  626.     public function getUpdatedBy(): ?User
  627.     {
  628.         return $this->updatedBy;
  629.     }
  630.     public function setUpdatedBy(?User $updatedBy): self
  631.     {
  632.         $this->updatedBy $updatedBy;
  633.         return $this;
  634.     }
  635.     public function isDashboardRatp(): ?bool
  636.     {
  637.         return $this->dashboardRatp;
  638.     }
  639.     public function setDashboardRatp(?bool $dashboardRatp): self
  640.     {
  641.         $this->dashboardRatp $dashboardRatp;
  642.         return $this;
  643.     }
  644. }