Ver código fonte

Merge branch 'develop' into features/dashboard

François Drouhard 2 anos atrás
pai
commit
7e65089fa0

+ 9 - 5
assets/js/addCollectionWidget.js

@@ -47,7 +47,9 @@
             var $container = $($(this).attr("data-list-selector"));
             $li = $container.find('li');
             $li.each(function() {
-                $(this).find(':input').prop("readonly", true);
+                if (chemin !== "") {
+                    $(this).find(':input').prop("readonly", true);
+                }
                 addDeleteLink($(this));
             })
       
@@ -70,11 +72,13 @@
                 // create a new list element and add it to the list
                 var newElem = jQuery(list.attr('data-widget-tags')).html(newWidget);
                 
-                requete (chemin, function(output) {
-                    newElem.find(':input').autocomplete({
-                        source: output
+                if (chemin !== "") {
+                    requete (chemin, function(output) {
+                        newElem.find(':input').autocomplete({
+                            source: output
+                        });
                     });
-                })
+                }
                 
                 addDeleteLink(newElem);
 

+ 45 - 0
migrations/Version20230419104506.php

@@ -0,0 +1,45 @@
+<?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 Version20230419104506 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('ALTER TABLE media_video ADD film_id INT NOT NULL');
+
+        foreach($this->connection->fetchAllAssociative('SELECT id, media_video_id FROM film WHERE media_video_id IS NOT NULL') as $film) {
+            $this->addSql('UPDATE media_video SET film_id = :idFilm WHERE id = :mediaVideoIdFilm', [
+                'idFilm' => $film['id'],
+                'mediaVideoIdFilm' => $film['media_video_id']
+            ]);
+        }
+
+        $this->addSql('DELETE FROM media_video WHERE (film_id = 0)');
+
+        $this->addSql('ALTER TABLE media_video ADD CONSTRAINT FK_63DE1E9D567F5183 FOREIGN KEY (film_id) REFERENCES film (id)');
+        $this->addSql('CREATE INDEX IDX_63DE1E9D567F5183 ON media_video (film_id)');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE media_video DROP FOREIGN KEY FK_63DE1E9D567F5183');
+        $this->addSql('DROP INDEX IDX_63DE1E9D567F5183 ON media_video');
+        $this->addSql('ALTER TABLE media_video DROP film_id');
+    }
+}

+ 35 - 0
migrations/Version20230419174011.php

@@ -0,0 +1,35 @@
+<?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 Version20230419174011 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('ALTER TABLE film DROP FOREIGN KEY FK_8244BE2226A02EFC');
+        $this->addSql('DROP INDEX UNIQ_8244BE2226A02EFC ON film');
+        $this->addSql('ALTER TABLE film DROP media_video_id');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE film ADD media_video_id INT DEFAULT NULL');
+        $this->addSql('ALTER TABLE film ADD CONSTRAINT FK_8244BE2226A02EFC FOREIGN KEY (media_video_id) REFERENCES media_video (id)');
+        $this->addSql('CREATE UNIQUE INDEX UNIQ_8244BE2226A02EFC ON film (media_video_id)');
+    }
+}

+ 1 - 0
src/Controller/VideothequeController.php

@@ -15,6 +15,7 @@ use App\Form\FilmType;
 use App\Repository\CommentaireRepository;
 use App\Repository\FilmRepository;
 use App\Repository\GenreRepository;
+use App\Repository\MediaVideoRepository;
 use App\Repository\RealisateurRepository;
 use App\Service\CommentaireManager;
 use App\Service\FilmManager;

+ 38 - 2
src/Entity/Film.php

@@ -3,8 +3,8 @@
 namespace App\Entity;
 
 use App\Repository\FilmRepository;
+use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
-use Doctrine\DBAL\Types\DateImmutableType;
 use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
@@ -44,11 +44,13 @@ class Film
     
     private ?int $nbComs = null;
 
+    /*
     #[Assert\Valid()]
     #[ORM\OneToOne(targetEntity: MediaVideo::class, cascade: ["persist","remove"])]
     #[ORM\JoinColumn(nullable: true)]
     
     private ?MediaVideo $mediaVideo = null;
+    */
 
     #[ORM\ManyToMany(targetEntity: Realisateur::class, inversedBy: "films", cascade: ["persist"])]
     
@@ -84,6 +86,9 @@ class Film
     #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
     private ?\DateTimeImmutable $dateSortie = null;
 
+    #[ORM\OneToMany(mappedBy: 'film', targetEntity: MediaVideo::class, orphanRemoval: true, cascade: ['persist'])]
+    private ?Collection $mediaVideos = null;
+
     public function __construct()
     {
         $this->realisateurs = new \Doctrine\Common\Collections\ArrayCollection();
@@ -92,6 +97,7 @@ class Film
         $this->genres = new \Doctrine\Common\Collections\ArrayCollection();
         $this->commentaires = new \Doctrine\Common\Collections\ArrayCollection();
         $this->setDateSubmited(new \DateTime());
+        $this->mediaVideos = new ArrayCollection();
     }
 
     public function getAuthered(): ?User
