src/Entity/Compliance.php line 57

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