Răsfoiți Sursa

bandes annonces

François 6 ani în urmă
părinte
comite
eb912aaa84

+ 1 - 1
assets/js/app.js

@@ -9,6 +9,6 @@ import 'jquery-ui/ui/widgets/autocomplete';
 
 $(document).ready(function() {
     $(function() {
-        $('[data-toggle="tootip"]').tooltip();
+        $('[data-toggle="tooltip"]').tooltip();
     })
 })

+ 0 - 3
src/AppBundle/Controller/VideothequeController.php

@@ -3,7 +3,6 @@
 namespace AppBundle\Controller;
 
 use AppBundle\Entity\Commentaire;
-use AppBundle\Entity\Realisateur;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\JsonResponse;
@@ -11,7 +10,6 @@ use Symfony\Component\Routing\Annotation\Route;
 use Symfony\Component\HttpFoundation\Request;
 use AppBundle\Entity\Film;
 use AppBundle\Form\FilmType;
-use Symfony\Component\Serializer\Tests\Fixtures\NullableConstructorArgumentDummy;
 
 class VideothequeController extends Controller
 {
@@ -51,7 +49,6 @@ class VideothequeController extends Controller
 		if ($form->isSubmitted() && $form->isValid())
 		{
             $realisateurs = $film->getRealisateurs();
-
             foreach ($realisateurs as $realisateur)
             {
                 if ($realisateur->getId() == null)

+ 21 - 0
src/AppBundle/Entity/Film.php

@@ -58,6 +58,11 @@ class Film
         $this->dateSubmited = $dateSubmited;
     }
 
+    /**
+     * @ORM\OneToOne(targetEntity="AppBundle\Entity\MediaVideo", cascade={"persist","remove"})
+     */
+    private $mediaVideo;
+
     /**
      * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Realisateur", inversedBy="films", cascade="persist")
      * @var \Doctrine\Common\Collections\Collection
@@ -84,6 +89,22 @@ class Film
      */
     private $usersWhoSeen;
 
+    /**
+     * @return mixed
+     */
+    public function getMediaVideo()
+    {
+        return $this->mediaVideo;
+    }
+
+    /**
+     * @param mixed $mediaVideo
+     */
+    public function setMediaVideo(\AppBundle\Entity\MediaVideo $mediaVideo)
+    {
+        $this->mediaVideo = $mediaVideo;
+    }
+
     /**
      * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Genre", cascade={"persist"})
      * @var \Doctrine\Common\Collections\Collection

+ 268 - 0
src/AppBundle/Entity/MediaVideo.php

@@ -0,0 +1,268 @@
+<?php
+
+namespace AppBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * MediaVideo
+ *
+ * @ORM\Table(name="media_video")
+ * @ORM\Entity(repositoryClass="AppBundle\Repository\MediaVideoRepository")
+ * @ORM\HasLifecycleCallbacks // Permet d’utiliser des événements
+ */
+class MediaVideo
+{
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="type", type="string", length=255)
+     */
+    private $type;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="identif", type="string", length=255)
+     */
+    private $identif;
+
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="date", type="datetime")
+     */
+    private $date;
+
+    /**
+     * @Assert\Regex(
+     *     pattern="#^(http|https)://(www.youtube.com|www.dailymotion.com|vimeo.com)/#",
+     *     match=true,
+     *     message="L'url doit correspondre à l'url d'une vidéo Youtube, DailyMotion ou Vimeo"
+     * )
+     */
+    private $url;
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->setDate(new \DateTime());
+    }
+
+    /**
+     * @return \DateTime
+     */
+    public function getDate()
+    {
+        return $this->date;
+    }
+
+    /**
+     * @param \DateTime $date
+     */
+    public function setDate($date)
+    {
+        $this->date = $date;
+    }
+
+    /**
+     * Get id
+     *
+     * @return int
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * @return string
+     *
+     */
+    public function getUrl()
+    {
+        return $this->url;
+    }
+
+    public function setUrl($url)
+    {
+        return $this->url = $url;
+    }
+
+    /**
+     * Set type
+     *
+     * @param string $type
+     *
+     * @return MediaVideo
+     */
+    public function setType($type)
+    {
+        $this->type = $type;
+
+        return $this;
+    }
+
+    /**
+     * Get type
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return $this->type;
+    }
+
+    /**
+     * Set identif
+     *
+     * @param string $identif
+     *
+     * @return MediaVideo
+     */
+    public function setIdentif($identif)
+    {
+        $this->identif = $identif;
+
+        return $this;
+    }
+
+    /**
+     * Get identif
+     *
+     * @return string
+     */
+    public function getIdentif()
+    {
+        return $this->identif;
+    }
+
+    /////////////////////
+    // Méthodes
+    private function youtubeId($url)
+    {
+        $tableaux = explode("=", $url);  // découpe l’url en deux  avec le signe ‘=’
+
+        $this->setIdentif($tableaux[1]);  // ajoute l’identifiant à l’attribut identif
+        $this->setType('youtube');  // signale qu’il s’agit d’une video youtube et l’inscrit dans l’attribut $type
+    }
+
+    private function dailymotionId($url)
+    {
+        $cas = explode("/", $url); // On sépare la première partie de l'url des 2 autres
+        $idb = $cas[4];  // On récupère la partie qui nous intéressent
+        $bp = explode("_", $idb);  // On sépare l'identifiant du reste
+        $id = $bp[0]; // On récupère l'identifiant
+
+        $this->setIdentif($id);  // ajoute l’identifiant à l’attribut identif
+        $this->setType('dailymotion'); // signale qu’il s’agit d’une video dailymotion et l’inscrit dans l’attribut $type
+    }
+
+    private function vimeoId($url)
+    {
+        $tableaux = explode("/", $url);  // on découpe l’url grâce au « / »
+        $id = $tableaux[count($tableaux)-1];  // on reticent la dernière partie qui contient l’identifiant
+        $this->setIdentif($id);  // ajoute l’identifiant à l’attribut identif
+        $this->setType('vimeo');  // signale qu’il s’agit d’une video vimeo et l’inscrit dans l’attribut $type
+    }
+
+    /**
+     * @ORM\PrePersist() // Les trois événement suivant s’exécute avant que l’entité soit enregistée
+     * @ORM\PreUpdate()
+     * @ORM\PreFlush()
+     */
+    public function extractIdentif()
+    {
+        $url = $this->getUrl();  // on récupère l’url
+
+        if (preg_match("#^(http|https)://www.youtube.com/#", $url))  // Si c’est une url Youtube on execute la fonction correspondante
+        {
+            $this->youtubeId($url);
+        }
+        else if((preg_match("#^(http|https)://www.dailymotion.com/#", $url))) // Si c’est une url Dailymotion on execute la fonction correspondante
+        {
+            $this->dailymotionId($url);
+        }
+        else if((preg_match("#^(http|https)://vimeo.com/#", $url))) // Si c’est une url Vimeo on execute la fonction correspondante
+        {
+            $this->vimeoId($url);
+        }
+
+    }
+
+    private function embedUrl()
+    {
+        $control = $this->getType();  // on récupère le type de la vidéo
+        $id = strip_tags($this->getIdentif()); // on récupère son identifiant
+
+        if ($control == 'youtube') {
+            $embed = "https://www.youtube-nocookie.com/embed/" . $id;
+            return $embed;
+        } else if ($control == 'dailymotion') {
+            $embed = "https://www.dailymotion.com/embed/video/" . $id;
+            return $embed;
+        } else if ($control == 'vimeo') {
+            $embed = "https://player.vimeo.com/video/" . $id;
+            return $embed;
+        }
+    }
+
+    private function url()
+    {
+        $control = $this->getType();  // on récupère le type de la vidéo
+        $id = strip_tags($this->getIdentif()); // on récupère son identifiant
+
+        if ($control == 'youtube') {
+            $embed = "https://www.youtube.com/watch?v=" . $id;
+            return $embed;
+        } else if ($control == 'dailymotion') {
+            $embed = "https://www.dailymotion.com/video/" . $id;
+            return $embed;
+        } else if ($control == 'vimeo') {
+            $embed = "https://vimeo.com/" . $id;
+            return $embed;
+        }
+    }
+
+
+    public function image()
+    {
+        $control = $this->getType();  // on récupère le type de la vidéo
+        $id = strip_tags($this->getIdentif()); // on récupère son identifiant
+
+        if ($control == 'youtube') {
+            $image = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
+            return $image;
+        } else if ($control == 'dailymotion') {
+            $image = 'https://www.dailymotion.com/thumbnail/150x120/video/' . $id . '';
+            return $image;
+        } else if ($control == 'vimeo') {
+            $hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/" . $id . ".php"));
+            $image = $hash[0]['thumbnail_small'];
+            return $image;
+        }
+    }
+
+
+    public function video()
+    {
+        $video = "<iframe width='100%' height='100%' src='".$this->embedUrl()."'  frameborder='0'  allowfullscreen></iframe>";
+        return $video;
+    }
+
+
+
+
+}

