]> git.agnieray.net Git - galette.git/commitdiff
Add event dispatcher for plugins; closes #1400
authorNicolas Béhier-Dévigne <nbehierdevigne@gmail.com>
Sun, 16 Feb 2020 16:49:54 +0000 (17:49 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 8 Mar 2020 10:10:13 +0000 (11:10 +0100)
Emits from models rather than routes
Add, Edit and Remove event for Adherent, Contribution and Transaction.
Tests for PHP 7.1, 7.2 and 7.3.

Add method to get plugins namespace

galette/composer.json
galette/composer.lock
galette/includes/dependencies.php
galette/lib/Galette/Core/Plugins.php
galette/lib/Galette/Entity/Adherent.php
galette/lib/Galette/Entity/Contribution.php
galette/lib/Galette/Entity/Transaction.php
galette/lib/Galette/Repository/Members.php
tests/TestsBootstrap.php

index 9a0b95f4114a086a7e5c07fe8b438bff84673fbb..f345a54b09e0d97c68e1cf13f1374c192c018866 100644 (file)
@@ -43,7 +43,8 @@
         "laminas/laminas-i18n": "^2.9",
         "laminas/laminas-cache": "^2.8",
         "soundasleep/html2text": "^0.5.0",
-        "laminas/laminas-dependency-plugin": "^1.0"
+        "laminas/laminas-dependency-plugin": "^1.0",
+        "aneek/slim-event-dispatcher": "^1.0"
     },
     "require-dev": {
         "atoum/atoum": "dev-master"
index 100132ca3aad79d981d39157a2feab261ffefb07..9cebbadc0bfb0b845eb5386650bce0014d2b2e75 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ddf9ee35678661c537784023d5f97298",
+    "content-hash": "30604f1397d8d5168f320b4052e2918d",
     "packages": [
         {
             "name": "akrabat/rka-slim-session-middleware",
         },
         {
             "name": "analog/analog",
-            "version": "1.0.14-stable",
+            "version": "1.0.13-stable",
             "source": {
                 "type": "git",
                 "url": "https://github.com/jbroadway/analog.git",
-                "reference": "d7ba74333a61970295fbe554177b8cd8000c2934"
+                "reference": "718ac1dad4577a15cadadab01b79d1923f5a9c6d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/jbroadway/analog/zipball/d7ba74333a61970295fbe554177b8cd8000c2934",
-                "reference": "d7ba74333a61970295fbe554177b8cd8000c2934",
+                "url": "https://api.github.com/repos/jbroadway/analog/zipball/718ac1dad4577a15cadadab01b79d1923f5a9c6d",
+                "reference": "718ac1dad4577a15cadadab01b79d1923f5a9c6d",
                 "shasum": ""
             },
             "require": {
                 "logging",
                 "syslog"
             ],
-            "time": "2020-02-07T17:41:54+00:00"
+            "time": "2019-06-27T16:18:03+00:00"
+        },
+        {
+            "name": "aneek/slim-event-dispatcher",
+            "version": "1.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/aneek/slim-event-dispatcher.git",
+                "reference": "9b3eb70b0408cc7131337796752df312c19abb99"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/aneek/slim-event-dispatcher/zipball/9b3eb70b0408cc7131337796752df312c19abb99",
+                "reference": "9b3eb70b0408cc7131337796752df312c19abb99",
+                "shasum": ""
+            },
+            "require": {
+                "league/event": "^2.1",
+                "php": ">= 5.6",
+                "slim/slim": "^3.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "5.7.22",
+                "symfony/var-dumper": "^3.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Slim\\Event\\": "./src/Event"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Aneek Mukhopadhyay",
+                    "email": "dream.aneek@gmail.com"
+                }
+            ],
+            "description": "An event dispatcher bridge between League Event and Slim Framework.",
+            "keywords": [
+                "emitter",
+                "event",
+                "event-dispatcher",
+                "listener",
+                "slim framework"
+            ],
+            "time": "2017-09-27T07:58:29+00:00"
         },
         {
             "name": "container-interop/container-interop",
         },
         {
             "name": "laminas/laminas-i18n",
-            "version": "2.10.1",
+            "version": "2.9.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/laminas/laminas-i18n.git",
-                "reference": "815be447f1c77f70a86bf24d00087fcb975b39ff"
+                "reference": "48883436c6fa1f9ef001af295e3a40003c5cfbf2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/laminas/laminas-i18n/zipball/815be447f1c77f70a86bf24d00087fcb975b39ff",
-                "reference": "815be447f1c77f70a86bf24d00087fcb975b39ff",
+                "url": "https://api.github.com/repos/laminas/laminas-i18n/zipball/48883436c6fa1f9ef001af295e3a40003c5cfbf2",
+                "reference": "48883436c6fa1f9ef001af295e3a40003c5cfbf2",
                 "shasum": ""
             },
             "require": {
-                "ext-intl": "*",
                 "laminas/laminas-stdlib": "^2.7 || ^3.0",
                 "laminas/laminas-zendframework-bridge": "^1.0",
                 "php": "^5.6 || ^7.0"
             },
