Эх сурвалжийг харах

gestion des auteurs des jeux

garthh 1 сар өмнө
parent
commit
14b1ec48f3

+ 37 - 0
migrations/Version20250919165140.php

@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DoctrineMigrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\Migrations\AbstractMigration;
+
+/**
+ * Auto-generated Migration: Please modify to your needs!
+ */
+final class Version20250919165140 extends AbstractMigration
+{
+    public function getDescription(): string
+    {
+        return '';
+    }
+
+    public function up(Schema $schema): void
+    {
+        // this up() migration is auto-generated, please modify it to your needs
+        $this->addSql('CREATE TABLE author_game (gamemaster_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', game_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', INDEX IDX_C7C4B95396376157 (gamemaster_id), INDEX IDX_C7C4B953E48FD905 (game_id), PRIMARY KEY(gamemaster_id, game_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE author_game ADD CONSTRAINT FK_C7C4B95396376157 FOREIGN KEY (gamemaster_id) REFERENCES gamemaster (id) ON DELETE CASCADE');
+        $this->addSql('ALTER TABLE author_game ADD CONSTRAINT FK_C7C4B953E48FD905 FOREIGN KEY (game_id) REFERENCES game (id) ON DELETE CASCADE');
+        $this->addSql('ALTER TABLE gamemaster ADD is_author TINYINT(1) DEFAULT NULL');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE author_game DROP FOREIGN KEY FK_C7C4B95396376157');
+        $this->addSql('ALTER TABLE author_game DROP FOREIGN KEY FK_C7C4B953E48FD905');
+        $this->addSql('DROP TABLE author_game');
+        $this->addSql('ALTER TABLE gamemaster DROP is_author');
+    }
+}

+ 14 - 1
src/Controller/Admin/GamemasterController.php

@@ -89,7 +89,13 @@ final class GamemasterController extends AbstractController
                 $slug = $slugger->slug(strtolower($gamemaster->getPreferedName()));
                 $gamemaster->setSlug($slug);
             }
-
+            
+            // Flag auteur, si len(authorOfGames) > 0 -> isAuthor
+            if (count($form->get('authorOfGames')->getData()) > 0) {
+                $gamemaster->setIsAuthor(true);
+            } else {
+                $gamemaster->setIsAuthor(false);
+            }
             
             // Traiter l'image proposée
             $tmpPicture = $form->get('picture')->getData();
@@ -153,6 +159,13 @@ final class GamemasterController extends AbstractController
                 $slug = $slugger->slug(strtolower($gamemaster->getPreferedName()));
                 $gamemaster->setSlug($slug);
             }
+            
+            // Flag auteur, si len(authorOfGames) > 0 -> isAuthor
+            if (count($form->get('authorOfGames')->getData()) > 0) {
+                $gamemaster->setIsAuthor(true);
+            } else {
+                $gamemaster->setIsAuthor(false);
+            }
 
             
             // Traiter l'image proposée

+ 14 - 0
src/Controller/PartyController.php

@@ -134,6 +134,13 @@ final class PartyController extends AbstractController
 
                 $party->setGamemaster($gamemasterSelected);
                 $party->setGame($gameSelected);
+                
+                // Si gamemaster = author, alors !
+                if (in_array($party->getGame(), $party->getGamemaster()->getAuthorOfGames()->toArray())) {
+                    $party->setGamemasterIsAuthor(true);
+                } else {
+                    $party->setGamemasterIsAuthor(false);
+                }
 
                 $manager->persist($party);
                 $manager->flush();
@@ -217,6 +224,13 @@ final class PartyController extends AbstractController
 
                 $party->setGamemaster($gamemasterSelected);
                 $party->setGame($gameSelected);
+                
+                // Si gamemaster = author, alors !
+                if (in_array($party->getGame(), $party->getGamemaster()->getAuthorOfGames()->toArray())) {
+                    $party->setGamemasterIsAuthor(true);
+                } else {
+                    $party->setGamemasterIsAuthor(false);
+                }
 
                 $manager->persist($party);
                 $manager->flush();

+ 34 - 0
src/Entity/Game.php

@@ -87,6 +87,12 @@ class Game
     #[ORM\OneToMany(targetEntity: Party::class, mappedBy: 'game')]
     private Collection $parties;
 
+    /**
+     * @var Collection<int, Gamemaster>
+     */
+    #[ORM\ManyToMany(targetEntity: Gamemaster::class, mappedBy: 'authorOfGames')]
+    private Collection $authors;
+
     public function __construct()
     {
         $this->genre = new ArrayCollection();
@@ -94,6 +100,7 @@ class Game
         $this->gamemasters = new ArrayCollection();
         $this->eventsAssignedTo = new ArrayCollection();
         $this->parties = new ArrayCollection();
+        $this->authors = new ArrayCollection();
     }
 
     public function getId(): ?Uuid
@@ -395,6 +402,33 @@ class Game
     {
         return $this->ageRecommendation->shortLabel();
     }
+
+    /**
+     * @return Collection<int, Gamemaster>
+     */
+    public function getAuthors(): Collection
+    {
+        return $this->authors;
+    }
+
+    public function addAuthor(Gamemaster $author): static
+    {
+        if (!$this->authors->contains($author)) {
+            $this->authors->add($author);
+            $author->addAuthorOfGame($this);
+        }
+
+        return $this;
+    }
+
+    public function removeAuthor(Gamemaster $author): static
+    {
+        if ($this->authors->removeElement($author)) {
+            $author->removeAuthorOfGame($this);
+        }
+
+        return $this;
+    }
     
     
 

+ 47 - 0
src/Entity/Gamemaster.php

@@ -78,12 +78,23 @@ class Gamemaster
     #[ORM\OneToMany(targetEntity: Availability::class, mappedBy: 'gamemaster', orphanRemoval: true)]
     private Collection $availabilities;
 
