]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/Entity/Contribution.php
Merge branch 'hotfix/1.0.3'
[galette.git] / galette / lib / Galette / Entity / Contribution.php
index f8cc8bd0db1e93ca8cf37ee7a0a2e1a896b65759..3457da44e01dc8437c3eeeb0d82943f3376dc18a 100644 (file)
@@ -40,6 +40,7 @@ namespace Galette\Entity;
 use ArrayObject;
 use DateTime;
 use Galette\Events\GaletteEvent;
+use Galette\Features\HasEvent;
 use Throwable;
 use Analog\Analog;
 use Laminas\Db\Sql\Expression;
@@ -85,6 +86,7 @@ use Galette\Features\Dynamics;
 class Contribution
 {
     use Dynamics;
+    use HasEvent;
 
     public const TABLE = 'cotisations';
     public const PK = 'id_cotis';
@@ -135,6 +137,12 @@ class Contribution
         global $preferences;
         $this->_payment_type = (int)$preferences->pref_default_paymenttype;
 
+        $this
+            ->withAddEvent()
+            ->withEditEvent()
+            ->withoutDeleteEvent()
+            ->activateEvents();
+
         /*
          * Fields configuration. Each field is an array and must reflect:
          * array(
@@ -683,7 +691,7 @@ class Contribution
                         _T("Contribution added"),
                         Adherent::getSName($this->zdb, $this->_member)
                     );
-                    $event = 'contribution.add';
+                    $event = $this->getAddEventName();
                 } else {
                     $hist->add(_T("Fail to add new contribution."));
                     throw new \Exception(
@@ -705,7 +713,7 @@ class Contribution
                     );
                 }
 
-                $event = 'contribution.edit';
+                $event = $this->getEditEventName();
             }
             //update deadline
             if ($this->isFee()) {
@@ -719,7 +727,7 @@ class Contribution
             $this->_orig_amount = $this->_amount;
 
             //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));
             }
 
@@ -1505,4 +1513,14 @@ class Contribution
 
         return false;
     }
+
+    /**
+     * Get prefix for events
+     *
+     * @return string
+     */
+    protected function getEventsPrefix(): string
+    {
+        return 'contribution';
+    }
 }