From 49f68a2237cb60edd6af30d8c6874cd7a385a387 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Tue, 5 Mar 2013 14:57:30 -0800 Subject: [PATCH] fix CRM-11435 --- CRM/Event/BAO/Event.php | 21 +++++++++++++++++++++ CRM/Event/Form/ManageEvent.php | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 2da65110de..d265d82413 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -2006,5 +2006,26 @@ LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field $defaults = array(); return CRM_Event_BAO_Event::retrieve($params, $defaults); } + + /* + * Update the Campaign Id of all the participants of the given event + * + * @params int $eventID event id. + * @params int $eventCampaignID campaign id of that event + * + */ + static function updateParticipantCampaignID($eventID, $eventCampaignID) { + $params = array(); + $params[1] = array($eventID, 'Integer'); + + if(empty($eventCampaignID)) { + $query = "UPDATE civicrm_participant SET campaign_id = NULL WHERE event_id = %1"; + } + else { + $query = "UPDATE civicrm_participant SET campaign_id = %2 WHERE event_id = %1"; + $params[2] = array($eventCampaignID, 'Integer'); + } + CRM_Core_DAO::executeQuery($query, $params); + } } diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 2c52ba6bc1..bf04dbb559 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -79,6 +79,12 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { protected $_cancelURL = NULL; + /** + * The campaign id of the existing event, we use this to know if we need to update + * the participant records + */ + protected $_campaignID = NULL; + /** * Function to set variables up before form is built * @@ -214,6 +220,8 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Event_BAO_Event::retrieve($params, $defaults); + + $this->_campaignID = CRM_Utils_Array::value('campaign_id', $defaults); } elseif ($this->_templateId) { $params = array('id' => $this->_templateId); @@ -333,6 +341,16 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { array(1 => ($subPage == 'friend') ? 'Friend' : $className) ), ts('Saved'), 'success'); + $config = CRM_Core_Config::singleton(); + if (in_array('CiviCampaign', $config->enableComponents)) { + $values = $this->controller->exportValues($this->_name); + $newCampaignID = CRM_Utils_Array::value('campaign_id', $values); + $eventID = CRM_Utils_Array::value('id', $values); + if ($eventID && $this->_campaignID != $newCampaignID) { + CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID); + } + } + $this->postProcessHook(); if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { -- 2.25.1