+    #[ORM\Column(nullable: true)]
+    private ?bool $isAuthor = null;
+
+    /**
+     * @var Collection<int, Game>
+     */
+    #[ORM\ManyToMany(targetEntity: Game::class, inversedBy: 'authors')]
+    #[ORM\JoinTable(name: 'author_game')]
+    private Collection $authorOfGames;
+
     public function __construct()
     {
         $this->gamesCanMaster = new ArrayCollection();
         $this->eventsAssignedTo = new ArrayCollection();
         $this->parties = new ArrayCollection();
         $this->availabilities = new ArrayCollection();
+        $this->authorOfGames = new ArrayCollection();
     }
 
     public function getId(): ?Uuid
@@ -332,5 +343,41 @@ class Gamemaster
         return $this;
     }
 
+    public function isAuthor(): ?bool
+    {
+        return $this->isAuthor;
+    }
+
+    public function setIsAuthor(?bool $isAuthor): static
+    {
+        $this->isAuthor = $isAuthor;
+
+        return $this;
+    }
+
+    /**
+     * @return Collection<int, Game>
+     */
+    public function getAuthorOfGames(): Collection
+    {
+        return $this->authorOfGames;
+    }
+
+    public function addAuthorOfGame(Game $authorOfGame): static
+    {
+        if (!$this->authorOfGames->contains($authorOfGame)) {
+            $this->authorOfGames->add($authorOfGame);
+        }
+
+        return $this;
+    }
+
+    public function removeAuthorOfGame(Game $authorOfGame): static
+    {
+        $this->authorOfGames->removeElement($authorOfGame);
+
+        return $this;
+    }
+
 
 }

+ 20 - 0
src/Form/GamemasterType.php

@@ -115,6 +115,26 @@ class GamemasterType extends AbstractType
                 'help_attr' => ['class' => 'help'],
                 'help' => 'Sélectionner le compte à lier à ce MJ.',
             ])
+//             ->add('isAuthor', null, [
+//                 'label' => 'Auteur(rice) de jeu de rôles',
+//                 'label_attr' => ['class' => 'checkbox'],
+//                 'help' => 'Cochez si ce meneur(euse) de jeu est aussi auteur(rice).',
+//                 'attr' => ['class' => 'checkbox'],
+//                 'row_attr' => ['class' => 'field'],
+//                 'help_attr' => ['class' => 'help'],
+//             ])
+            ->add('authorOfGames', EntityType::class, [
+                'label' => 'Auteur(rice) des jeux',
+                'attr' => ['class' => 'checkboxes'],
+                'class' => Game::class,
+                'choice_label' => 'name',
+                'required' => false,
+                'expanded' => true,
+                'multiple' => true,
+                'label_attr' => ['class' => 'label'],
+                'choice_attr' => ['class' => 'checkbox'],
+                'help_attr' => ['class' => 'help'],
+            ])
         ;
     }
 

+ 8 - 8
src/Form/PartyType.php

@@ -27,14 +27,14 @@ class PartyType extends AbstractType
                 'row_attr' => ['class' => 'field'],
                 'help_attr' => ['class' => 'help'],
             ])
-            ->add('gamemasterIsAuthor', null, [
-                'label' => 'le(a) MJ est l\'auteur(rice) du jeu',
-                'label_attr' => ['class' => 'checkbox'],
-                'help' => 'Cochez si par partie est animée par l\'auteur(rice) du jeu.',
-                'attr' => ['class' => 'checkbox'],
-                'row_attr' => ['class' => 'field'],
-                'help_attr' => ['class' => 'help'],
-            ])
+//             ->add('gamemasterIsAuthor', null, [
+//                 'label' => 'le(a) MJ est l\'auteur(rice) du jeu',
+//                 'label_attr' => ['class' => 'checkbox'],
+//                 'help' => 'Cochez si par partie est animée par l\'auteur(rice) du jeu.',
+//                 'attr' => ['class' => 'checkbox'],
+//                 'row_attr' => ['class' => 'field'],
+//                 'help_attr' => ['class' => 'help'],
+//             ])
             ->add('minParticipants', null, [
                 'label' => 'Nombre minimum de participant(e)s',
                 'help' => 'Nombre minimum de participant(e)s pour permettre de jouer la partie.',

+ 2 - 2
templates/admin/event/config/gamemaster.html.twig

@@ -55,8 +55,8 @@
               <div class="content">
                 <p>
                   <strong>{{ gamemaster.preferedName }}</strong>
-                  <br/>
-                  {{ gamemaster.description }}
+                  {#<br/>
+                  {{ gamemaster.description }}#}
                 </p>
               </div>
             </div>

+ 10 - 0
templates/admin/gamemaster/edit.html.twig

@@ -61,12 +61,22 @@
         {{ form_help(form.gamesCanMaster) }}
     </div>
     </div>
+    
+        
+    <div class="box">
+    <div class="field">
+        {{ form_label(form.authorOfGames) }}
+        {{ form_widget(form.authorOfGames) }}
+        {{ form_help(form.authorOfGames) }}
+    </div>
+    </div>
 
     <div class="box">
         {{ form_row(form.linkToUser) }}
     </div>
 
 
+
     {{ form_widget(form) }}
     
 

+ 2 - 2
templates/party/_modal.edit.html.twig

@@ -38,11 +38,11 @@
         </select>
     </div>
     
-    <div class="field">
+{#    <div class="field">
         {{ form_widget(form.gamemasterIsAuthor) }}
         {{ form_label(form.gamemasterIsAuthor) }}
         {{ form_help(form.gamemasterIsAuthor) }}
-    </div>
+    </div>#}
     {{ form_row(form.description) }}
 
     <div class="box">