-            "conflict": {
-                "phpspec/prophecy": "<1.9.0"
-            },
             "replace": {
                 "zendframework/zend-i18n": "self.version"
             },
                 "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.16"
             },
             "suggest": {
+                "ext-intl": "Required for most features of Laminas\\I18n; included in default builds of PHP",
                 "laminas/laminas-cache": "Laminas\\Cache component",
                 "laminas/laminas-config": "Laminas\\Config component",
                 "laminas/laminas-eventmanager": "You should install this package to use the events in the translator",
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "2.10.x-dev",
-                    "dev-develop": "2.11.x-dev"
+                    "dev-master": "2.9.x-dev",
+                    "dev-develop": "2.10.x-dev"
                 },
                 "laminas": {
                     "component": "Laminas\\I18n",
                 "i18n",
                 "laminas"
             ],
-            "time": "2019-12-31T17:07:17+00:00"
+            "time": "2019-12-31T17:09:58+00:00"
         },
         {
             "name": "laminas/laminas-servicemanager",
             ],
             "time": "2020-01-07T22:58:31+00:00"
         },
+        {
+            "name": "league/event",
+            "version": "2.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/event.git",
+                "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/event/zipball/d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
+                "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.4.0"
+            },
+            "require-dev": {
+                "henrikbjorn/phpspec-code-coverage": "~1.0.1",
+                "phpspec/phpspec": "^2.2"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.2-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "League\\Event\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Frank de Jonge",
+                    "email": "info@frenky.net"
+                }
+            ],
+            "description": "Event package",
+            "keywords": [
+                "emitter",
+                "event",
+                "listener"
+            ],
+            "time": "2018-11-26T11:52:41+00:00"
+        },
         {
             "name": "mathmarques/smarty-view",
             "version": "1.1.2",
         },
         {
             "name": "monolog/monolog",
-            "version": "1.25.3",
+            "version": "1.25.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Seldaek/monolog.git",
-                "reference": "fa82921994db851a8becaf3787a9e73c5976b6f1"
+                "reference": "70e65a5470a42cfec1a7da00d30edb6e617e8dcf"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fa82921994db851a8becaf3787a9e73c5976b6f1",
-                "reference": "fa82921994db851a8becaf3787a9e73c5976b6f1",
+                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/70e65a5470a42cfec1a7da00d30edb6e617e8dcf",
+                "reference": "70e65a5470a42cfec1a7da00d30edb6e617e8dcf",
                 "shasum": ""
             },
             "require": {
                 "logging",
                 "psr-3"
             ],
