From e51b7372633401e369de7dca3807f1c29d00ad86 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 28 Nov 2014 13:28:04 +0530 Subject: [PATCH] Event api break fixes and cleanup --- CRM/Contact/BAO/Query.php | 11 +- CRM/Contact/Form/Search/Advanced.php | 2 +- CRM/Contribute/Form/Search.php | 6 +- CRM/Core/BAO/Mapping.php | 1 - CRM/Event/BAO/Participant.php | 33 ++-- CRM/Event/BAO/Query.php | 201 +++++---------------- CRM/Event/Form/Search.php | 6 + templates/CRM/Event/Form/Search/Common.tpl | 20 +- xml/schema/Event/Event.xml | 8 +- xml/schema/Event/Participant.xml | 8 +- 10 files changed, 93 insertions(+), 203 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index dfa13d4bf3..3a6ec31952 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1542,7 +1542,7 @@ class CRM_Contact_BAO_Query { return $result; } - if ($apiEntity) { + if ($apiEntity && substr($id, 0, strlen($apiEntity)) != $apiEntity) { $id = $apiEntity . '_' . $id; } @@ -5551,12 +5551,13 @@ 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 ($value['pseudoField'] == 'participant_role') { - $viewRoles = array(); + 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) { - $viewRoles[] = CRM_Event_PseudoConstant::participantRole($v); + $viewValues[] = $pseudoOptions[$v]; } - $dao->$key = implode(', ', $viewRoles); + $dao->$key = implode(', ', $viewValues); } else { $labels = CRM_Core_OptionGroup::values($value['pseudoField']); diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 963efef85a..a9aad9c576 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -364,7 +364,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { } } - foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status', 'contribution_source', 'contribution_trxn_id', 'activity_type_id', 'status_id', 'activity_subject') as $element) { + foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status', 'contribution_source', 'contribution_trxn_id', 'activity_type_id', 'status_id', 'activity_subject', 'participant_status_id', 'participant_role_id') as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); if ($value) { if (is_array($value)) { diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index d70a2f8533..fdb7ffafb8 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -275,9 +275,9 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { if (is_array($value)) { $this->_formValues[$element] = array('IN' => $value); } - } - else { - $this->_formValues[$element] = array('LIKE' => "%$value%"); + else { + $this->_formValues[$element] = array('LIKE' => "%$value%"); + } } } diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 4d202a00ae..cbca237afb 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -423,7 +423,6 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields); } - unset($fields['Participant']['participant_contact_id']); $compArray['Participant'] = ts('Participant'); } } diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index ca1a28299d..55aaf9cb79 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -110,6 +110,10 @@ class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant { // ensure that role ids are encoded as a string if (isset($params['role_id']) && is_array($params['role_id'])) { + if (in_array(key($params['role_id']), CRM_Core_DAO::acceptedSQLOperators())) { + $op = key($params['role_id']); + $params['role_id'] = $params['role_id'][$op]; + } $params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']); } @@ -750,44 +754,31 @@ GROUP BY participant.event_id $fields = array(); $participantFields = CRM_Event_DAO_Participant::export(); + $eventFields = CRM_Event_DAO_Event::export(); $noteField = array( 'participant_note' => array( 'title' => 'Participant Note', 'name' => 'participant_note', - ), - ); + 'type' => CRM_Utils_Type::T_STRING, + )); $participantStatus = array( 'participant_status' => array( 'title' => 'Participant Status', 'name' => 'participant_status', - ), - ); + 'type' => CRM_Utils_Type::T_STRING, + )); $participantRole = array( 'participant_role' => array( 'title' => 'Participant Role', 'name' => 'participant_role', - ), - ); - - //CRM-13595 add event id to participant export - $eventid = array( - 'event_id' => array( - 'title' => 'Event ID', - 'name' => 'event_id', - ), - ); - $eventtitle = array( - 'event_title' => array( - 'title' => 'Event Title', - 'name' => 'event_title', - ), - ); + 'type' => CRM_Utils_Type::T_STRING, + )); $discountFields = CRM_Core_DAO_Discount::export(); - $fields = array_merge($participantFields, $participantStatus, $participantRole, $eventid, $eventtitle, $noteField, $discountFields); + $fields = array_merge($participantFields, $participantStatus, $participantRole, $eventFields, $noteField, $discountFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant')); diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index ca8f7550a7..f53d09b201 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -76,6 +76,12 @@ class CRM_Event_BAO_Query { $query->_element['participant_fee_level'] = 1; } + //add participant contact ID + if (!empty($query->_returnProperties['participant_contact_id'])) { + $query->_select['participant_contact_id'] = "civicrm_participant.contact_id as participant_contact_id"; + $query->_element['participant_contact_id'] = 1; + } + //add fee amount if (!empty($query->_returnProperties['participant_fee_amount'])) { $query->_select['participant_fee_amount'] = "civicrm_participant.fee_amount as participant_fee_amount"; @@ -134,6 +140,10 @@ class CRM_Event_BAO_Query { $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 @@ -234,6 +244,8 @@ class CRM_Event_BAO_Query { */ public static function whereClauseSingle(&$values, &$query) { list($name, $op, $value, $grouping, $wildcard) = $values; + $fields = CRM_Event_BAO_Participant::exportableFields(); + switch ($name) { case 'event_start_date_low': case 'event_start_date_high': @@ -249,13 +261,6 @@ class CRM_Event_BAO_Query { ); return; - case 'event_id': - $query->_where[$grouping][] = "civicrm_event.id $op {$value}"; - $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, 'title'); - $query->_qill[$grouping][] = ts('Event') . " $op {$eventTitle}"; - $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; - return; - case 'event_include_repeating_events': /** * Include Repeating Events @@ -292,14 +297,6 @@ class CRM_Event_BAO_Query { $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; return; - case 'event_type_id': - - $eventTypes = CRM_Core_OptionGroup::values("event_type"); - $query->_where[$grouping][] = "civicrm_participant.event_id = civicrm_event.id and civicrm_event.event_type_id = '{$value}'"; - $query->_qill[$grouping][] = ts('Event Type - %1', array(1 => $eventTypes[$value])); - $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; - return; - case 'participant_test': // We dont want to include all tests for sql OR CRM-7827 if (!$value || $query->getOperator() != 'OR') { @@ -325,18 +322,6 @@ class CRM_Event_BAO_Query { $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; return; - case 'participant_fee_amount': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.fee_amount", - $op, - $value, - "Money" - ); - if ($value) { - $query->_qill[$grouping][] = ts("Fee Amount") . " $op $value"; - } - $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; - return; - case 'participant_fee_amount_high': case 'participant_fee_amount_low': $query->numberRangeBuilder($values, @@ -344,105 +329,35 @@ class CRM_Event_BAO_Query { ); return; - case 'participant_pay_later': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.is_pay_later", - $op, - $value, - "Boolean" - ); - $query->_qill[$grouping][] = $value ? ts("Participant is Pay Later") : ts("Participant is not Pay Later"); - $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; - return; - case 'participant_status': case 'participant_status_id': - $val = array(); - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[$k] = $k; - } - } - $status = implode(',', $val); - } - else { - $status = $value; - } - - if (count($val) > 0) { - $op = 'IN'; - $status = "({$status})"; - } - - $statusTypes = CRM_Event_PseudoConstant::participantStatus(); - $names = array(); - - if (!empty($val)) { - foreach ($val as $id => $dontCare) { - $names[] = $statusTypes[$id]; - } - } - else { - if (!empty($value)) { - $names[] = $statusTypes[$value]; - } - } - - $query->_qill[$grouping][] = ts('Participant Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); - - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.status_id", - $op, - $status, - "Integer" - ); - $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; - return; - case 'participant_role': case 'participant_role_id': - $val = array(); - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[$k] = $k; - } - } + case 'participant_source': + case 'participant_id': + case 'participant_contact_id': + case 'participant_pay_later': + case 'participant_fee_amount': + case 'participant_fee_level': + $qillName = $name; + if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level'))) { + $name = str_replace('participant_', '', $name); } - else { - $val = array($value => 1); + if ($name == 'participant_pay_later') { + $name = str_replace('participant', 'is', $name); + $qillName = 'participant_' . $name; } - $roleTypes = CRM_Event_PseudoConstant::participantRole(); + $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; - $names = array(); - foreach ($val as $id => $dontCare) { - if (!empty($roleTypes[$id])) { - $names[] = $roleTypes[$id]; - } + if (in_array($name, array('participant_status', 'participant_role'))) { + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, $dataType); } - - if (!empty($names)) { - $query->_qill[$grouping][] = - ts('Participant Role %1', array(1 => $op)) . - ' ' . - implode(' ' . ts('or') . ' ', $names); - $query->_where[$grouping][] = - " civicrm_participant.role_id REGEXP '[[:<:]]" . - implode('[[:>:]]|[[:<:]]', array_keys($val)) . - "[[:>:]]' "; - - $query->_tables['civicrm_participant'] = - $query->_whereTables['civicrm_participant'] = 1; + else { + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.$name", $op, $value, $dataType); } - return; - - case 'participant_source': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.source", - $op, - $value, - "String" - ); - $query->_qill[$grouping][] = ts("Participant Source") . " $op $value"; + 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; return; @@ -452,38 +367,23 @@ class CRM_Event_BAO_Query { ); return; - case 'participant_id': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.id", $op, $value, "Integer"); - $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; - return; - case 'event_id': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.id", - $op, - $value, - "Integer" - ); - $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; - $title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $value, "title"); - $query->_qill[$grouping][] = ts('Event') . " $op $value"; - return; + case 'event_is_public': + case 'event_type_id': - case 'participant_contact_id': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.contact_id", - $op, - $value, - "Integer" - ); - $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; - return; + $qillName = $name; + if (in_array($name, array('event_id', 'event_is_public'))) { + $name = str_replace('event_', '', $name); + } + $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; - case 'event_is_public': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.is_public", - $op, - $value, - "Integer" - ); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.$name", $op, $value, $dataType); $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; + if (!array_key_exists($qillName, $fields)) { + break; + } + list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); return; case 'participant_campaign_id': @@ -636,14 +536,13 @@ class CRM_Event_BAO_Query { CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); $eventIncludeRepeatingEvents = &$form->addElement('checkbox', "event_include_repeating_events", NULL, ts(' Include Repeating Events (If Any) ? ')); - $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); - foreach ($status as $id => $Name) { - $form->_participantStatus = &$form->addElement('checkbox', "participant_status_id[$id]", NULL, $Name); - } + $form->addSelect('participant_status_id', + array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) + ); - foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { - $form->_participantRole = &$form->addElement('checkbox', "participant_role_id[$rId]", NULL, $rName); - } + $form->addSelect('participant_role_id', + array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) + ); $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); $form->addYesNo('participant_pay_later', ts('Participant is Pay Later?'), TRUE); diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 12baa8350c..147b093206 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -268,6 +268,12 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); + foreach (array('participant_status_id', 'participant_role_id') as $element) { + $value = CRM_Utils_Array::value($element, $this->_formValues); + if ($value && is_array($value)) { + $this->_formValues[$element] = array('IN' => $value); + } + } } if (empty($this->_formValues)) { diff --git a/templates/CRM/Event/Form/Search/Common.tpl b/templates/CRM/Event/Form/Search/Common.tpl index a4ee7ae552..4335d6a939 100644 --- a/templates/CRM/Event/Form/Search/Common.tpl +++ b/templates/CRM/Event/Form/Search/Common.tpl @@ -37,25 +37,13 @@ {include file="CRM/Core/DateRange.tpl" fieldName="event" from='_start_date_low' to='_end_date_high'} - +
-
- {foreach from=$form.participant_status_id item="participant_status_val"} -
- {$participant_status_val.html} -
- {/foreach} -
+ {$form.participant_status_id.html} - +
-
- {foreach from=$form.participant_role_id item="participant_role_id_val"} -
- {$participant_role_id_val.html} -
- {/foreach} -

+ {$form.participant_role_id.html} diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index d8f11a9e62..3583e5b4f2 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -9,10 +9,15 @@ id int unsigned - Event + Event ID true Event 1.7 + + civicrm_event
+ id + title +
id @@ -66,6 +71,7 @@ event_type_id Event Type 0 + true event_type diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index 260baff418..1b67e43a62 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -57,11 +57,11 @@ status_id participant_status_id - Participant Status + Participant Status ID /(participant.)?(status)$/i true int unsigned - false + true true 1 Participant status ID. FK to civicrm_participant_status_type. Default of 1 should map to status = @@ -91,7 +91,7 @@ role_id participant_role_id - Participant Role(s) + Participant Role ID participant_role @@ -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 -- 2.25.1