@@ -310,7 +316,7 @@ class Film
         return $this;
     }
 
-    public function getMediaVideo(): ?MediaVideo
+    /*public function getMediaVideo(): ?MediaVideo
     {
         return $this->mediaVideo;
     }
@@ -319,6 +325,36 @@ class Film
     {
         $this->mediaVideo = $mediaVideo;
 
+        return $this;
+    }*/
+
+    /**
+     * @return Collection<int, MediaVideo>
+     */
+    public function getMediaVideos(): ?Collection
+    {
+        return $this->mediaVideos;
+    }
+
+    public function addMediaVideo(MediaVideo $mediaVideo): self
+    {
+        if (!$this->mediaVideos->contains($mediaVideo)) {
+            $this->mediaVideos->add($mediaVideo);
+            $mediaVideo->setFilm($this);
+        }
+
+        return $this;
+    }
+
+    public function removeMediaVideo(MediaVideo $mediaVideo): self
+    {
+        if ($this->mediaVideos->removeElement($mediaVideo)) {
+            // set the owning side to null (unless already changed)
+            if ($mediaVideo->getFilm() === $this) {
+                $mediaVideo->setFilm(null);
+            }
+        }
+
         return $this;
     }
 

+ 26 - 0
src/Entity/MediaVideo.php

@@ -34,12 +34,21 @@ class MediaVideo
     
     private ?string $url = null;
 
+    #[ORM\ManyToOne(inversedBy: 'mediaVideos')]
+    #[ORM\JoinColumn(nullable: false)]
+    private ?Film $film = null;
+
     public function setFromTmdb(string $type, string $identif): void
     {
         $this->setType($type);
         $this->setIdentif($identif);
     }
 
+    public function __toString(): string
+    {
+        return "MediaVideo Entity";
+    }
+
     public function getId(): ?int
     {
         return $this->id;
@@ -230,4 +239,21 @@ class MediaVideo
         $video = "<iframe src='".$this->embedUrl()."' allowfullscreen></iframe>";
         return $video;
     }
+
+    public function getFilm(): ?Film
+    {
+        return $this->film;
+    }
+
+    public function setFilm(?Film $film): self
+    {
+        if ($film) {
+            if (!$film->getMediaVideos()->contains($this))
+            {
+                $film->addMediaVideo($this);
+            }
+        }
+        $this->film = $film;
+        return $this;
+    }
 }

+ 20 - 12
src/Form/FilmType.php

@@ -2,6 +2,7 @@
 
 namespace App\Form;
 
+use App\Entity\Film;
 use Symfony\Component\Form\Extension\Core\Type\CollectionType;
 use Symfony\Component\Form\Extension\Core\Type\TextType;
 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
@@ -31,31 +32,38 @@ class FilmType extends AbstractType
             ->add('lien', TextType::class, array(
                 'required'  => false
             ))
-            ->add('mediaVideo', MediaVideoType::class,array(
-                'required'  =>  false,
-            ))
+            ->add('mediaVideos',  CollectionType::class, [
+                'entry_type' => MediaVideoType::class,
+                'entry_options' =>  array('label'=>false),
+                'allow_add'     =>  true,
+                'allow_delete'  =>  true,
+                'by_reference'  => false
+            ])
             ->add('dateSortie', DateType::class, [
                 'input'     =>  'datetime_immutable',
                 'html5'     =>  true,
                 'widget'    =>  'single_text',
                 'required'  =>  false
             ])
-            ->add('information', TextareaType::class, array(
+            ->add('information', TextareaType::class, [
                 'required' => false,
-            ))
-            ->add('genres', CollectionType::class, array(
+                'attr'  => [
+                    'rows'  => 5
+                ]
+            ])
+            ->add('genres', CollectionType::class, [
                 'entry_type'    =>  GenreType::class,
                 'entry_options' =>  array('label'=>false),
                 'allow_add'     =>  true,
                 'allow_delete'  =>  true
-            ))
-            ->add('realisateurs', CollectionType::class, array(
+            ])
+            ->add('realisateurs', CollectionType::class, [
                 'entry_type'    =>  RealisateurType::class,
                 'entry_options' =>  array('label'=>false),
                 'allow_add'     =>  true,
                 'allow_delete'  =>  true,
                 'allow_extra_fields'    => true
-            ))
+            ])
 		    ->add('save', SubmitType::class, array('label' => 'Enregistrer'));
     }
     
@@ -64,9 +72,9 @@ class FilmType extends AbstractType
      */
     public function configureOptions(OptionsResolver $resolver)
     {
-        $resolver->setDefaults(array(
-            'data_class' => 'App\Entity\Film'
-        ));
+        $resolver->setDefaults([
+            'data_class' => Film::class
+        ]);
     }
 
     /**

+ 2 - 2
src/Form/MediaVideoType.php

@@ -16,8 +16,8 @@ class MediaVideoType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder->add('url', TextType::class, array(
-            'label' => 'Url de la vidéo',
-            'required'  =>false
+            'label'     => false,
+            'row_attr'  => ['class' =>  'input-group']
         ));
     }/**
      * {@inheritdoc}

+ 8 - 2
src/Service/FilmManager.php

@@ -17,6 +17,7 @@ class FilmManager {
         protected EntityManagerInterface $em,
         protected UniciteCollections $uc,
         protected CommentaireManager $cm,
+        protected MediaVideoManager $mvm,
         Security $security
     )
     {
@@ -41,10 +42,15 @@ class FilmManager {
     {
         $commentaires = $film->getCommentaires();
         /** @var \App\Entity\Commentaire $commentaire */
