From f179424e66ce29818463396d6c9a6175caed9bf0 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Fri, 26 Feb 2016 18:30:39 +0530 Subject: [PATCH] CRM-17780 -- Allow multiple-selection of Events by Title on Searches --- CRM/Contact/Form/Search.php | 2 +- CRM/Event/BAO/Query.php | 34 +++++++++++++++++----- CRM/Event/Form/Search.php | 15 ++++++---- templates/CRM/Event/Form/Search/Common.tpl | 27 +++-------------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 311e53d707..6a0ee798a6 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -150,7 +150,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { * * @var array */ - protected $entityReferenceFields = array('membership_type_id'); + protected $entityReferenceFields = array('event_id', 'membership_type_id'); /** * Name of the selector to use. diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 29dd6eab1b..c40c084c11 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -285,9 +285,20 @@ class CRM_Event_BAO_Query { $value = $extractEventId[2]; unset($query->_where[$grouping][$key]); } + else if (strstr($val, 'civicrm_event.id IN')) { + //extract the first event id if multiple events are selected + preg_match('/civicrm_event.id IN \(\"(\d+)/', $val, $matches); + $value = $matches[1]; + unset($query->_where[$grouping][$key]); + } + } + if ($exEventId) { + $extractEventId = explode(" ", $exEventId); + $value = $extractEventId[2]; + } + else if(!empty($matches[1])) { + $value = $matches[1]; } - $extractEventId = explode(" ", $exEventId); - $value = $extractEventId[2]; unset($query->_where[$grouping][$key]); } $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event'); @@ -328,12 +339,13 @@ class CRM_Event_BAO_Query { return; case 'participant_fee_id': - $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $value, 'label'); - $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); - if ($value) { - $query->_where[$grouping][] = "civicrm_participant.fee_level LIKE '%$feeLabel%'"; - $query->_qill[$grouping][] = ts("Fee level") . " contains $feeLabel"; + foreach ($value as $k => &$val) { + $val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label'); + $val = CRM_Core_DAO::escapeString(trim($val)); } + $feeLabel = implode('|', $value); + $query->_where[$grouping][] = "civicrm_participant.fee_level REGEXP '{$feeLabel}'"; + $query->_qill[$grouping][] = ts("Fee level") . " IN " . implode(', ', $value); $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; return; @@ -575,6 +587,7 @@ class CRM_Event_BAO_Query { $form->addEntityRef('event_id', ts('Event Name'), array( 'entity' => 'event', 'placeholder' => ts('- any -'), + 'multiple' => 1, 'select' => array('minimumInputLength' => 0), ) ); @@ -587,7 +600,12 @@ class CRM_Event_BAO_Query { ), ) ); - $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select')); + $obj = new CRM_Report_Form_Event_ParticipantListing(); + $form->add('select', 'participant_fee_id', + ts('Fee Level'), + $obj->getPriceLevels(), + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')) + ); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 6fbf40a321..b1ba0ac0ad 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -130,7 +130,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { ); } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); + $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $selector = new CRM_Event_Selector_Search($this->_queryParams, $this->_action, NULL, @@ -215,9 +215,12 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { // CRM-15379 if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; - $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label'); - $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); - $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )"; + foreach ($participant_fee_id as $k => &$val) { + $val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label'); + $val = CRM_Core_DAO::escapeString(trim($val)); + } + $feeLabel = implode('|', $participant_fee_id); + $seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )"; } $seatClause = implode(' AND ', $seatClause); @@ -314,7 +317,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); + $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); @@ -337,7 +340,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { ); } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); + $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $selector = new CRM_Event_Selector_Search($this->_queryParams, $this->_action, diff --git a/templates/CRM/Event/Form/Search/Common.tpl b/templates/CRM/Event/Form/Search/Common.tpl index bab2fd45d6..0b16f48066 100644 --- a/templates/CRM/Event/Form/Search/Common.tpl +++ b/templates/CRM/Event/Form/Search/Common.tpl @@ -98,37 +98,18 @@ CRM.$(function($) { if (!$(this).data('select2')) { $(this).crmEntityRef(); } - isRepeating = $(this).select2('data').extra.is_recur; + if (!$.isEmptyObject($(this).select2('data')[0].extra)) { + isRepeating = $(this).select2('data')[0].extra.is_recur; + } } if (isRepeating) { $('.crm-event-form-block-event_include_repeating_events').show(); - $('label[for=event_include_repeating_events]').html(recurringLabel.replace('%1', $(this).select2('data').label)); + $('label[for=event_include_repeating_events]').html(recurringLabel.replace('%1', $(this).select2('data')[0].label)); } else { $('.crm-event-form-block-event_include_repeating_events').hide().find('input').prop('checked', false); } } $('#event_id').each(toggleRecurrigCheckbox).change(toggleRecurrigCheckbox); - - // FIXME: This could be much simpler as an entityRef field but the priceFieldValue api doesn't currently support the filters we need - $('#participant_fee_id').crmSelect2({ - placeholder: {/literal}'{ts escape="js"}- any -{/ts}'{literal}, - minimumInputLength: 1, - allowClear: true, - ajax: { - url: "{/literal}{$dataURLEventFee}{literal}", - data: function(term) { - return {term: term}; - }, - results: function(response) { - return {results: response}; - } - }, - initSelection: function(el, callback) { - CRM.api3('price_field_value', 'getsingle', {id: $(el).val()}).done(function(data) { - callback({id: data.id, text: data.label}); - }); - } - }); }); {/literal} -- 2.25.1