From: monishdeb Date: Wed, 26 Aug 2015 12:36:56 +0000 (+0530) Subject: Participant role fix X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=348b1fda86cdea3e09db8a656862a9f2dd9d1bba;p=civicrm-core.git Participant role fix --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 351b3dc6d2..3e54f48ab8 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -5494,11 +5494,14 @@ AND displayRelType.is_active = 1 } // FIX ME: we should potentially move this to component Query and write a wrapper function that // handles pseudoconstant fixes for all component - elseif (in_array($value['pseudoField'], array('participant_status', 'participant_role'))) { - $pseudoOptions = $viewValues = array(); - $pseudoOptions = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', $value['idCol']); - foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $val) as $k => $v) { - $viewValues[] = $pseudoOptions[$v]; + elseif (in_array($value['pseudoField'], array('participant_role_id', 'participant_role'))) { + $viewValues = explode(CRM_Core_DAO::VALUE_SEPARATOR, $val); + + if ($value['pseudoField'] == 'participant_role') { + $pseudoOptions = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'role_id'); + foreach ($viewValues as $k => $v) { + $viewValues[$k] = $pseudoOptions[$v]; + } } $dao->$key = implode(', ', $viewValues); } diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 2ee35af37c..6f34f0476b 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -151,14 +151,22 @@ class CRM_Event_BAO_Query { $query->_element['participant_role_id'] = 1; $query->_tables['civicrm_participant'] = 1; $query->_whereTables['civicrm_participant'] = 1; + $query->_pseudoConstantsSelect['participant_role_id'] = array( + 'pseudoField' => 'participant_role_id', + 'idCol' => 'participant_role_id', + ); } //add participant_role if (!empty($query->_returnProperties['participant_role'])) { - $query->_select['participant_status'] = "participant_role.label as participant_role"; + $query->_select['participant_status'] = "civicrm_participant.role_id as participant_role"; $query->_element['participant_role'] = 1; $query->_tables['participant_role'] = 1; $query->_whereTables['civicrm_participant'] = 1; + $query->_pseudoConstantsSelect['participant_role'] = array( + 'pseudoField' => 'participant_role', + 'idCol' => 'participant_role', + ); } //add register date @@ -375,15 +383,17 @@ class CRM_Event_BAO_Query { $op = key($value); $value = $value[$op]; } - $regexOp = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP'; - $query->_where[$grouping][] = " civicrm_participant.$name $regexOp '[[:<:]]*" . implode('[[:>:]]*|[[:<:]]*', (array) $value) . "[[:>:]]*' "; + if (!strstr($op, 'NULL') || !strstr($op, 'EMPTY')) { + $regexOp = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP'; + $query->_where[$grouping][] = " civicrm_participant.$name $regexOp '^" . implode('[[:cntrl:]]', (array) $value) . "$' "; + } } } $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; $tableName = empty($tableName) ? 'civicrm_participant' : $tableName; - if ($name != 'role_id') { + if ($name != 'role_id' || empty($regexOp)) { $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType); } @@ -460,7 +470,7 @@ class CRM_Event_BAO_Query { case 'participant_role': $from = " $side JOIN civicrm_option_group option_group_participant_role ON (option_group_participant_role.name = 'participant_role')"; - $from .= " $side JOIN civicrm_option_value participant_role ON (civicrm_participant.role_id = participant_role.value + $from .= " $side JOIN civicrm_option_value participant_role ON ((civicrm_participant.role_id = participant_role.value OR SUBSTRING_INDEX(role_id,'', 1) = participant_role.value) AND option_group_participant_role.id = participant_role.option_group_id ) "; break; @@ -505,6 +515,8 @@ class CRM_Event_BAO_Query { 'event_type' => 1, 'participant_id' => 1, 'participant_status' => 1, + 'participant_status_id' => 1, + 'participant_role' => 1, 'participant_role_id' => 1, 'participant_note' => 1, 'participant_register_date' => 1, diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index dca4f2ec1a..adc47cadee 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -330,10 +330,6 @@ class CRM_Export_BAO_Export { } } $returnProperties[self::defaultReturnProperty($exportMode)] = 1; - if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT && !empty($returnProperties['participant_role'])) { - unset($returnProperties['participant_role']); - $returnProperties['participant_role_id'] = 1; - } } else { $primary = TRUE; @@ -873,15 +869,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c elseif ($field == 'provider_id' || $field == 'im_provider') { $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); } - elseif ($field == 'participant_role_id') { - $participantRoles = CRM_Event_PseudoConstant::participantRole(); - $sep = CRM_Core_DAO::VALUE_SEPARATOR; - $viewRoles = array(); - foreach (explode($sep, $iterationDAO->$field) as $k => $v) { - $viewRoles[] = $participantRoles[$v]; - } - $fieldValue = implode(',', $viewRoles); - } elseif ($field == 'master_id') { $masterAddressId = NULL; if (isset($iterationDAO->master_id)) { diff --git a/api/v3/Participant.php b/api/v3/Participant.php index 443fd22072..72e7718173 100644 --- a/api/v3/Participant.php +++ b/api/v3/Participant.php @@ -163,6 +163,7 @@ function civicrm_api3_participant_get($params) { $participant = array(); while ($dao->fetch()) { + $query->convertToPseudoNames($dao); $participant[$dao->participant_id] = $query->store($dao); //@todo - is this required - contribution & pledge use the same query but don't self-retrieve custom data _civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);