Просмотр исходного кода

Merge branch 'improvement/views' into develop

François Drouhard 9 месяцев назад
Родитель
Сommit
89adc27829

+ 9 - 0
src/Config/View.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace App\Config;
+
+enum View: int
+{
+    case TABLEAU = 0;
+    case VIGNETTE = 1;
+}

+ 4 - 4
src/Controller/ProfilController.php

@@ -2,7 +2,7 @@
 
 namespace App\Controller;
 
-use App\Entity\Profile;
+use App\Config\View;
 use Doctrine\ORM\EntityManagerInterface;
 use App\Form\UserEditProfilType;
 use App\Form\ProfileType;
@@ -59,10 +59,10 @@ class ProfilController extends AbstractController
         /** @var \App\Entity\User $user */
         $user = $this->getUser();
         $profile = $user->getProfile();
-        if ($profile->getView() == Profile::$VIEW['liste']) {
-            $profile->setView(Profile::$VIEW['vignette']);
+        if ($profile->getView() == View::TABLEAU) {
+            $profile->setView(View::VIGNETTE);
         } else {
-            $profile->setView(Profile::$VIEW['liste']);
+            $profile->setView(View::TABLEAU);
         }
         $em->flush();
 

+ 9 - 7
src/Entity/Profile.php

@@ -2,18 +2,20 @@
 
 namespace App\Entity;
 
+use App\Config\View;
 use App\Repository\ProfileRepository;
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 
 #[ORM\Entity(repositoryClass: ProfileRepository::class)]
 class Profile
 {
-    public static $VIEW = ['liste' => 0, 'vignette' => 1];
+    //public static $VIEW = ['liste' => 0, 'vignette' => 1];
 
 
     #[ORM\Id]
     #[ORM\GeneratedValue]
-    #[ORM\Column(type: "integer")]
+    #[ORM\Column(type: Types::INTEGER)]
 
     private ?int $id = null;
 
@@ -24,13 +26,13 @@ class Profile
     private ?User $user = null;
 
 
-    #[ORM\Column(type: "integer")]
+    #[ORM\Column(type: Types::INTEGER, enumType: View::class)]
 
-    private ?int $view = null;
+    private ?View $view = null;
 
     public function __construct()
     {
-        $this->setView(Profile::$VIEW['vignette']);
+        $this->setView(View::VIGNETTE);
     }
 
     public function getId(): ?int
@@ -50,12 +52,12 @@ class Profile
         return $this;
     }
 
-    public function getView(): ?int
+    public function getView(): ?View
     {
         return $this->view;
     }
 
-    public function setView(?int $view): self
+    public function setView(?View $view): self
     {
         $this->view = $view;
 

+ 3 - 2
src/Form/ProfileType.php

@@ -2,6 +2,7 @@
 
 namespace App\Form;
 
+use App\Config\View;
 use App\Entity\Profile;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -18,8 +19,8 @@ class ProfileType extends AbstractType
                 'expanded'  => true,
                 'multiple'  => false,
                 'choices'   => [
-                    'Liste' => 0,
-                    'Vignette'  => 1
+                    'Liste' => View::TABLEAU,
+                    'Vignette'  => View::VIGNETTE
                 ],
                 'label_attr'    =>  [
                     'class'     =>  'pt-0'

+ 3 - 1
src/Service/OptionsManager.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Config\View;
 use App\Entity\User;
 use App\Entity\Profile;
 use Symfony\Bundle\SecurityBundle\Security;
@@ -23,7 +24,8 @@ class OptionsManager
 
     public function vue(): string
     {
-        if ($this->options->getView() === 0)
+        dump(View::TABLEAU);
+        if ($this->options->getView() === View::TABLEAU)
         {
             return "tableaux";
         } else {