From 86950de8d3a5cdf22326a19a83c85ddb5e1ec6f2 Mon Sep 17 00:00:00 2001 From: Sean Madsen Date: Wed, 14 Mar 2018 17:31:47 -0400 Subject: [PATCH] Add pre/post hooks to the Survey entity Also improve docblock --- CRM/Campaign/BAO/Survey.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/CRM/Campaign/BAO/Survey.php b/CRM/Campaign/BAO/Survey.php index a652633d72..9ae75ea897 100644 --- a/CRM/Campaign/BAO/Survey.php +++ b/CRM/Campaign/BAO/Survey.php @@ -61,15 +61,12 @@ class CRM_Campaign_BAO_Survey extends CRM_Campaign_DAO_Survey { } /** - * Takes an associative array and creates a Survey object. - * - * the function extract all the params it needs to initialize the create a - * survey object. - * + * Takes an associative array and creates a Survey object based on the + * supplied values. * * @param array $params * - * @return CRM_Survey_DAO_Survey + * @return bool|CRM_Campaign_DAO_Survey */ public static function create(&$params) { if (empty($params)) { @@ -90,12 +87,24 @@ class CRM_Campaign_BAO_Survey extends CRM_Campaign_DAO_Survey { if (!(CRM_Utils_Array::value('created_date', $params))) { $params['created_date'] = date('YmdHis'); } + + CRM_Utils_Hook::pre('create', 'Survey', NULL, $params); + } + else { + CRM_Utils_Hook::pre('edit', 'Survey', $params['id'], $params); } $dao = new CRM_Campaign_DAO_Survey(); $dao->copyValues($params); $dao->save(); + if (!empty($params['id'])) { + CRM_Utils_Hook::post('edit', 'Survey', $dao->id, $dao); + } + else { + CRM_Utils_Hook::post('create', 'Survey', $dao->id, $dao); + } + if (!empty($params['custom']) && is_array($params['custom']) ) { -- 2.25.1