From d623de42c887b757d42c4a2308444b6199610874 Mon Sep 17 00:00:00 2001 From: Monish Date: Mon, 25 Aug 2014 22:12:47 +0530 Subject: [PATCH] CRM-15139 fix - Batch update does not show values when using custom fields limited by event type https://issues.civicrm.org/jira/browse/CRM-15139 --- CRM/Core/BAO/UFGroup.php | 29 +++++++++++++++++------------ CRM/Event/Form/Task/Batch.php | 11 +++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 478501d452..677cc2f90a 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -3165,7 +3165,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) case 'Event': $componentBAO = 'CRM_Event_BAO_Participant'; $componentBAOName = 'Participant'; - $componentSubType = array('role_id', 'event_id'); + $componentSubType = array('role_id', 'event_id', 'event_type_id'); break; case 'Activity': @@ -3180,6 +3180,9 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) //get the component values. CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values); + if ($componentBAOName == 'Participant') { + $values += array('event_type_id' => CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values['event_id'], 'event_type_id')); + } $formattedGroupTree = array(); $dateTimeFields = array('participant_register_date', 'activity_date_time', 'receive_date', 'receipt_date', 'cancel_date', 'thankyou_date', 'membership_start_date', 'membership_end_date', 'join_date'); @@ -3236,18 +3239,20 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $skipValue = FALSE; foreach ($formattedGroupTree as $tree) { - if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) { - $skipValue = TRUE; - $defaults['field'][$componentId][$name] = $customValue; - break; - } - elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') { - $skipValue = TRUE; + if (!empty($tree['fields'][$customFieldDetails[0]])) { + if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) { + $skipValue = TRUE; + $defaults['field'][$componentId][$name] = $customValue; + break; + } + elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') { + $skipValue = TRUE; - // CRM-6681, $default contains formatted date, time values. - $defaults[$fldName] = $customValue; - if (!empty($defaults[$customKey . '_time'])) { - $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time']; + // CRM-6681, $default contains formatted date, time values. + $defaults[$fldName] = $customValue; + if (!empty($defaults[$customKey . '_time'])) { + $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time']; + } } } } diff --git a/CRM/Event/Form/Task/Batch.php b/CRM/Event/Form/Task/Batch.php index e0078ef21c..5d70d16c20 100644 --- a/CRM/Event/Form/Task/Batch.php +++ b/CRM/Event/Form/Task/Batch.php @@ -163,19 +163,24 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { // get the option value for custom data type $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); + $this->_eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); // build custom data getFields array $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_roleCustomDataTypeID); $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventNameCustomDataTypeID); + $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventTypeCustomDataTypeID); + $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE) ); + $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields); $this->_customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields); foreach ($this->_participantIds as $participantId) { $roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'role_id'); $eventId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'event_id'); + $eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventId, 'event_type_id'); foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { $customValue = CRM_Utils_Array::value($customFieldID, $this->_customFields); @@ -186,6 +191,7 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { ); } $entityColumnValueRole = CRM_Utils_Array::value($roleId, $entityColumnValue); + $entityColumnValueEventType = CRM_Utils_Array::value(array_search($eventTypeId, $entityColumnValue), $entityColumnValue); if (($this->_roleCustomDataTypeID == $customValue['extends_entity_column_id']) && ($entityColumnValueRole) ) { @@ -196,6 +202,11 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { ) { CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); } + elseif ($this->_eventTypeCustomDataTypeID == $customValue['extends_entity_column_id'] && + ($entityColumnValueEventType == $eventTypeId) + ) { + CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); + } elseif (CRM_Utils_System::isNull($entityColumnValueRole)) { CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId); } -- 2.25.1