]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/Entity/Adherent.php
Merge branch 'hotfix/1.0.3'
[galette.git] / galette / lib / Galette / Entity / Adherent.php
index 9b844fc231ac148872596412f6bb271251f5e888..e6d67b4d94282f039c845efa3ac25c9182bf9686 100644 (file)
@@ -38,6 +38,7 @@ namespace Galette\Entity;
 
 use ArrayObject;
 use Galette\Events\GaletteEvent;
+use Galette\Features\HasEvent;
 use Galette\Features\Socials;
 use Throwable;
 use Analog\Analog;
@@ -126,6 +127,7 @@ class Adherent
 {
     use Dynamics;
     use Socials;
+    use HasEvent;
 
     public const TABLE = 'adherents';
     public const PK = 'id_adh';
@@ -237,6 +239,12 @@ class Adherent
             }
         }
 
+        $this
+            ->withAddEvent()
+            ->withEditEvent()
+            ->withoutDeleteEvent()
+            ->activateEvents();
+
         if ($args == null || is_int($args)) {
             if (is_int($args) && $args > 0) {
                 $this->load($args);
@@ -1569,7 +1577,7 @@ class Adherent
                         );
                     }
 
-                    $event = 'member.add';
+                    $event = $this->getAddEventName();
                 } else {
                     $hist->add(_T("Fail to add new member."));
                     throw new \Exception(
@@ -1605,7 +1613,7 @@ class Adherent
                         $this->sname
                     );
                 }
-                $event = 'member.edit';
+                $event = $this->getEditEventName();
             }
 
             //dynamic fields
@@ -1613,7 +1621,7 @@ class Adherent
             $this->storeSocials($this->id);
 
             //send event at the end of process, once all has been stored
-            if ($event !== null) {
+            if ($event !== null && $this->areEventsEnabled()) {
                 $emitter->dispatch(new GaletteEvent($event, $this));
             }
             return true;
@@ -2267,4 +2275,14 @@ class Adherent
         $this->loadParent();
         return $this;
     }
+
+    /**
+     * Get prefix for events
+     *
+     * @return string
+     */
+    protected function getEventsPrefix(): string
+    {
+        return 'member';
+    }
 }