Add hook_civicrm_pre / hook_civicrm_post for Campaign
authorsamuelsov <samuel@koumbit.org>
Thu, 26 Feb 2015 14:11:03 +0000 (09:11 -0500)
committersamuelsov <samuel@koumbit.org>
Thu, 26 Feb 2015 14:11:03 +0000 (09:11 -0500)
CRM/Campaign/BAO/Campaign.php

index 2261f3a15b1f1e00238e754a95b65e1dd140d241..876d92683e5db701d06f1a936059cff0387950ec 100644 (file)
@@ -65,12 +65,23 @@ class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
       if (!(CRM_Utils_Array::value('name', $params))) {
         $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64);
       }
+
+      CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params);
+    } else {
+      CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params);
     }
 
     $campaign = new CRM_Campaign_DAO_Campaign();
     $campaign->copyValues($params);
     $campaign->save();
 
+    if (!empty($params['id'])) {
+      CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign);
+    }
+    else {
+      CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign);
+    }
+
     /* Create the campaign group record */
 
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
@@ -109,9 +120,16 @@ class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
     if (!$id) {
       return FALSE;
     }
+
+    CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray);
+
     $dao = new CRM_Campaign_DAO_Campaign();
     $dao->id = $id;
-    return $dao->delete();
+    $result = $dao->delete();
+
+    CRM_Utils_Hook::post('delete', 'Campaign', $id, $dao);
+
+    return $result;
   }
 
   /**