From 98a9c88c9fa706a8cca7e446aee303f3e98c1edb Mon Sep 17 00:00:00 2001 From: Patrick Figel Date: Mon, 25 Feb 2019 15:30:28 +0100 Subject: [PATCH] CRM/Event - Fix participant note search parameter being ignored This fixes a bug in Search Builder that prevents criteria on the "Participant Note" field from being applied. --- CRM/Event/BAO/Query.php | 15 +++++--- tests/phpunit/CRM/Event/BAO/QueryTest.php | 42 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/CRM/Event/BAO/QueryTest.php diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index e43e38377c..f9e5e7129a 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -187,10 +187,10 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { //participant note if (!empty($query->_returnProperties['participant_note'])) { - $query->_select['participant_note'] = "civicrm_note.note as participant_note"; + $query->_select['participant_note'] = "participant_note.note as participant_note"; $query->_element['participant_note'] = 1; $query->_tables['participant_note'] = 1; - $query->_whereTables['civicrm_note'] = 1; + $query->_whereTables['participant_note'] = 1; } if (!empty($query->_returnProperties['participant_is_pay_later'])) { @@ -465,6 +465,13 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op, array('check_permission' => $checkPermission)); $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); return; + + case 'participant_note': + $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1; + $query->_tables['participant_note'] = $query->_whereTables['participant_note'] = 1; + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('participant_note.note', $op, $value, 'String'); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value)); + break; } } @@ -493,8 +500,8 @@ class CRM_Event_BAO_Query extends CRM_Core_BAO_Query { break; case 'participant_note': - $from .= " $side JOIN civicrm_note ON ( civicrm_note.entity_table = 'civicrm_participant' AND - civicrm_participant.id = civicrm_note.entity_id )"; + $from .= " $side JOIN civicrm_note participant_note ON ( participant_note.entity_table = 'civicrm_participant' AND + civicrm_participant.id = participant_note.entity_id )"; break; case 'participant_status': diff --git a/tests/phpunit/CRM/Event/BAO/QueryTest.php b/tests/phpunit/CRM/Event/BAO/QueryTest.php new file mode 100644 index 0000000000..d95a7fbb0e --- /dev/null +++ b/tests/phpunit/CRM/Event/BAO/QueryTest.php @@ -0,0 +1,42 @@ +eventCreate(); + $this->individualCreate([ + 'api.participant.create' => [ + 'event_id' => $event['id'], + 'note' => 'some_note', + ] + ]); + $this->individualCreate([ + 'api.participant.create' => [ + 'event_id' => $event['id'], + 'note' => 'some_other_note', + ] + ]); + $params = [ + [ + 0 => 'participant_note', + 1 => '=', + 2 => 'some_note', + 3 => 1, + 4 => 0, + ] + ]; + + $query = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS); + $sql = $query->query(FALSE); + $result = CRM_Core_DAO::executeQuery(implode(' ', $sql)); + $this->assertEquals(1, $result->N); + } + +} -- 2.25.1