Quellcode durchsuchen

Passage de la vue en enum

François Drouhard vor 9 Monaten
Ursprung
Commit
0734b56fc4
4 geänderte Dateien mit 13 neuen und 12 gelöschten Zeilen
  1. 5 5
      src/Config/View.php
  2. 4 4
      src/Controller/ProfilController.php
  3. 1 1
      src/Entity/Profile.php
  4. 3 2
      src/Form/ProfileType.php

+ 5 - 5
src/Config/View.php

@@ -2,8 +2,8 @@
 
 namespace App\Config;
 
-enum View {
-    case TABLEAU;
-    case VIGNETTE;
-}
-
+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();
 

+ 1 - 1
src/Entity/Profile.php

@@ -26,7 +26,7 @@ class Profile
     private ?User $user = null;
 
 
-    #[ORM\Column(type: Types::INTEGER)]
+    #[ORM\Column(type: Types::INTEGER, enumType: View::class)]
 
     private ?View $view = null;
 

+ 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'