src/Entity/Compliance.php line 58

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EvaluationRepository;
  4. use App\State\CompliancePostProcessor;
  5. use App\State\CompliancePutProcessor;
  6. use App\State\ComplianceDeleteProcessor;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use App\Traits\AutoTimestampTrait;
  11. use ApiPlatform\Metadata\ApiResource;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  14. use ApiPlatform\Metadata\ApiFilter;
  15. use ApiPlatform\Metadata\ApiProperty;
  16. use ApiPlatform\Metadata\Delete;
  17. use ApiPlatform\Metadata\Get;
  18. use ApiPlatform\Metadata\GetCollection;
  19. use ApiPlatform\Metadata\Post;
  20. use ApiPlatform\Metadata\Put;
  21. #[ORM\Table(name'compliance')]
  22. #[ORM\Index(name'section_id'columns: ['section_id'])]
  23. #[ORM\Entity]
  24. #[ORM\HasLifecycleCallbacks]
  25. #[ApiResource(
  26.     order: ['ranked' => 'ASC'],
  27.     normalizationContext: ['groups' => ['compliance.get''compliance.write']],
  28.     denormalizationContext: ['groups' => ['compliance.write']],
  29.     operations: [
  30.         new GetCollection(),
  31.         new Post(
  32.             security'user.isMasterAdmin()',
  33.             processorCompliancePostProcessor::class
  34.         ),
  35.         new Get(),
  36.         new Put(
  37.             security'user.isMasterAdmin()',
  38.             processorCompliancePutProcessor::class
  39.         ),
  40.         new Delete(
  41.             security'user.isMasterAdmin()',
  42.             processorComplianceDeleteProcessor::class
  43.         )
  44.     ]
  45. )]
  46. #[ApiFilter(
  47.     SearchFilter::class, properties: [
  48.     'evaluations.site' => 'exact',
  49.     'title' => 'partial',
  50.     'document' => 'exact',
  51.     'section' => 'exact',
  52.     'evaluations.document' => 'exact',
  53. ]
  54. )]
  55. class Compliance
  56. {
  57.     use AutoTimestampTrait;
  58.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  59.     #[ORM\Id]
  60.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  61.     #[Groups(['compliance.get''plan.get'])]
  62.     private int $id;
  63.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  64.     private ?string $oldId null;
  65.     #[ORM\Column(name'deadline_at'type'datetime'nullabletrue)]
  66.     #[Groups('compliance.get')]
  67.     private $deadlineAt;
  68.     #[ORM\Column(name'title'type'text'length65535)]
  69.     #[Groups(['compliance.get','plan.get','compliance.write'])]
  70.     private ?string $title;
  71.     #[ORM\Column(name'ranked'type'integer')]
  72.     #[Groups(['compliance.get','compliance.write'])]
  73.     private int $ranked 1;
  74.     #[ORM\Column(name'is_applicable'type'boolean')]
  75.     #[Groups('compliance.get')]
  76.     private bool $isApplicable true;
  77.     #[ORM\JoinColumn(name'section_id'referencedColumnName'id')]
  78.     #[ORM\ManyToOne(targetEntity'Section'inversedBy'compliances')]
  79.     #[Groups(['plan.get','compliance.write'])]
  80.     private Section $section;
  81.     #[ORM\JoinColumn(name'text_id'referencedColumnName'id')]
  82.     #[ORM\ManyToOne(targetEntity'Document'inversedBy'compliances')]
  83.     #[Groups(['compliance.get','compliance.write'])]
  84.     private Document $document;
  85.     #[ORM\OneToMany(mappedBy'compliance'targetEntityEvaluation::class)]
  86.     #[Groups('compliance:evaluation:get')]
  87.     private Collection $evaluations;
  88.     #[Groups('compliance.get')]
  89.     private ?int $conformity;
  90.     #[Groups('compliance.get')]
  91.     private ?int $progress;
  92.     #[ORM\ManyToOne(inversedBy'evaluations'targetEntity'EvaluationStatus')]
  93.     #[ORM\JoinColumn(nullabletrue)]
  94.     #[Groups(['compliance.get'])]
  95.     private $status null;
  96.     #[ORM\Column(name'annotation_compliance'type'text'nullabletrue)]
  97.     #[Groups(['compliance.get'])]
  98.     private ?string $annotationCompliance  null;
  99.     #[ORM\Column(name'last_update_compliance'type'datetime'nullabletrue)]
  100.     #[Groups('compliance.get')]
  101.     private ?\DateTimeInterface $lastUpdateCompliance null;
  102.     #[ORM\Column(nullabletrue)]
  103.     private ?int $version null;
  104.     #[ORM\Column(type'text'nullabletrue)]
  105.     private ?string $defaultPaTitle null;
  106.     #[ORM\ManyToOne]
  107.     #[Groups('compliance.get')]
  108.     private ?User $updatedBy null;
  109.     #[ORM\Column(type'text'nullabletrue)]
  110.     #[Groups(['compliance.get','plan.get'])]
  111.     private ?string $titleRte null;
  112.     public function __construct()
  113.     {
  114.         $this->evaluations = new ArrayCollection();
  115.     }
  116.     public function getId(): ?int
  117.     {
  118.         return $this->id;
  119.     }
  120.     public function getOldId(): ?string
  121.     {
  122.         return $this->oldId;
  123.     }
  124.     public function setOldId(?string $oldId): self
  125.     {
  126.         $this->oldId $oldId;
  127.         return $this;
  128.     }
  129.     public function getDeadlineAt(): ?\DateTimeInterface
  130.     {
  131.         return $this->deadlineAt;
  132.     }
  133.     public function setDeadlineAt(?\DateTimeInterface $deadlineAt): self
  134.     {
  135.         $this->deadlineAt $deadlineAt;
  136.         return $this;
  137.     }
  138.     public function getTitle(): ?string
  139.     {
  140.         return $this->title;
  141.     }
  142.     public function setTitle(?string $title): self
  143.     {
  144.         $this->title $title;
  145.         return $this;
  146.     }
  147.     public function getRanked(): int
  148.     {
  149.         return $this->ranked;
  150.     }
  151.     public function setRanked(int $ranked): self
  152.     {
  153.         $this->ranked $ranked;
  154.         return $this;
  155.     }
  156.     public function isIsApplicable(): bool
  157.     {
  158.         return $this->isApplicable;
  159.     }
  160.     public function setIsApplicable(bool $isApplicable): self
  161.     {
  162.         $this->isApplicable $isApplicable;
  163.         return $this;
  164.     }
  165.     public function getSection(): Section
  166.     {
  167.         return $this->section;
  168.     }
  169.     public function setSection(Section $section): self
  170.     {
  171.         $this->section $section;
  172.         return $this;
  173.     }
  174.     public function getDocument(): Document
  175.     {
  176.         return $this->document;
  177.     }
  178.     public function setDocument(Document $document): self
  179.     {
  180.         $this->document $document;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection<int, self>
  185.      */
  186.     public function getEvaluations(): Collection
  187.     {
  188.         return $this->evaluations;
  189.     }
  190.     public function addEvaluation(self $evaluation): self
  191.     {
  192.         if (!$this->evaluations->contains($evaluation)) {
  193.             $this->evaluations->add($evaluation);
  194.             $evaluation->setCompliance($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeEvaluation(self $evaluation): self
  199.     {
  200.         if ($this->evaluations->removeElement($evaluation)) {
  201.             // set the owning side to null (unless already changed)
  202.             if ($evaluation->getCompliance() === $this) {
  203.                 $evaluation->setCompliance(null);
  204.             }
  205.         }
  206.         return $this;
  207.     }
  208.     public function getConformity(): int
  209.     {
  210.         return $this->conformity;
  211.     }
  212.     public function setConformity(int $conformity): self
  213.     {
  214.         $this->conformity $conformity;
  215.         return $this;
  216.     }
  217.     public function getProgress(): int
  218.     {
  219.         return $this->progress;
  220.     }
  221.     public function setProgress(int $progress): self
  222.     {
  223.         $this->progress $progress;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return null
  228.      */
  229.     public function getStatus()
  230.     {
  231.         return $this->status;
  232.     }
  233.     /**
  234.      * @param null $status
  235.      */
  236.     public function setStatus($status): void
  237.     {
  238.         $this->status $status;
  239.     }
  240.     /**
  241.      * @return string|null
  242.      */
  243.     public function getAnnotationCompliance(): ?string
  244.     {
  245.         return $this->annotationCompliance;
  246.     }
  247.     /**
  248.      * @param string|null $annotationCompliance
  249.      */
  250.     public function setAnnotationCompliance(?string $annotationCompliance): void
  251.     {
  252.         $this->annotationCompliance $annotationCompliance;
  253.     }
  254.     /**
  255.      * @return \DateTimeInterface|null
  256.      */
  257.     public function getLastUpdateCompliance(): ?\DateTimeInterface
  258.     {
  259.         return $this->lastUpdateCompliance;
  260.     }
  261.     /**
  262.      * @param \DateTimeInterface|null $lastUpdateCompliance
  263.      */
  264.     public function setLastUpdateCompliance(?\DateTimeInterface $lastUpdateCompliance): self
  265.     {
  266.         $this->lastUpdateCompliance $lastUpdateCompliance;
  267.         return $this;
  268.     }
  269.     #[Groups(['compliance.get'])]
  270.     public function getLiveStatus()
  271.     {
  272.         $lastUpdateComplianceAgofalse;
  273.         if (!empty($this->lastUpdateCompliance))
  274.             $lastUpdateComplianceAgo = (new \DateTimeImmutable('now'))->diff($this->lastUpdateCompliance)->format('%a');
  275.         $documentStatusDaysAgo EvaluationRepository::DOCUMENT_STATUS_DAYS_AGO;
  276.         if ($this->status?->getId() === DocumentStatus::REPEALED_COMPLIANCE_STATUS){
  277.             $status $this->status?->getId();
  278.         }
  279.         else if (!empty($this->lastUpdateCompliance) && $lastUpdateComplianceAgo $documentStatusDaysAgo) {
  280.             $status DocumentStatus::EDITED_STATUS;
  281.         }
  282.         else{
  283.             if ($this->status) {
  284.                 $status $this->status;
  285.                 return '';
  286.             } else {
  287.                 $status 39;
  288.             }
  289.         }
  290.         return  DocumentStatus::STATUSES[$status];
  291.     }
  292.     public function getVersion(): ?int
  293.     {
  294.         return $this->version;
  295.     }
  296.     public function setVersion(?int $version): self
  297.     {
  298.         $this->version $version;
  299.         return $this;
  300.     }
  301.     public function getDefaultPaTitle(): ?string
  302.     {
  303.         return $this->defaultPaTitle;
  304.     }
  305.     public function setDefaultPaTitle(?string $defaultPaTitle): self
  306.     {
  307.         $this->defaultPaTitle $defaultPaTitle;
  308.         return $this;
  309.     }
  310.     public function getUpdatedBy(): ?User
  311.     {
  312.         return $this->updatedBy;
  313.     }
  314.     public function setUpdatedBy(?User $updatedBy): self
  315.     {
  316.         $this->updatedBy $updatedBy;
  317.         return $this;
  318.     }
  319.     public function getTitleRte(): ?string
  320.     {
  321.         return $this->titleRte;
  322.     }
  323.     public function setTitleRte(string $titleRte): self
  324.     {
  325.         $this->titleRte $titleRte;
  326.         return $this;
  327.     }
  328. }