src/Entity/Evaluation.php line 92

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use App\Controller\Action\EvaluationController;
  7. use App\Controller\Action\EvaluationDuplicatePutAction;
  8. use App\Controller\Action\EvaluationHistoryActionController;
  9. use App\Controller\Action\EvaluationPutAction;
  10. use App\Controller\Action\EvaluationReportController;
  11. use App\Controller\Action\StatisticsEvaluationsReportController;
  12. use App\Repository\EvaluationRepository;
  13. use App\State\EvaluationPutProcessor;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\SerializedName;
  19. use ApiPlatform\Metadata\Delete;
  20. use ApiPlatform\Metadata\Get;
  21. use ApiPlatform\Metadata\GetCollection;
  22. use ApiPlatform\Metadata\Post;
  23. use ApiPlatform\Metadata\Put;
  24. #[ORM\Table(name'evaluation')]
  25. #[ORM\Index(name'compliance_id'columns: ['compliance_id'])]
  26. #[ORM\Index(name'site_id'columns: ['site_id'])]
  27. #[ORM\Index(name'user_id'columns: ['user_id'])]
  28. #[ORM\Entity(repositoryClassEvaluationRepository::class)]
  29. #[ApiResource(
  30.     operations: [
  31.     new GetCollection(),
  32.     new GetCollection(
  33.         name'_api_/evaluations/{id}/histories',
  34.         uriTemplate'/evaluations/{id}/histories',
  35.         controllerEvaluationHistoryActionController::class,
  36.         writefalse,
  37.         readfalse
  38.     ),
  39.     new Post(
  40.         name'_api_/evaluations_report',
  41.         uriTemplate'/evaluations_report',
  42.         controllerEvaluationController::class,
  43.         writefalse,
  44.         readfalse
  45.     ),
  46.     new Post(
  47.         uriTemplate'/evaluations_report_optimized',
  48.         controllerEvaluationReportController::class,
  49.         readfalse,
  50.         writefalse,
  51.         name'_api_/evaluations_report_optimized'
  52.     ),
  53.     new Post(
  54.         security'user.isMasterAdmin()'
  55.     ),
  56.     new Get(),
  57.     new Put(
  58.         controllerEvaluationPutAction::class,
  59.     ),
  60.     new Put(
  61.         name'_api_/evaluation_duplicate',
  62.         uriTemplate'/evaluation_duplicate',
  63.         controllerEvaluationDuplicatePutAction::class,
  64.         writefalse,
  65.         readfalse
  66.     ),
  67.     new Delete(),
  68.     new Post(
  69.         uriTemplate'/report_evaluations_statistics',
  70.         controllerStatisticsEvaluationsReportController::class,
  71.         readfalse,
  72.         writefalse,
  73.         name'_api_/report_evaluations_statistics'
  74.     ),
  75. ],
  76.     normalizationContext: ['skip_null_values' => false'datetime_format' => 'Y-m-d''groups' => ['compliance.get''evaluation.get']],
  77.     denormalizationContext: ['groups' => ['evaluation.write']]
  78. )]
  79. #[ApiFilter(
  80.     SearchFilter::class,
  81.     properties: [
  82.         'site' => 'exact',
  83.         'compliance.document' => 'exact',
  84.         'compliance.section' => 'exact',
  85.         'document' => 'exact',
  86.     ]
  87. )]
  88. class Evaluation
  89. {
  90.     #[ORM\Column(name'id'type'bigint'nullablefalse)]
  91.     #[ORM\Id]
  92.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  93.     #[Groups(['compliance.get','plan.get'])]
  94.     private int $id;
  95.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  96.     private ?string $oldId null;
  97.     #[ORM\JoinColumn(name'compliance_id'referencedColumnName'id')]
  98.     #[ORM\ManyToOne(targetEntity'Compliance'inversedBy'evaluations')]
  99.     #[Groups(['evaluation.get','plan.get'])]
  100.     private ?\App\Entity\Compliance $compliance null;
  101.     #[ORM\JoinColumn(name'site_id'referencedColumnName'id')]
  102.     #[ORM\ManyToOne(targetEntity'Site')]
  103.     #[Groups(['compliance.get''evaluation.get'])]
  104.     private ?\App\Entity\Site $site null;
  105.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id')]
  106.     #[ORM\ManyToOne(targetEntity'User')]
  107.     #[Groups(['compliance.get''evaluation.get','evaluation.write'])]
  108.     private ?\App\Entity\User $user null;
  109.     #[ORM\Column(name'annotation_nvs'type'string'length16777215nullabletrue)]
  110.     #[Groups(['compliance.get''evaluation.get''evaluation.write'])]
  111.     private ?string $annotationNvs;
  112.     #[ORM\Column(name'annotation'type'string'length16777215nullabletrue)]
  113.     #[Groups(['compliance.get''evaluation.get''evaluation.write','plan.get'])]
  114.     private ?string $annotation;
  115.     #[ORM\Column(name'comment'type'string'length16777215nullabletrue)]
  116.     #[Groups(['compliance.get''evaluation.get''evaluation.write','plan.get'])]
  117.     private ?string $comment;
  118.     #[ORM\ManyToOne(inversedBy'evaluations')]
  119.     #[ORM\JoinColumn(nullablefalse)]
  120.     private ?Section $section null;
  121.     #[ORM\ManyToOne(inversedBy'evaluations')]
  122.     #[ORM\OrderBy(['updatedAt' => 'DESC''datedAt' => 'DESC'])]
  123.     #[ORM\JoinColumn(nullablefalse)]
  124.     #[Groups(['compliance.get''evaluation.get'])]
  125.     private ?Document $document null;
  126.     #[ORM\Column(nullabletrue)]
  127.     #[Groups(['compliance.get''evaluation.get''evaluation.write','plan.get'])]
  128.     private ?\DateTimeImmutable $evaluationDate null;
  129.     #[ORM\ManyToOne(inversedBy'evaluations'targetEntity'EvaluationStatus')]
  130.     #[ORM\JoinColumn(nullabletrue)]
  131.     #[Groups(['compliance.get''evaluation.get''evaluation.write''compliance:evaluation:get','plan.get'])]
  132.     private $status null;
  133.     #[ORM\ManyToMany(targetEntityActionPlan::class, inversedBy'evaluation'orphanRemovalfalsecascade: ['persist'])]
  134.     private Collection $actionPlans;
  135.     #[ORM\ManyToOne(inversedBy'evaluation_file')]
  136.     #[Groups(['evaluation.get''evaluation.write'])]
  137.     private ?Media $evaluation_file null;
  138.     public function __construct()
  139.     {
  140.         $this->actionPlans = new ArrayCollection();
  141.     }
  142.     public function getId(): ?int
  143.     {
  144.         return $this->id;
  145.     }
  146.     public function getOldId(): ?string
  147.     {
  148.         return $this->oldId;
  149.     }
  150.     public function setOldId(?string $oldId): self
  151.     {
  152.         $this->oldId $oldId;
  153.         return $this;
  154.     }
  155.     public function getCompliance(): ?Compliance
  156.     {
  157.         return $this->compliance;
  158.     }
  159.     public function setCompliance(?Compliance $compliance): self
  160.     {
  161.         $this->compliance $compliance;
  162.         return $this;
  163.     }
  164.     public function getSite(): ?Site
  165.     {
  166.         return $this->site;
  167.     }
  168.     public function setSite(?Site $site): self
  169.     {
  170.         $this->site $site;
  171.         return $this;
  172.     }
  173.     public function getUser(): ?User
  174.     {
  175.         return $this->user;
  176.     }
  177.     public function setUser(?User $user): self
  178.     {
  179.         $this->user $user;
  180.         return $this;
  181.     }
  182.     public function getAnnotationNvs()
  183.     {
  184.         return $this->annotationNvs;
  185.     }
  186.     public function getAnnotation()
  187.     {
  188.         return $this->annotation;
  189.     }
  190.     public function getComment()
  191.     {
  192.         return $this->comment;
  193.     }
  194.     public function setAnnotationNvs($annotationNvs)
  195.     {
  196.         $this->annotationNvs $annotationNvs;
  197.         return $this;
  198.     }
  199.     public function setAnnotation($annotation)
  200.     {
  201.         $this->annotation $annotation;
  202.         return $this;
  203.     }
  204.     public function setComment($comment)
  205.     {
  206.         $this->comment $comment;
  207.         return $this;
  208.     }
  209.     public function getSection(): ?Section
  210.     {
  211.         return $this->section;
  212.     }
  213.     public function setSection(?Section $section): self
  214.     {
  215.         $this->section $section;
  216.         return $this;
  217.     }
  218.     public function getDocument(): ?Document
  219.     {
  220.         return $this->document;
  221.     }
  222.     public function setDocument(?Document $document): self
  223.     {
  224.         $this->document $document;
  225.         return $this;
  226.     }
  227.     public function getEvaluationDate(): ?\DateTimeImmutable
  228.     {
  229.         return $this->evaluationDate;
  230.     }
  231.     public function setEvaluationDate(\DateTimeImmutable $evaluationDate): self
  232.     {
  233.         $this->evaluationDate $evaluationDate;
  234.         return $this;
  235.     }
  236.     public function getStatus(): ?EvaluationStatus
  237.     {
  238.         return $this->status;
  239.     }
  240.     public function setStatus(?EvaluationStatus $status): self
  241.     {
  242.         $this->status $status;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return Collection<int, ActionPlan>
  247.      */
  248.     public function getActionPlans(): Collection
  249.     {
  250.         return $this->actionPlans;
  251.     }
  252.     public function addActionPlans(ActionPlan $actionPlan): self
  253.     {
  254.             $this->actionPlans->add($actionPlan);
  255.             $actionPlan->addEvaluation($this);
  256.         return $this;
  257.     }
  258.     public function removeActionPlan(ActionPlan $actionPlan): self
  259.     {
  260.         $this->actionPlans->removeElement($actionPlan);
  261.         return $this;
  262.     }
  263. //
  264. //    #[Groups(['compliance.get', 'evaluation.get'])]
  265. //    public function getLiveStatus()
  266. //    {
  267. //        $lastUpdateEvaluation = $this->getEvaluationDate()? (int) (new \DateTimeImmutable('now'))->diff($this->getEvaluationDate())->format('%a') : 0;
  268. //        $year = $this->site->getCustomer()?->getYear() ? $this->site->getCustomer()?->getYear() : 3;
  269. //        $nbDays = $year ? $year*360 : 0;
  270. //        if(($nbDays && $lastUpdateEvaluation >= $nbDays)){
  271. //            $status = DocumentStatus::WARNING_STATUS;
  272. //        }
  273. //        else{
  274. //            $status = 39;
  275. //        }
  276. //        return  DocumentStatus::STATUSES[$status];
  277. //    }
  278.     public function getEvaluationFile(): ?Media
  279.     {
  280.         return $this->evaluation_file;
  281.     }
  282.     public function setEvaluationFile(?Media $evaluation_file): self
  283.     {
  284.         $this->evaluation_file $evaluation_file;
  285.         return $this;
  286.     }
  287. }