Răsfoiți Sursa

Ajout d'un mattermost quand commentaire ou note

François 5 ani în urmă
părinte
comite
1fb1f470ef

+ 6 - 2
src/AppBundle/Service/FilmCreationListener.php

@@ -2,6 +2,7 @@
 
 namespace AppBundle\Service;
 
+use AppBundle\Entity\Commentaire;
 use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
 use AppBundle\Entity\Film;
 use Symfony\Component\Config\Definition\Exception\Exception;
@@ -21,13 +22,16 @@ class FilmCreationListener
     public function postPersist(LifecycleEventArgs $args)
     {
         $entity = $args->getObject();
-        if (!$entity instanceof Film)
+        if (!$entity instanceof Film and !$entity instanceof Commentaire)
         {
             return;
         }
 
         try {
-            $this->mattermostSender->sendNouveauFilm($entity);
+            if ($entity instanceof Film)
+                $this->mattermostSender->sendNouveauFilm($entity);
+            else
+                $this->mattermostSender->sendNouveauCommentaire($entity->getFilm());
         } catch (Exception $exception) {
 
         }

+ 12 - 0
src/AppBundle/Service/Mattermost.php

@@ -52,5 +52,17 @@ class Mattermost
         $this->SendNotif($message);
     }
 
+    public function sendNouveauCommentaire(Film $film)
+    {
+        $message =
+            ":new: **"
+            .$film->getAuthered()->getUsername()
+            ."** vient d'ajouter un commentaire sur le film **"
+            .$film->getTitre()
+            ."** dans la [vidéothèque](https://videotheque.fdlibre.eu) ! Wooooo";
+
+        $this->SendNotif($message);
+    }
+
 
 }