-        foreach($commentaires as $commentaire)
-        {
+        foreach($commentaires as $commentaire) {
             $this->cm->delCommentaire($commentaire);
         }
+
+        $mediaVideos = $film->getMediaVideos();
+        /** @var \App\Entity\MediaVideo $mediaVideos */
+        foreach($mediaVideos as $media) {
+            $this->mvm->delMediaVideo($media);
+        }
         $this->em->remove($film);
 
         $this->em->flush();

+ 21 - 0
src/Service/MediaVideoManager.php

@@ -0,0 +1,21 @@
+<?php 
+
+namespace App\Service;
+
+use App\Entity\MediaVideo;
+use Doctrine\ORM\EntityManagerInterface;
+
+class MediaVideoManager
+{
+    public function __construct(protected EntityManagerInterface $em)
+    {
+        
+    }
+    public function delMediaVideo(MediaVideo $mediaVideo, bool $flush = false): void
+    {
+        $this->em->remove($mediaVideo);
+        if ($flush) {
+            $this->em->flush();
+        }
+    }
+}

+ 1 - 1
src/Service/TmdbApiService.php

@@ -131,7 +131,7 @@ class TmdbApiService
         if (!empty($videoTmdb)) {
             $video = new MediaVideo();
             $video->setFromTmdb($videoTmdb['type'], $videoTmdb['identif']);
-            $film->setMediaVideo($video);
+            $film->addMediaVideo($video);
         }
 
         $film = $this->uc->assureUniciteCollections($film);

+ 30 - 4
templates/videotheque/form.html.twig

@@ -12,14 +12,40 @@
                     {% form_theme form 'bootstrap_5_layout.html.twig' %}
                     {{ form_row(form.information) }}
 
+                    {#
                     {{ form_label(form.mediaVideo, 'Bande annonce') }}
                     {{ form_errors(form.mediaVideo) }}
                     {{ form_widget(form.mediaVideo) }}
-                    
+                    #}
+                </div>
+                <div class="">
+                    <div class="card mb-3">
+                        <div class="card-header">
+                            {{ form_label(form.mediaVideos, 'Bandes annonces') }}
+                        </div>
+                        <div class="card-body">
+                            <button type="button" id="add_media-video" class="btn btn-link add-another-collection-widget mb-3" data-path="" data-list-selector="#media-video-fields-list">Ajouter une bande annonce</button>
+                            <ul id="media-video-fields-list"
+                                data-prototype="{{ form_widget(form.mediaVideos.vars.prototype)|e }}"
+                                data-widget-tags="{{ '<li class="list-group-item mb-3"></li>'|e }}"
+                                data-widget-counter="{{ form.children|length }}">
+                                {% for mediaVideoField in form.mediaVideos %}
+                                <li class="list-group-item mb-3">
+                                    {{ form_widget(mediaVideoField) }}
+                                    {{ form_errors(mediaVideoField) }}
+                                </li>
+                                {% else %}
+                                    {{ form_widget(form.mediaVideos) }}
+                                    {{ form_errors(form.mediaVideos) }}
+                                {% endfor %}
+                            </ul>
+                        </div>
+                    </div>
                 </div>
             </div>
+
             <div class="col-md">
-                <div class="card">
+                <div class="card mb-3">
                     <div class="card-header">
                         {{ form_label(form.genres, 'Genres') }}
                     </div>
@@ -43,7 +69,7 @@
                 </div>
             </div>
             <div class="col-md">
-                <div class="card">
+                <div class="card mb-3">
                     <div class="card-header">
                         {{ form_label(form.realisateurs, 'Réalisateurs') }}
                     </div>
@@ -65,8 +91,8 @@
                         </ul>
                     </div>
                 </div>
-
             </div>
+            
         </div>
     </div>
     {{ form_rest(form) }}

+ 5 - 5
templates/videotheque/voirfilm.html.twig

@@ -144,13 +144,13 @@
                     <h5>Bande Annonce</h5>
                 </div>
                 <div class="card-body text-center">
-                    {% if film.mediaVideo.video is defined %}
-                        <div class="ratio ratio-4x3">
-                            {{ film.mediaVideo.video|raw }}
+                    {% for mediaVideo in film.mediaVideos %}
+                        <div class="ratio ratio-4x3 mb-3">
+                            {{ mediaVideo.video|raw }}
                         </div>
-                    {% else %}
+                    {% else %}  
                         <p>Pas encore de bande annonce</p>
-                    {% endif %}
+                    {% endfor %}
                 </div>
             </div>
         </div>