Participant role fix
authormonishdeb <monish.deb@webaccessglobal.com>
Wed, 26 Aug 2015 12:36:56 +0000 (18:06 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Sat, 5 Sep 2015 08:26:29 +0000 (13:56 +0530)
CRM/Contact/BAO/Query.php
CRM/Event/BAO/Query.php
CRM/Export/BAO/Export.php
api/v3/Participant.php

index 752ec95f6a2e0d541490448bf855022f1f437d41..c643f9edeb6b2ae026626169a30f9c1aeb445776 100644 (file)
@@ -5519,11 +5519,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['pseudoField'], array('flip' => 1));
-          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);
         }
index ae793cd60673fbf042572ebdc27d6381c353ec28..1b6b0fddc0ec0e4a08d7758ec8e214fecb2fcaeb 100644 (file)
@@ -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
@@ -372,15 +380,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);
         }
 
@@ -470,7 +480,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', 1) = participant_role.value)
                                AND option_group_participant_role.id = participant_role.option_group_id ) ";
         break;
 
@@ -515,6 +525,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,
index 198e38dcae0cc0a1894bb28d2e06a5719fbad0c0..d1c165299f1593035d21bde12a1288a05af8e442 100644 (file)
@@ -254,10 +254,6 @@ class CRM_Export_BAO_Export {
       }
       elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
         $returnProperties['participant_id'] = 1;
-        if (!empty($returnProperties['participant_role'])) {
-          unset($returnProperties['participant_role']);
-          $returnProperties['participant_role_id'] = 1;
-        }
       }
       elseif ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
         $returnProperties['membership_id'] = 1;
@@ -831,15 +827,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)) {
index 7bca68fd963c794449c9b14f04b24a226ce5b249..19442ceb791912064cf5c325c3582b94ef3eb204 100644 (file)
@@ -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);