-            "time": "2019-12-20T14:15:16+00:00"
+            "time": "2019-09-06T13:49:17+00:00"
         },
         {
             "name": "nikic/fast-route",
         },
         {
             "name": "phpmailer/phpmailer",
-            "version": "v6.1.4",
+            "version": "v6.1.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/PHPMailer/PHPMailer.git",
-                "reference": "c5e61d0729507049cec9673aa1a679f9adefd683"
+                "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/c5e61d0729507049cec9673aa1a679f9adefd683",
-                "reference": "c5e61d0729507049cec9673aa1a679f9adefd683",
+                "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8",
+                "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8",
                 "shasum": ""
             },
             "require": {
                 "php": ">=5.5.0"
             },
             "require-dev": {
-                "doctrine/annotations": "^1.2",
+                "doctrine/annotations": "1.2.*",
                 "friendsofphp/php-cs-fixer": "^2.2",
-                "phpunit/phpunit": "^4.8 || ^5.7"
+                "phpdocumentor/phpdocumentor": "2.*",
+                "phpunit/phpunit": "^4.8 || ^5.7",
+                "zendframework/zend-eventmanager": "3.0.*",
+                "zendframework/zend-i18n": "2.7.3",
+                "zendframework/zend-serializer": "2.7.*"
             },
             "suggest": {
                 "ext-mbstring": "Needed to send email in multibyte encoding charset",
                 }
             ],
             "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
-            "time": "2019-12-10T11:17:38+00:00"
+            "time": "2019-09-27T21:33:43+00:00"
         },
         {
             "name": "pimple/pimple",
-            "version": "v3.3.0",
+            "version": "v3.2.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/silexphp/Pimple.git",
-                "reference": "e55d12f9d6a0e7f9c85992b73df1267f46279930"
+                "reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/silexphp/Pimple/zipball/e55d12f9d6a0e7f9c85992b73df1267f46279930",
-                "reference": "e55d12f9d6a0e7f9c85992b73df1267f46279930",
+                "url": "https://api.github.com/repos/silexphp/Pimple/zipball/9e403941ef9d65d20cba7d54e29fe906db42cf32",
+                "reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32",
                 "shasum": ""
             },
             "require": {
-                "php": "^7.2.5",
+                "php": ">=5.3.0",
                 "psr/container": "^1.0"
             },
             "require-dev": {
-                "symfony/phpunit-bridge": "^3.4|^4.4|^5.0"
+                "symfony/phpunit-bridge": "^3.2"
             },
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "3.3.x-dev"
+                    "dev-master": "3.2.x-dev"
                 }
             },
             "autoload": {
                 }
             ],
             "description": "Pimple, a simple Dependency Injection Container",
-            "homepage": "https://pimple.symfony.com",
+            "homepage": "http://pimple.sensiolabs.org",
             "keywords": [
                 "container",
                 "dependency injection"
             ],
-            "time": "2020-03-03T09:12:48+00:00"
+            "time": "2018-01-21T07:42:36+00:00"
         },
         {
             "name": "psr/cache",
         },
         {
             "name": "psr/log",
-            "version": "1.1.2",
+            "version": "1.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/php-fig/log.git",
-                "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801"
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801",
-                "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801",
+                "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
                 "shasum": ""
             },
             "require": {
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.1.x-dev"
+                    "dev-master": "1.0.x-dev"
                 }
             },
             "autoload": {
                 "psr",
                 "psr-3"
             ],
-            "time": "2019-11-01T11:05:21+00:00"
+            "time": "2018-11-20T15:27:04+00:00"
         },
         {
             "name": "psr/simple-cache",
         },
         {
             "name": "slim/slim",
-            "version": "3.12.3",
+            "version": "3.12.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/slimphp/Slim.git",
-                "reference": "1c9318a84ffb890900901136d620b4f03a59da38"
+                "reference": "200c6143f15baa477601879b64ab2326847aac0b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/slimphp/Slim/zipball/1c9318a84ffb890900901136d620b4f03a59da38",
-                "reference": "1c9318a84ffb890900901136d620b4f03a59da38",
+                "url": "https://api.github.com/repos/slimphp/Slim/zipball/200c6143f15baa477601879b64ab2326847aac0b",
+                "reference": "200c6143f15baa477601879b64ab2326847aac0b",
                 "shasum": ""
             },
             "require": {
+                "container-interop/container-interop": "^1.2",
                 "ext-json": "*",
                 "ext-libxml": "*",
                 "ext-simplexml": "*",
                 "micro",
                 "router"
             ],
