Explorar o código

Ajout de bientôt en salle

François Drouhard hai 1 ano
pai
achega
d6e9e633aa

+ 13 - 1
src/Service/EnSalle.php

@@ -14,8 +14,20 @@ class EnSalle implements RuntimeExtensionInterface
             return false;
         }
         $interval = new \DateInterval('P20D');
-        $dateLimite= $dateSortie->add($interval);
+        $dateLimite = $dateSortie->add($interval);
         $date = new \DateTime('now');
         return ( $date <= $dateLimite && $date >= $dateSortie);
     }
+
+    public function bientotEnSalle(?\DateTimeImmutable $dateSortie): bool
+    {
+        if (!$dateSortie) {
+            return false;
+        }
+        $interval = new \DateInterval('P15D');
+        $interval->invert = 1;
+        $dateLimite = $dateSortie->add($interval);
+        $date = new \DateTime('now');
+        return ( $date >= $dateLimite && $date < $dateSortie );
+    }
 }

+ 3 - 2
src/Twig/TwigEnSalle.php

@@ -12,12 +12,13 @@ class TwigEnSalle extends AbstractExtension
     {
         return array(
             new TwigFunction('estEnSalle', array(EnSalle::class, 'enSalle')),
+            new TwigFunction('bientotEnSalle', array(EnSalle::class, 'bientotEnSalle'))
         );
     }
 
-    public function getName() : string
+    /*public function getName() : string
     {
         return 'estEnSalle';
-    }
+    }*/
 
 }

+ 2 - 1
templates/videotheque/liste_tableaux.html.twig

@@ -82,7 +82,8 @@
 					<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-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 %}
+					{% if bientotEnSalle(film.dateSortie) %}<span class="badge text-bg-info">Bientot</span>{% endif %}
+					{% if film.nbComs %}<span class="badge text-bg-warning rounded-pill" data-bs-toggle="tooltip" title="{{ film.nbComs }} commentaire(s)">{{ film.nbComs }}</span>{% endif %}
 
 				</td>
 				<td>

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

@@ -125,6 +125,7 @@
 					<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 %}
+						{% if bientotEnSalle(film.dateSortie) %}<span class="badge text-bg-info">Bientot</span>{% endif %}
 					</div>
 				</div>
 				<div class="">

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

@@ -58,6 +58,11 @@
         <i class="fa fa-film"></i> EN SALLE
     </div>
     {% endif %}
+    {% if bientotEnSalle(film.dateSortie) %}
+    <div class="text-center alert alert-info" role="alert">
+        <i class="fa fa-clock-o"></i> BIENTOT EN SALLE
+    </div>
+    {% endif %}
   
     <div class="row">
         <div class="col">