Browse Source

Merge branch 'develop' into vuejs

François Drouhard 2 years ago
parent
commit
76fd709000

+ 31 - 0
migrations/Version20230410110851.php

@@ -0,0 +1,31 @@
+<?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 Version20230410110851 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 CHANGE date_sortie date_sortie DATE DEFAULT NULL COMMENT \'(DC2Type:date_immutable)\'');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE film CHANGE date_sortie date_sortie DATE DEFAULT NULL');
+    }
+}

+ 1 - 1
src/Controller/VideothequeController.php

@@ -45,7 +45,7 @@ class VideothequeController extends AbstractController
 
         return $this->render('videotheque/liste_'.$options->vue().'.html.twig', array(
             'listeFilms'	=>	$listeFilms,
-            'titre'         =>  'Prochaines sorties',
+            'titre'         =>  'Prochaines sorties et films en salle',
 		));
     }
 

+ 4 - 3
src/Entity/Film.php

@@ -4,6 +4,8 @@ namespace App\Entity;
 
 use App\Repository\FilmRepository;
 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;
 
@@ -79,9 +81,8 @@ class Film
     
     private ?string $information = null;
 
-    #[ORM\Column(type: "date", nullable: true)]
-    
-    private ?\DateTimeInterface $dateSortie = null;
+    #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
+    private ?\DateTimeImmutable $dateSortie = null;
 
     public function __construct()
     {

+ 1 - 0
src/Form/FilmType.php

@@ -35,6 +35,7 @@ class FilmType extends AbstractType
                 'required'  =>  false,
             ))
             ->add('dateSortie', DateType::class, [
+                'input'     =>  'datetime_immutable',
                 'html5'     =>  true,
                 'widget'    =>  'single_text',
                 'required'  =>  false

+ 1 - 1
src/Repository/FilmRepository.php

@@ -132,7 +132,7 @@ class FilmRepository extends ServiceEntityRepository
     public function findProchaines(): array
     {
         $date = new \DateTime('now');
-        $interval = new \DateInterval("P1D");
+        $interval = new \DateInterval("P20D");
         $interval->invert = 1;
         $date->add($interval);
         $qb = $this->createQueryBuilder('f');

+ 21 - 0
src/Service/EnSalle.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Service;
+
+use Twig\Extension\RuntimeExtensionInterface;
+
+class EnSalle implements RuntimeExtensionInterface
+{
+
+    // Afficher si le film est sorti depuis moins de 20 jours
+    public function enSalle(?\DateTimeImmutable $dateSortie): bool
+    {
+        if (!$dateSortie) {
+            return false;
+        }
+        $interval = new \DateInterval('P20D');
+        $dateLimite= $dateSortie->add($interval);
+        $date = new \DateTime('now');
+        return ( $date <= $dateLimite && $date >= $dateSortie);
+    }
+}

+ 23 - 0
src/Twig/TwigEnSalle.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Twig;
+
+use App\Service\EnSalle;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
+
+class TwigEnSalle extends AbstractExtension
+{
+    public function getFunctions () : array
+    {
+        return array(
+            new TwigFunction('estEnSalle', array(EnSalle::class, 'enSalle')),
+        );
+    }
+
+    public function getName() : string
+    {
+        return 'estEnSalle';
+    }
+
+}

+ 20 - 32
templates/videotheque/liste_tableaux.html.twig

@@ -82,6 +82,7 @@
 					<td>
 						<a href="{{ path('videotheque_voirfilm', {'id': film.id}) }}"><span data-bs-toggle="tooltip" data-placement="right" title="{{ film.information }}">{{ film.titre }}</span></a>
 						{% if film.new %}<span class="badge bg-success">New</span>{% endif %}
+						{% if estEnSalle(film.dateSortie) %}<span class="badge text-bg-success">En salle</span>{% endif %}
 						{% if film.nbComs %}<span class="badge bg-info rounded-pill" data-bs-toggle="tooltip" title="{{ film.nbComs }} commentaire(s)">{{ film.nbComs }}</span>{% endif %}
 
 					</td>
@@ -98,39 +99,26 @@
 							<a href="{{ path('videotheque_listeparreal', {"id": realisateur.id}) }}"><span class="badge bg-info">{{ realisateur.nomComplet }}</span></a>
 						{%  endfor %}
 				{% endif %}
-				<td>
-					<a href="{{ path('videotheque_voirfilm', {'id': film.id}) }}"><span data-bs-toggle="tooltip" data-placement="right" title="{{ film.information }}">{{ film.titre }}</span></a>
-					{% if film.new %}<span class="badge bg-success">New</span>{% endif %}
-					{% if film.nbComs %}<span class="badge bg-info rounded-pill" data-bs-toggle="tooltip" title="{{ film.nbComs }} commentaire(s)">{{ film.nbComs }}</span>{% endif %}
-
 				</td>
 				<td>
-					{% if film.genres is defined %}
-						{% for genre in film.genres %}
-							<a href="{{ path("videotheque_listepargenre", {"id": genre.id}) }}"><span class="badge bg-secondary">{{ genre.name }}</span></a>
-						{% endfor %}
+					{% if film.note > 0 %}
+						<input class="rating"
+							data-disabled="true"
+							data-show-clear="false"
+							data-show-caption="false"
+							data-theme="krajee-fa"
+							style="display:none;"
+							min=0
+							max=5
+							data-step=0.5
+							data-size="xs"
+							value="{{ film.note }}">
 					{% endif %}
-					</td>
-					<td>
-						{% if film.note > 0 %}
-							<input class="rating"
-								data-disabled="true"
-								data-show-clear="false"
-								data-show-caption="false"
-								data-theme="krajee-fa"
-								style="display:none;"
-								min=0
-								max=5
-								data-step=0.5
-								data-size="xs"
-								value="{{ film.note }}">
-						{% endif %}
-					</td>
-					<td>{{ film.annee | date('Y') }}</td>
-					<td>{% if film.dateSortie %}{{ film.dateSortie | date('d/m/y')}}{% endif %}</td>
-				</tr>
-				{% endfor %}
-			</tbody>
-		</table>
-	</div>
+				</td>
+				<td>{{ film.annee | date('Y') }}</td>
+				<td>{% if film.dateSortie %}{{ film.dateSortie | date('d/m/y')}}{% endif %}</td>
+			</tr>
+			{% endfor %}
+		</tbody>
+	</table>
 {% endblock %}

+ 5 - 1
templates/videotheque/liste_vignettes.html.twig

@@ -112,11 +112,15 @@
 								data-size="xs"
 								value="{{ film.note }}">
 						</div>
-						<div class="">
+						<div class="me-3">
 							{% if film.nbComs %}
 								<a href="{{ path('videotheque_voirfilm', {'id': film.id}) }}#coms"><span class="badge bg-warning text-dark">{{ film.nbComs }} commentaire{% if film.nbComs > 1 %}s{% endif %}</span></a>
 							{% endif %}
 						</div>
+						<div class="">
+							{% if film.new %}<span class="badge text-bg-secondary">New</span>{% endif %}
+							{% if estEnSalle(film.dateSortie) %}<span class="badge text-bg-success">En salle</span>{% endif %}
+						</div>
 					</div>
 					<div class="">
 					{%  if film.authered is defined %}

+ 6 - 0
templates/videotheque/voirfilm.html.twig

@@ -60,6 +60,12 @@
 {% endblock %}
 
 {%  block body %}
+    {% if estEnSalle(film.dateSortie) %}
+    <div class="text-center alert alert-success" role="alert">
+        <i class="fa fa-film"></i> EN SALLE
+    </div>
+    {% endif %}
+  
     <div class="row">
         <div class="col">
             <div class="card shadow mb-4">