ソースを参照

fix entity mapping

Vincent GUFFON 3 年 前
コミット
264a08f456

+ 1 - 1
src/Entity/Booking/Course.php

@@ -68,7 +68,7 @@ class Course extends AbstractBooking
     #[ORM\JoinColumn(nullable: false)]
     protected Organization $organization;
 
-    #[ORM\ManyToOne]
+    #[ORM\ManyToOne(inversedBy: 'courses')]
     #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
     private Education $education;
 

+ 38 - 0
src/Entity/Education/CriteriaNotation.php

@@ -8,6 +8,7 @@ use App\Entity\Organization\Organization;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
 
 
 /**
@@ -40,6 +41,19 @@ class CriteriaNotation
     #[ORM\OneToMany(mappedBy: 'criteriaNotation', targetEntity: EducationNotationCriteriaConfig::class,  cascade: ['persist', 'remove'], orphanRemoval: true, )]
     private Collection $educationNotationCriteriaConfigs;
 
+    #[ORM\Column]
+    #[Assert\Choice(callback: ['\AppBundle\Enum\Education\TypeCriteriaEnum', 'toArray'], message: 'invalid-type')]
+    private string $type;
+
+    #[ORM\Column]
+    #[Assert\GreaterThanOrEqual(value: 0)]
+    #[Assert\Range(
+        notInRangeMessage: 'between_{{ min }}_and_{{ max }}',
+        min: 0,
+        max: 100
+    )]
+    private ?int $noteMax;
+
     public function __construct()
     {
         $this->educationNotations = new ArrayCollection();
@@ -153,4 +167,28 @@ class CriteriaNotation
 
         return $this;
     }
+
+    public function getType(): ?string
+    {
+        return $this->type;
+    }
+
+    public function setType(string $type): self
+    {
+        $this->type = $type;
+
+        return $this;
+    }
+
+    public function getNoteMax(): ?int
+    {
+        return $this->noteMax;
+    }
+
+    public function setNoteMax(int $noteMax): self
+    {
+        $this->noteMax = $noteMax;
+
+        return $this;
+    }
 }

+ 25 - 3
src/Entity/Education/EducationNotation.php

@@ -5,14 +5,16 @@ namespace App\Entity\Education;
 
 use ApiPlatform\Core\Annotation\ApiResource;
 use App\Entity\Core\Tagg;
+use App\Repository\Education\EducationNotationRepository;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
 
 /**
  * Classe ... qui ...
  */
-#[ORM\Entity]
+#[ORM\Entity(repositoryClass: EducationNotationRepository::class)]
 #[ApiResource(
     collectionOperations: [],
     itemOperations: [
@@ -32,11 +34,11 @@ class EducationNotation
 
     #[ORM\ManyToOne(inversedBy: 'educationNotations')]
     #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
-    private CriteriaNotation $criteriaNotation;
+    private ?CriteriaNotation $criteriaNotation;
 
     #[ORM\ManyToOne(inversedBy: 'educationNotations')]
     #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
-    private EducationNotationCriteriaConfig $criteriaNotationConfig;
+    private ?EducationNotationCriteriaConfig $criteriaNotationConfig;
 
     #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'educationNotations', cascade: ['persist'])]
     #[ORM\JoinTable(name: 'tag_educationNotation')]
@@ -44,6 +46,14 @@ class EducationNotation
     #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
     private Collection $tags;
 
+    #[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
+    #[Assert\Range(
+        notInRangeMessage: 'between_{{ min }}_and_{{ max }}',
+        min: 0,
+        max: 100
+    )]
+    private ?float $note;
+
     public function __construct()
     {
         $this->tags = new ArrayCollection();
@@ -113,4 +123,16 @@ class EducationNotation
 
         return $this;
     }
+
+    public function setNote(?float $note): self
+    {
+        $this->note = (!is_null($note)) ? (float)($note) : $note;
+        return $this;
+    }
+
+    public function getNote(): ?float
+    {
+        if(is_null($this->note)) return $this->note;
+        return round ( $this->note , 2 );
+    }
 }

+ 17 - 0
src/Enum/Education/TypeCriteriaEnum.php

@@ -0,0 +1,17 @@
+<?php
+declare(strict_types=1);
+
+
+namespace App\Enum\Education;
+
+use MyCLabs\Enum\Enum;
+
+/**
+ * Type de critère possible pour les notations
+ */
+class TypeCriteriaEnum extends Enum
+{
+    private const WITH_NOTATION   = 'WITH_NOTATION';
+    private const CUSTOM_NOTATION  = 'CUSTOM_NOTATION';
+    private const WITHOUT_NOTATION   = 'WITHOUT_NOTATION';
+}