Kaynağa Gözat

Ajout des notifs par mattermost !

François 6 yıl önce
ebeveyn
işleme
6db8c49425

+ 1 - 0
app/config/parameters.yml.dist

@@ -19,6 +19,7 @@ parameters:
     mail_from: ~
     mail_reply: ~
     mail_name: ~
+    mattermost_url: ~
 
 
     # A secret key that's used to generate certain security-related tokens

+ 7 - 1
app/config/services.yml

@@ -58,4 +58,10 @@ services:
         - "@twig"
         - '%mail_from%'
         - '%mail_reply%'
-        - '%mail_name%'
+        - '%mail_name%'
+
+    film.mattermost:
+        class: AppBundle\Service\Mattermost
+        public: true
+        arguments:
+        - '%mattermost_url%'

+ 1 - 0
composer.json

@@ -21,6 +21,7 @@
     },
     "require": {
         "php": ">=5.5.9",
+        "ext-curl": "^7.0",
         "doctrine/doctrine-bundle": "^1.6",
         "doctrine/orm": "^2.5",
         "incenteev/composer-parameter-handler": "^2.0",

+ 4 - 3
composer.lock

@@ -4,8 +4,8 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "3308374bdf1452bd309c42e8700fb392",
-    "content-hash": "b031c059e75bab5ae35c69dfc8616c70",
+    "hash": "ef74d03784a1a538bfd2fc570071e59f",
+    "content-hash": "458438b30a95d02c70df3ecbec1075eb",
     "packages": [
         {
             "name": "composer/ca-bundle",
@@ -2498,7 +2498,8 @@
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
-        "php": ">=5.5.9"
+        "php": ">=5.5.9",
+        "ext-curl": "^7.0"
     },
     "platform-dev": []
 }

+ 2 - 0
src/AppBundle/Controller/VideothequeController.php

@@ -83,6 +83,8 @@ class VideothequeController extends Controller
 			$em->persist($film);
 			$em->flush();
 			$this->addFlash('success', 'Le film a été ajouté');
+			$notifMattermost = $this->get('film.mattermost');
+			$notifMattermost->sendNouveauFilm($film);
 			return $this->redirectToRoute('videotheque_voirfilm', array('id'=>$film->getId()));
 		}
 

+ 0 - 1
src/AppBundle/Service/Mail.php

@@ -2,7 +2,6 @@
 
 namespace AppBundle\Service;
 
-use Symfony\Component\Templating\EngineInterface;
 use Twig\Environment;
 
 /**

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

@@ -0,0 +1,56 @@
+<?php
+
+namespace AppBundle\Service;
+
+
+use AppBundle\Entity\Film;
+
+/**
+ * Envoi notifs mattermost
+ */
+class Mattermost
+{
+    protected $url;
+    /**
+     * Mail Manager
+     */
+    public function __construct($url)
+    {
+        $this->url = $url;
+    }
+
+    protected function SendNotif($message)
+    {
+        // crée une nouvelle ressource cURL
+        $ch = curl_init();
+
+        // fixe l'URL et les autres options appropriées
+        $options = array(
+            CURLOPT_URL => $this->url,
+            CURLOPT_HTTPHEADER => array('Content-Type:', 'application/json'),
+            CURLOPT_POSTFIELDS  =>  '{"text": "' . $message . '"}'
+        );
+
+        curl_setopt_array($ch, $options);
+
+        // attrape l'URL et la passe au navigateur
+        curl_exec($ch);
+
+        // ferme la ressource cURL et libère les ressources systèmes
+        curl_close($ch);
+    }
+
+    public function sendNouveauFilm(Film $film)
+    {
+        $message =
+            ":new: **"
+            .$film->getAuthered()->getUsername()
+            ."** vient d'ajouter **"
+            .$film->getTitre()
+            ."** dans la [vidéothèque](https://videotheque.fdlibre.eu) ! C'est beau !";
+
+        $this->SendNotif($message);
+    }
+
+
+}