-            "time": "2019-11-28T17:40:33+00:00"
+            "time": "2019-08-20T18:46:05+00:00"
         },
         {
             "name": "smarty/smarty",
-            "version": "v3.1.34",
+            "version": "v3.1.33",
             "source": {
                 "type": "git",
                 "url": "https://github.com/smarty-php/smarty.git",
-                "reference": "c9f0de05f41b9e52798b268ab1e625fac3b8578c"
+                "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/c9f0de05f41b9e52798b268ab1e625fac3b8578c",
-                "reference": "c9f0de05f41b9e52798b268ab1e625fac3b8578c",
+                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/dd55b23121e55a3b4f1af90a707a6c4e5969530f",
+                "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f",
                 "shasum": ""
             },
             "require": {
                 "php": ">=5.2"
             },
-            "require-dev": {
-                "phpunit/phpunit": "6.4.1"
-            },
             "type": "library",
             "extra": {
                 "branch-alias": {
                 }
             },
             "autoload": {
-                "classmap": [
-                    "libs/"
+                "files": [
+                    "libs/bootstrap.php"
                 ]
             },
             "notification-url": "https://packagist.org/downloads/",
             "keywords": [
                 "templating"
             ],
-            "time": "2019-02-28T06:42:20+00:00"
+            "time": "2018-09-12T20:54:16+00:00"
         },
         {
             "name": "soundasleep/html2text",
         },
         {
             "name": "tecnickcom/tcpdf",
-            "version": "6.3.5",
+            "version": "6.3.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/tecnickcom/TCPDF.git",
-                "reference": "19a535eaa7fb1c1cac499109deeb1a7a201b4549"
+                "reference": "9fde7bb9b404b945e7ea88fb7eccd23d9a4e324b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/19a535eaa7fb1c1cac499109deeb1a7a201b4549",
-                "reference": "19a535eaa7fb1c1cac499109deeb1a7a201b4549",
+                "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/9fde7bb9b404b945e7ea88fb7eccd23d9a4e324b",
+                "reference": "9fde7bb9b404b945e7ea88fb7eccd23d9a4e324b",
                 "shasum": ""
             },
             "require": {
             },
             "notification-url": "https://packagist.org/downloads/",
             "license": [
-                "LGPL-3.0-only"
+                "LGPL-3.0"
             ],
             "authors": [
                 {
                 "pdf417",
                 "qrcode"
             ],
-            "time": "2020-02-14T14:20:12+00:00"
+            "time": "2019-09-20T09:35:01+00:00"
         }
     ],
     "packages-dev": [
             "source": {
                 "type": "git",
                 "url": "https://github.com/atoum/atoum.git",
-                "reference": "53ddbdfd5b7fa0a624f68b9efe2276736c38c7fa"
+                "reference": "b6c93433a7b0b92b54c2bb9b0731d71ddc03b365"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/atoum/atoum/zipball/53ddbdfd5b7fa0a624f68b9efe2276736c38c7fa",
-                "reference": "53ddbdfd5b7fa0a624f68b9efe2276736c38c7fa",
+                "url": "https://api.github.com/repos/atoum/atoum/zipball/b6c93433a7b0b92b54c2bb9b0731d71ddc03b365",
+                "reference": "b6c93433a7b0b92b54c2bb9b0731d71ddc03b365",
                 "shasum": ""
             },
             "require": {
                 "test",
                 "unit testing"
             ],
-            "time": "2020-03-04T10:30:56+00:00"
+            "time": "2019-10-04T19:45:12+00:00"
         }
     ],
     "aliases": [],
index f9acaf2318774dacf3252d5053792a225c9a2d48..77b62848d933182a32963cc5c76f99aa2591b2eb 100644 (file)
@@ -33,6 +33,7 @@
  */
 
 use Galette\Entity\PdfModel;
+use Slim\Event\SlimEventManager;
 
 $container = $app->getContainer();
 
