Sfoglia il codice sorgente

On passe le film en vu et on enlève le bookmark quand commenté

Sangfroid 5 mesi fa
parent
commit
0b8e5edffc
1 ha cambiato i file con 15 aggiunte e 1 eliminazioni
  1. 15 1
      src/Service/FilmCreationListener.php

+ 15 - 1
src/Service/FilmCreationListener.php

@@ -6,6 +6,7 @@ use App\Entity\Commentaire;
 use App\Entity\Film;
 use App\Entity\MediaVideo;
 use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
+use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\ORM\Event\PostPersistEventArgs;
 use Doctrine\ORM\Events;
 use Symfony\Component\Config\Definition\Exception\Exception;
@@ -13,7 +14,10 @@ use Symfony\Component\Config\Definition\Exception\Exception;
 #[AsDoctrineListener(event: Events::postPersist)]
 class FilmCreationListener
 {
-    public function __construct(protected Mattermost $mattermostSender)
+    public function __construct(
+        protected Mattermost $mattermostSender,
+        protected EntityManagerInterface $em
+    )
     {
     }
 
@@ -36,6 +40,16 @@ class FilmCreationListener
                 $this->mattermostSender->sendNewMediaVideo($entity->getFilm());
             } else {
                 $this->mattermostSender->sendNouveauCommentaire($entity->getUser(), $entity->getFilm());
+                
+                if ($entity->getFilm()->getUsersWantToView()->contains($entity->getUser())) {
+                    $entity->getFilm()->removeUserWantToView($entity->getUser());
+                }
+                if (!$entity->getFilm()->getUsersWhoSeen()->contains($entity->getUser())) {
+                    $entity->getFilm()->addUserWhoSeen($entity->getUser());
+                }
+
+
+                $this->em->flush();
             }
         } catch (Exception $exception) {