Browse Source

Corrections avant merge en dev

François Drouhard 2 years ago
parent
commit
d592adea40

+ 2 - 1
config/packages/framework.yaml

@@ -21,7 +21,8 @@ framework:
         scoped_clients:
             tmdb.client:
                 base_uri: '%env(TMDB_URL)%'
-                #query:
+                query:
+                    language: 'fr'
                     #api_key: '%env(TMDB_APIKEY_V3)%'
                 headers:
                     Authorization: 'Bearer %env(TMDB_APIKEY_V4)%'

+ 6 - 2
src/Form/RechercheTmdbType.php

@@ -13,8 +13,12 @@ class RechercheTmdbType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options): void
     {
         $builder
-            ->add('recherche', TextType::class)
-            ->add('Rechercher', SubmitType::class)
+            ->add('recherche', TextType::class, [
+                'attr'  => [
+                    'placeholder' => 'search_in_tmdb'
+                ]
+            ])
+            ->add('rechercher', SubmitType::class)
         ;   
     }
 

+ 38 - 39
src/Service/TmdbApiService.php

@@ -13,7 +13,10 @@ class TmdbApiService
     protected int $nbResults = 0;
     protected array $films = [];
 
-    public function __construct(protected HttpClientInterface $tmdbClient, protected UniciteCollections $uc)
+    public function __construct(
+        protected HttpClientInterface $tmdbClient,
+        protected UniciteCollections $uc
+    )
     {
         
     }
@@ -24,14 +27,12 @@ class TmdbApiService
             $response = $this->tmdbClient->request(
                 'GET',
                 'search/movie',[
-                    'query' => [
-                        'language'  => 'fr',
+                    'query' => [                
                         'query' => $titre
                     ]
                 ]
             );
 
-            //dump($response->getContent());
             $this->content = $response->getContent();
             $this->jsonDecode();
         } catch (\Exception $e) {
@@ -48,8 +49,7 @@ class TmdbApiService
                 'GET',
                 'movie/'. $id ,[
                     'query' => [
-                        'language'  => 'fr',
-                        'append_to_response'    => 'credits'
+                        'append_to_response'    => 'credits,videos',
                     ]
                 ]
             );
@@ -75,7 +75,6 @@ class TmdbApiService
     {
         $json = json_decode($this->content);
 
-        //dump($json);
         $this->nbResults = $json->total_results;
         $entrees = $json->results;
 
@@ -91,43 +90,43 @@ class TmdbApiService
     {
         $filmTmdb = json_decode($this->getDetailMovie($filmTmdbId));
 
-            dump($filmTmdb);
-            
-            $film = new Film();
+        dump($filmTmdb);
+        
+        $film = new Film();
+        $film
+            ->setTitre($filmTmdb->title)
+            ->setInformation($filmTmdb->overview);
+
+        if (preg_match ("/^\d{4}-\d{2}-\d{2}$/", $filmTmdb->release_date))
+        {
+            $dateSortie = $filmTmdb->release_date;
+            dump($dateSortie);
+            $annee = substr($dateSortie, 0, 4) . '-01-01';
+            dump($annee);
             $film
-                ->setTitre($filmTmdb->title)
-                ->setInformation($filmTmdb->overview);
-
-            if (preg_match ("/^\d{4}-\d{2}-\d{2}$/", $filmTmdb->release_date))
-            {
-                $dateSortie = $filmTmdb->release_date;
-                dump($dateSortie);
-                $annee = substr($dateSortie, 0, 4) . '-01-01';
-                dump($annee);
-                $film
-                    ->setDateSortie(new \DateTimeImmutable($dateSortie))
-                    ->setAnnee(new \DateTimeImmutable($annee))
-                ;
-
-            } elseif (preg_match("/^\d{4}/", $filmTmdb->release_date)) {
-                $annee = substr($filmTmdb->release_date, 0, 4) . '-01-01';
-                $film                    
-                    ->setAnnee(new \DateTimeImmutable($annee));
-                ;
-            }
+                ->setDateSortie(new \DateTimeImmutable($dateSortie))
+                ->setAnnee(new \DateTimeImmutable($annee))
+            ;
 
+        } elseif (preg_match("/^\d{4}/", $filmTmdb->release_date)) {
+            $annee = substr($filmTmdb->release_date, 0, 4) . '-01-01';
+            $film                    
+                ->setAnnee(new \DateTimeImmutable($annee));
             ;
-            foreach ($filmTmdb->genres as $genre) {
-                $film->addGenre((new Genre())->setName($genre->name));
-            }
+        }
 
-            foreach ($this->getRealisateurs($filmTmdb) as $realisateur) {
-                $film->addRealisateur($realisateur);
-            }
+        ;
+        foreach ($filmTmdb->genres as $genre) {
+            $film->addGenre((new Genre())->setName($genre->name));
+        }
+
+        foreach ($this->getRealisateurs($filmTmdb) as $realisateur) {
+            $film->addRealisateur($realisateur);
+        }
 
-            $film = $this->uc->assureUniciteCollections($film);
-            dump($film);
-            return $film;
+        $film = $this->uc->assureUniciteCollections($film);
+        dump($film);
+        return $film;
     }
 
     public function getRealisateurs($detailMovie): array

+ 7 - 2
templates/videotheque/add_tmdb.html.twig

@@ -14,15 +14,20 @@
     <table class="table table-bordered table-hover table-striped table-sm align-middle">
         <thead>
             <tr>
-                <th></th>
+                <th>&nbsp;</th>
                 <th>Titre</th>
                 <th>Date de sortie</th>
                 <th>Résumé</th>
-                <th>Action</th>
+                <th>Genre</th>
                 <th>Realisateur</th>
             </tr>
         </thead>
         <tbody>
+            {% if films | length == 0 %}
+                <tr>
+                    <td colspan="6" class="text-center">Pas de résultat</td>
+                <tr>
+            {% endif %}
             {% for idtmdb, film in films %}
             <tr>
                 <td><a type="button" class="btn btn-primary" href="{{ path('videotheque_ajouter', {'idtmdb': idtmdb }) }}">Créér</a></td>

+ 4 - 1
translations/messages.fr.yaml

@@ -13,7 +13,10 @@ Information: informations complémentaires
 Email: Email
 Envoyer-mail: Envoyer le mail
 password: Mot de passe
-repeat-password: Répéter le mot de passe 
+repeat-password: Répéter le mot de passe
+Recherche: Recherche
+Rechercher: Rechercher
+search_in_tmdb: Rechercher un titre de film sur TheMovieDB.org
 
 Username: Nom d'utilisateur
 Prenom: Prénom