@@ -725,6 +726,12 @@ $container['translator'] = function ($c) {
     return $translator;
 };
 
+// Add Event manager to dependency.
+$container['event_manager'] = function ($c) {
+    $emitter = new SlimEventManager();
+    return $emitter;
+};
+
 //For bad existing globals can be used...
 if (!isset($container['mode']) || $container['mode'] !== 'INSTALL' && $container['mode'] !== 'NEED_UPDATE') {
     $zdb = $container['zdb'];
@@ -734,5 +741,6 @@ if (!isset($container['mode']) || $container['mode'] !== 'INSTALL' && $container
 }
 $i18n = $container['i18n'];
 $translator = $container['translator'];
+$emitter = $container['event_manager'];
 
 require_once GALETTE_ROOT . 'includes/i18n.inc.php';
index 159cd559682e26a931be4310c4a4aa33d19332c1..ddf35a76e184958d802faec79b26305a347274b8 100644 (file)
@@ -129,7 +129,7 @@ class Plugins
                             if (file_exists($full_entry . '/lib') && isset($this->modules[$entry])) {
                                 $varname = $entry . 'Loader';
                                 $$varname = new ClassLoader(
-                                    str_replace(' ', '', $this->modules[$entry]['name']),
+                                    $this->getNamespace($entry),
                                     $full_entry . '/lib'
                                 );
                                 $$varname->register();
@@ -174,6 +174,7 @@ class Plugins
         foreach ($this->modules as $id => $m) {
             $this->loadModuleL10N($id, $lang);
             $this->loadSmarties($id);
+            $this->loadEventProviders($id);
             $this->overridePrefs($id);
         }
     }
@@ -375,6 +376,25 @@ class Plugins
         }
     }
 
+    /**
+     * Loads event provider
+     *
+     * @param string $id Module ID
+     *
+     * @return void
+     */
+    public function loadEventProviders($id)
+    {
+        global $emitter;
+
+        $providerClassName = '\\' . $this->getNamespace($id) . '\\' . 'PluginEventProvider';
+        if (class_exists($providerClassName)
+            && method_exists($providerClassName, 'provideListeners')
+        ) {
+            $emitter->useListenerProvider(new $providerClassName());
+        }
+    }
+
     /**
      * Returns all modules associative array or only one module if <var>$id</var>
      * is present.
@@ -794,4 +814,16 @@ class Plugins
         $this->id = null;
         $this->mroot = null;
     }
+
+    /**
+     * Get module namespace
+     *
+     * @param integer $id Module ID
+     *
+     * @return string
+     */
+    public function getNamespace($id)
+    {
+        return str_replace(' ', '', $this->modules[$id]['name']);
+    }
 }
index f8d4e9510bdb54f2781e2e6cddec01fef14c4e34..ba9d213a7f30498625c55f8e80a0a705f6ab125f 100644 (file)
@@ -1321,7 +1321,7 @@ class Adherent
      */
     public function store()
     {
-        global $hist;
+        global $hist, $emitter;
 
         try {
             $values = array();
@@ -1422,6 +1422,8 @@ class Adherent
                         );
                     }
                     $success = true;
+
+                    $emitter->emit('member.add', $this);
                 } else {
                     $hist->add(_T("Fail to add new member."));
                     throw new \Exception(
@@ -1460,6 +1462,8 @@ class Adherent
                     );
                 }
                 $success = true;
+
+                $emitter->emit('member.edit', $this);
             }
 
             //dynamic fields
