Browse Source

Ajout de actuellement au ciné

François Drouhard 1 year ago
parent
commit
e9454128f8

+ 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');
+    }
+}

+ 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

+ 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';
+    }
+
+}

+ 6 - 3
templates/videotheque/liste_tableaux.html.twig

@@ -13,7 +13,7 @@
 	{{ include ('videotheque/_liste_header.html.twig') }}
 
 	<table
-		class="table table-bordered table-hover table-striped table-sm align-middle">
+		class="table table-bordered table-hover table-sm align-middle">
 		<thead class="">
 			<tr>
 				{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
@@ -80,7 +80,8 @@
 				{% 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.new %}<span class="badge bg-secondary">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>
@@ -114,7 +115,9 @@
 					{% endif %}
 				</td>
 				<td>{{ film.annee | date('Y') }}</td>
-				<td>{% if film.dateSortie %}{{ film.dateSortie | date('d/m/y')}}{% endif %}</td>
+				<td>
+					{% if film.dateSortie %}{{ film.dateSortie | date('d/m/y')}}{% endif %}
+				</td>
 			</tr>
 			{% endfor %}
 		</tbody>

+ 7 - 3
templates/videotheque/liste_vignettes.html.twig

@@ -18,7 +18,7 @@
 		<article class="card border-primary mb-4" data-controller="collapser" data-auteur="{{ film.authered.nomComplet }}">
 			<div class="card-header d-flex justify-content-between">
 				<h3 class="card-title"><a class="" 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 %}
+					
 				</h3>
 				<div class="d-flex">
 					{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
@@ -117,11 +117,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>
+							<a href="{{ path('videotheque_voirfilm', {'id': film.id}) }}#coms"><span class="badge text-bg-warning">{{ 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

@@ -53,6 +53,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">