From: monishdeb Date: Fri, 21 Aug 2015 10:30:49 +0000 (+0530) Subject: tests/phpunit/api/v3/MappingFieldTest.php X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=773ee993bbe94053460631b0a15510a670ed15a8;p=civicrm-core.git tests/phpunit/api/v3/MappingFieldTest.php --- diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 15cca74926..ae793cd606 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -129,36 +129,36 @@ class CRM_Event_BAO_Query { $query->_whereTables['event_type'] = 1; } - //add status and status_id - if (!empty($query->_returnProperties['participant_status']) || !empty($query->_returnProperties['participant_status_id'])) { - $query->_select['participant_status'] = "participant_status.label as participant_status"; - $query->_select['participant_status_id'] = "participant_status.id as participant_status_id"; + //add status_id + if (!empty($query->_returnProperties['participant_status_id'])) { + $query->_select['participant_status_id'] = "civicrm_participant.status_id as participant_status_id"; $query->_element['participant_status_id'] = 1; - $query->_element['participant_status'] = 1; $query->_tables['civicrm_participant'] = 1; + $query->_whereTables['civicrm_participant'] = 1; + } + + // get particupant_status label + if (!empty($query->_returnProperties['participant_status'])) { + $query->_select['participant_status'] = "participant_status.label as participant_status"; + $query->_element['participant_status'] = 1; $query->_tables['participant_status'] = 1; $query->_whereTables['civicrm_participant'] = 1; - $query->_whereTables['participant_status'] = 1; - $query->_pseudoConstantsSelect['participant_status'] = array( - 'pseudoField' => 'participant_status', - 'idCol' => 'participant_status_id', - ); } - //add participant_role and participant_role_id - if (!empty($query->_returnProperties['participant_role']) || !empty($query->_returnProperties['participant_role_id'])) { - $query->_select['participant_role'] = "participant_role.label as participant_role"; + //add participant_role_id + if (!empty($query->_returnProperties['participant_role_id'])) { $query->_select['participant_role_id'] = "civicrm_participant.role_id as participant_role_id"; - $query->_element['participant_role'] = 1; $query->_element['participant_role_id'] = 1; $query->_tables['civicrm_participant'] = 1; + $query->_whereTables['civicrm_participant'] = 1; + } + + //add participant_role + if (!empty($query->_returnProperties['participant_role'])) { + $query->_select['participant_status'] = "participant_role.label as participant_role"; + $query->_element['participant_role'] = 1; $query->_tables['participant_role'] = 1; $query->_whereTables['civicrm_participant'] = 1; - $query->_whereTables['participant_role'] = 1; - $query->_pseudoConstantsSelect['participant_role'] = array( - 'pseudoField' => 'participant_role', - 'idCol' => 'participant_role_id', - ); } //add register date @@ -340,6 +340,9 @@ class CRM_Event_BAO_Query { } case 'participant_status': case 'participant_role': + if (!strpos($name, '_id')) { + $name .= '_id'; + } case 'participant_source': case 'participant_id': case 'participant_contact_id': @@ -361,20 +364,26 @@ class CRM_Event_BAO_Query { if ($name == 'is_pay_later') { $qillName = $name; } + + // Participant role need a special handling as role ids are being stored with value separator if ($name == 'role_id') { $qillName = 'participant_role'; - $query->_where[$grouping][] = " civicrm_participant.$name REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', (array) $value) . "[[:>:]]' "; + if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $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) . "[[:>:]]*' "; } } $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; + $tableName = empty($tableName) ? 'civicrm_participant' : $tableName; - if (in_array($name, array('participant_status', 'participant_role'))) { - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, $dataType); - } - elseif ($name != 'role_id') { - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.$name", $op, $value, $dataType); + if ($name != 'role_id') { + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType); } + list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op); $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; diff --git a/api/v3/utils.php b/api/v3/utils.php index 62630bff71..10a0014d61 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1901,6 +1901,7 @@ function _civicrm_api3_swap_out_aliases(&$apiRequest, $fields) { ) { $apiRequest['params'][$field] = $apiRequest['params'][$values['name']]; // note that it would make sense to unset the original field here but tests need to be in place first + unset($apiRequest['params'][$values['name']]); } if (!isset($apiRequest['params'][$field]) && $uniqueName diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 052bba1ed4..236b8225ee 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -328,7 +328,7 @@ default_role_id default_role_id - Participant Role + Default Role ID true int unsigned 1 diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index e4d0bfbffe..1b67e43a62 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -102,7 +102,7 @@ true varchar 128 - false + true NULL Participant role ID. Implicit FK to civicrm_option_value where option_group = participant_role. 1.7