index 17e84b679b42b1e2b06e9431b0b9903c75fb3c7b..153303fd74d840bb61b23c8cb0215d8ef849160b 100644 (file)
@@ -540,7 +540,7 @@ class Contribution
      */
     public function store()
     {
-        global $hist;
+        global $hist, $emitter;
 
         if (count($this->errors) > 0) {
             throw new \RuntimeException(
@@ -598,6 +598,8 @@ class Contribution
                         Adherent::getSName($this->zdb, $this->_member)
                     );
                     $success = true;
+
+                    $emitter->emit('contribution.add', $this);
                 } else {
                     $hist->add(_T("Fail to add new contribution."));
                     throw new \Exception(
@@ -627,6 +629,8 @@ class Contribution
                     );
                 }
                 $success = true;
+
+                $emitter->emit('contribution.edit', $this);
             }
             //update deadline
             if ($this->isCotis()) {
@@ -700,6 +704,8 @@ class Contribution
      */
     public function remove($transaction = true)
     {
+        global $emitter;
+
         try {
             if ($transaction) {
                 $this->zdb->connection->beginTransaction();
@@ -719,6 +725,7 @@ class Contribution
             if ($transaction) {
                 $this->zdb->connection->commit();
             }
+            $emitter->emit('contribution.remove', $this);
             return true;
         } catch (\Exception $e) {
             if ($transaction) {
index 58304065bc7ba6421bc3397e54444719b762b538..4c85f5d528eaef124d5074ee4ab8de26e7c42548 100644 (file)
@@ -177,6 +177,8 @@ class Transaction
      */
     public function remove(History $hist, $transaction = true)
     {
+        global $emitter;
+
         try {
             if ($transaction) {
                 $this->zdb->connection->beginTransaction();
@@ -205,6 +207,7 @@ class Transaction
             if ($transaction) {
                 $this->zdb->connection->commit();
             }
+            $emitter->emit('transaction.remove', $this);
             return true;
         } catch (\Exception $e) {
             if ($transaction) {
@@ -370,6 +373,8 @@ class Transaction
      */
     public function store(History $hist)
     {
+        global $emitter;
+
         try {
             $this->zdb->connection->beginTransaction();
             $values = array();
@@ -402,6 +407,8 @@ class Transaction
                         Adherent::getSName($this->zdb, $this->_member)
                     );
                     $success = true;
+
+                    $emitter->emit('transaction.add', $this);
                 } else {
                     $hist->add(_T("Fail to add new transaction."));
                     throw new \Exception(
@@ -424,6 +431,8 @@ class Transaction
                     );
                 }
                 $success = true;
+
+                $emitter->emit('transaction.edit', $this);
             }
 
             //dynamic fields
index 1f359d1d8f37fa7a216639d1d4293dfb078d55d5..034b4042b2ec87028bad0a61d48c8c49994747eb 100644 (file)
@@ -281,7 +281,7 @@ class Members
      */
     public function removeMembers($ids)
     {
-        global $zdb, $hist;
+        global $zdb, $hist, $emitter;
 
         $list = array();
         if (is_numeric($ids)) {
@@ -298,7 +298,7 @@ class Members
                 //Retrieve some informations
                 $select = $zdb->select(self::TABLE);
                 $select->columns(
-                    array(self::PK, 'nom_adh', 'prenom_adh')
+                    array(self::PK, 'nom_adh', 'prenom_adh', 'email_adh')
                 )->where->in(self::PK, $list);
 
                 $results = $zdb->execute($select);
@@ -327,6 +327,13 @@ class Members
                             );
                         }
                     }
+
+                    $emitter->emit('member.remove', [
+                        'id_adh' => $member->id_adh,
+                        'nom_adh' => $member->nom_adh,
+                        'prenom_adh' => $member->prenom_adh,
+                        'email_adh' => $member->email_adh
+                    ]);
                 }
 
                 //delete contributions
index cfab94d7b3d69b07062d4090df5e6a22224d262d..b7f9541c47bc3aed1ca86a8af86dabe843df57ca 100755 (executable)
@@ -75,9 +75,10 @@ require_once GALETTE_BASE_PATH . 'includes/galette.inc.php';
 //require_once GALETTE_BASE_PATH . 'includes/i18n.inc.php';
 
 //Globals... :(
-global $preferences;
+global $preferences, $emitter;
 $zdb = new \Galette\Core\Db();
 $preferences = new \Galette\Core\Preferences($zdb);
+$emitter = new \Slim\Event\SlimEventManager();
 
 /**
  * Maps _T Galette's function