$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);
+ }
}
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
*
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);
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") {