Skip to content

Commit

Permalink
Merge pull request #13697 from greenpeace-cee/fix-event-search
Browse files Browse the repository at this point in the history
CRM/Event - Fix participant note search parameter being ignored
  • Loading branch information
eileenmcnaughton authored Mar 21, 2019
2 parents fa61b2b + 98a9c88 commit adf139c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
15 changes: 11 additions & 4 deletions CRM/Event/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ public static function select(&$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'])) {
Expand Down Expand Up @@ -465,6 +465,13 @@ public static function whereClauseSingle(&$values, &$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;
}
}

Expand Down Expand Up @@ -493,8 +500,8 @@ public static function from($name, $mode, $side) {
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':
Expand Down
42 changes: 42 additions & 0 deletions tests/phpunit/CRM/Event/BAO/QueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @group headless
*/
class CRM_Event_BAO_QueryTest extends CiviUnitTestCase {

public function setUp() {
parent::setUp();
}

public function testParticipantNote() {
$event = $this->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);
}

}

0 comments on commit adf139c

Please sign in to comment.