+ 4 - 0
src/AppBundle/Form/FilmType.php

@@ -4,6 +4,7 @@ namespace AppBundle\Form;
 
 use AppBundle\Entity\Film;
 use AppBundle\Entity\Genre;
+use AppBundle\Entity\MediaVideo;
 use Doctrine\ORM\Mapping\Entity;
 use Symfony\Bridge\Doctrine\Form\Type\EntityType;
 use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@@ -31,6 +32,9 @@ class FilmType extends AbstractType
                 'html5'     =>  true,
                 'required'  =>  false
             ))
+            ->add('mediaVideo', MediaVideoType::class,array(
+                //'required'  =>  false,
+            ))
             ->add('genres', CollectionType::class, array(
                 'entry_type'    =>  GenreType::class,
                 'entry_options' =>  array('label'=>false),

+ 40 - 0
src/AppBundle/Form/MediaVideoType.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace AppBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
+
+class MediaVideoType extends AbstractType
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function buildForm(FormBuilderInterface $builder, array $options)
+    {
+        $builder->add('url', TextType::class, array(
+            'label' => 'Url de la vidéo',
+                'required'  =>false
+        ));
+    }/**
+     * {@inheritdoc}
+     */
+    public function configureOptions(OptionsResolver $resolver)
+    {
+        $resolver->setDefaults(array(
+            'data_class' => 'AppBundle\Entity\MediaVideo',
+        ));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
+    {
+        return 'appbundle_mediavideo';
+    }
+
+
+}

+ 13 - 0
src/AppBundle/Repository/MediaVideoRepository.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace AppBundle\Repository;
+
+/**
+ * MediaVideoRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class MediaVideoRepository extends \Doctrine\ORM\EntityRepository
+{
+}

+ 3 - 2
src/AppBundle/Resources/public/assets/collectiontypeadd.js

@@ -42,7 +42,7 @@ function collections (reponse, nomDuDiv, nomDuBouton) {
     } else {
         // S'il existe déjà des catégories, on ajoute un lien de suppression pour chacune d'entre elles
         $container.children('fieldset').each(function() {
-            $container.find(':input').prop("disabled",  true);
+            //$container.find(':input').prop("disabled",  true);
             $container.find(':input').autocomplete({
                 source: reponse
             });
@@ -80,7 +80,8 @@ function collections (reponse, nomDuDiv, nomDuBouton) {
     // La fonction qui ajoute un lien de suppression d'une catégorie
     function addDeleteLink($prototype) {
         // Création du lien
-        let $deleteLink = $('<a href="#" class="btn btn-danger">Supprimer</a>');
+        //let $deleteLink = $('<a href="#" class="btn btn-danger">Supprimer</a>');
+        let $deleteLink = $('<a href="#"><i class="fa fa-trash" style="color:Tomato;"></i></a>');
 
         // Ajout du lien
         $prototype.append($deleteLink);

+ 4 - 0
src/AppBundle/Resources/views/videotheque/form.html.twig

@@ -8,6 +8,10 @@
                 <div class="form-group row">
                     {{ form_row(form.annee) }}
                 </div>
+                <div class="form-group row">
+                    {{ form_label(form.mediaVideo, 'Bande annonce') }}
+                    {{ form_widget(form.mediaVideo) }}
+                </div>
             </div>
             <div class="col">
                 <div class="card">

+ 68 - 57
src/AppBundle/Resources/views/videotheque/voirfilm.html.twig

@@ -1,74 +1,85 @@
 {% extends "@App/videotheque/base.html.twig" %}
 
 {% block title %}Fiche film{% endblock %}
-{% block titre %}
-    {%  if film.usersWantToView.contains(app.user) %}
-        <a href="#" class="boutonVoir" data-content="{{ film.id }}"><i class="fa fa-star"></i></a>
-    {%  else %}
-        <a href="#" class="boutonVoir" data-content="{{ film.id }}"><i class="fa fa-star-o"></i></a>
-    {%  endif %}
-    {{ film.titre }}
-    {% if film.usersWhoSeen.contains(app.user) %}
-        <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i><i class="badge badge-success">Vu</i></a>
-        {#<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-success">Vu</i></a>#}
-    {%  else %}
-        <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-danger">Pas vu</i><i class="badge badge-secondary">Vu</i></a>
-        {#<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i></a>#}
-    {%  endif %}
-{% endblock %}
+{% block titre %}{% endblock %}
 
 {%  block body %}
     <div class="row">
-        <div class="col">
-            <div class="card mb-3">
-                <div class="card-body">
-                    <h5 class="card-title">
-                        Fiche technique
-                    </h5>
-                    <div class="container-fluid">
-                        <div class="row">
-                            <div class="col">
-                                <p><strong>Réalisateur(s)</strong></p>
-                                <ul class="">
-                                {% for realisateur in film.realisateurs %}
-                                    <li class=""><a href="{{ path('realisateur_modifier', {'id': realisateur.id}) }}">{{ realisateur.nomComplet }}</a></li>
-                                {% endfor %}
-                                </ul>
+        <div class="col-8">
+            <h1>
+                {%  if film.usersWantToView.contains(app.user) %}
+                    <a href="#" class="boutonVoir" data-content="{{ film.id }}"><i class="fa fa-star"></i></a>
+                {%  else %}
+                    <a href="#" class="boutonVoir" data-content="{{ film.id }}"><i class="fa fa-star-o"></i></a>
+                {%  endif %}
+                {{ film.titre }}
+                {% if film.usersWhoSeen.contains(app.user) %}
+                    <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i><i class="badge badge-success">Vu</i></a>
+                    {#<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-success">Vu</i></a>#}
+                {%  else %}
+                    <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-danger">Pas vu</i><i class="badge badge-secondary">Vu</i></a>
+                    {#<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i></a>#}
+                {%  endif %}
+            </h1>
+            <div class="row">
+                <div class="col-7">
+                    <div class="card mb-3">
+                        <div class="card-body">
+                            <h5 class="card-title">
+                                Fiche technique
+                            </h5>
+                            <div class="container-fluid">
+                                <div class="row">
+                                    <div class="col">
+                                        <p><strong>Réalisateur(s)</strong></p>
+                                        <ul class="">
+                                        {% for realisateur in film.realisateurs %}
+                                            <li class=""><a href="{{ path('realisateur_modifier', {'id': realisateur.id}) }}">{{ realisateur.nomComplet }}</a></li>
+                                        {% endfor %}
+                                        </ul>
+                                    </div>
+                                    <div class="col">
+                                        <p><strong>Année</strong> : {{ film.annee | date('Y') }}</p>
+                                        <p><strong>Genre</strong> :
+                                            {% for genre in film.genres %}
+                                            <a href="{{ path('genre_modifier', {'id': genre.id}) }}"><span class="badge badge-info">{{ genre.name }}</span></a>
+                                        {% endfor %}
+                                        </p>
+                                    </div>
+                                </div>
+                                <div class="text-right">
+                                    <a class="btn btn-link btn-sm" href="{{ path('videotheque_modifier', {'id': film.id}) }}">Modifier fiche du film</a>
+                                </div>
+
                             </div>
-                            <div class="col">
-                                <p><strong>Année</strong> : {{ film.annee | date('Y') }}</p>
-                                <p><strong>Genre</strong> :
-                                    {% for genre in film.genres %}
-                                    <a href="{{ path('genre_modifier', {'id': genre.id}) }}"><span class="badge badge-info">{{ genre.name }}</span></a>
+                        </div>
+                    </div>
+                    <div class="row">
+                        <div class="col">
+                            <p><strong>Suivi par</strong></p>
+                            <ul>
+                                {% for user in film.usersWantToView %}
+                                    <li>{{ user.username }}</li>
                                 {% endfor %}
-                                </p>
-                            </div>
+                            </ul>
                         </div>
-                        <div class="text-right">
-                            <a class="btn btn-link btn-sm" href="{{ path('videotheque_modifier', {'id': film.id}) }}">Modifier fiche du film</a>
+                        <div class="col">
+                            <p><strong>Vu par</strong></p>
+                            <ul>
+                                {% for user in film.usersWhoSeen %}
+                                    <li>{{ user.username }}</li>
+                                {% endfor %}
+                            </ul>
                         </div>
-
                     </div>
                 </div>
-            </div>
-            <div class="row">
-                <div class="col">
-                    <p><strong>Suivi par</strong></p>
-                    <ul>
-                        {% for user in film.usersWantToView %}
-                            <li>{{ user.username }}</li>
-                        {% endfor %}
-                    </ul>
-                </div>
-                <div class="col">
-                    <p><strong>Vu par</strong></p>
-                    <ul>
-                        {% for user in film.usersWhoSeen %}
-                            <li>{{ user.username }}</li>
-                        {% endfor %}
-                    </ul>
+                <div class="col-5">
+                    <div style='height :200px ;width :300px'>
+                        {{ film.mediaVideo.video|raw }}
+                    </div>
                 </div>
             </div>
+
             <h3>Votre commentaire</h3>
             {{ include('@App/videotheque/form_commentaire.html.twig') }}
         </div>