3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Activity_BAO_Query
{
36 * Build select for Case.
38 * @param CRM_Contact_BAO_Query $query
40 public static function select(&$query) {
41 if (!empty($query->_returnProperties
['activity_id'])) {
42 $query->_select
['activity_id'] = 'civicrm_activity.id as activity_id';
43 $query->_element
['activity_id'] = 1;
44 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
47 if (!empty($query->_returnProperties
['activity_type_id'])) {
48 $query->_select
['activity_type_id'] = 'activity_type.value as activity_type_id';
49 $query->_element
['activity_type_id'] = 1;
50 $query->_tables
['civicrm_activity'] = 1;
51 $query->_tables
['activity_type'] = 1;
52 $query->_whereTables
['civicrm_activity'] = 1;
53 $query->_whereTables
['activity_type'] = 1;
56 if (!empty($query->_returnProperties
['activity_type'])) {
57 $query->_select
['activity_type'] = 'activity_type.label as activity_type';
58 $query->_element
['activity_type'] = 1;
59 $query->_tables
['civicrm_activity'] = 1;
60 $query->_tables
['activity_type'] = 1;
61 $query->_whereTables
['civicrm_activity'] = 1;
62 $query->_whereTables
['activity_type'] = 1;
65 if (!empty($query->_returnProperties
['activity_subject'])) {
66 $query->_select
['activity_subject'] = 'civicrm_activity.subject as activity_subject';
67 $query->_element
['activity_subject'] = 1;
68 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
71 if (!empty($query->_returnProperties
['activity_date_time'])) {
72 $query->_select
['activity_date_time'] = 'civicrm_activity.activity_date_time as activity_date_time';
73 $query->_element
['activity_date_time'] = 1;
74 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
77 if (!empty($query->_returnProperties
['activity_status_id'])) {
78 $query->_select
['activity_status_id'] = 'civicrm_activity.status_id as activity_status_id';
79 $query->_element
['activity_status_id'] = 1;
80 $query->_tables
['civicrm_activity'] = 1;
81 $query->_whereTables
['civicrm_activity'] = 1;
84 if (!empty($query->_returnProperties
['activity_status'])) {
85 $query->_select
['activity_status'] = 'activity_status.label as activity_status,
86 civicrm_activity.status_id as status_id';
87 $query->_element
['activity_status'] = 1;
88 $query->_tables
['civicrm_activity'] = 1;
89 $query->_tables
['activity_status'] = 1;
90 $query->_whereTables
['civicrm_activity'] = 1;
91 $query->_whereTables
['activity_status'] = 1;
94 if (!empty($query->_returnProperties
['activity_duration'])) {
95 $query->_select
['activity_duration'] = 'civicrm_activity.duration as activity_duration';
96 $query->_element
['activity_duration'] = 1;
97 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
100 if (!empty($query->_returnProperties
['activity_location'])) {
101 $query->_select
['activity_location'] = 'civicrm_activity.location as activity_location';
102 $query->_element
['activity_location'] = 1;
103 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
106 if (!empty($query->_returnProperties
['activity_details'])) {
107 $query->_select
['activity_details'] = 'civicrm_activity.details as activity_details';
108 $query->_element
['activity_details'] = 1;
109 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
112 if (!empty($query->_returnProperties
['source_record_id'])) {
113 $query->_select
['source_record_id'] = 'civicrm_activity.source_record_id as source_record_id';
114 $query->_element
['source_record_id'] = 1;
115 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
118 if (!empty($query->_returnProperties
['activity_is_test'])) {
119 $query->_select
['activity_is_test'] = 'civicrm_activity.is_test as activity_is_test';
120 $query->_element
['activity_is_test'] = 1;
121 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
124 if (!empty($query->_returnProperties
['activity_campaign_id'])) {
125 $query->_select
['activity_campaign_id'] = 'civicrm_activity.campaign_id as activity_campaign_id';
126 $query->_element
['activity_campaign_id'] = 1;
127 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
130 if (!empty($query->_returnProperties
['activity_engagement_level'])) {
131 $query->_select
['activity_engagement_level'] = 'civicrm_activity.engagement_level as activity_engagement_level';
132 $query->_element
['activity_engagement_level'] = 1;
133 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
136 if (!empty($query->_returnProperties
['source_contact'])) {
137 $query->_select
['source_contact'] = 'source_contact.sort_name as source_contact';
138 $query->_element
['source_contact'] = 1;
139 $query->_tables
['civicrm_activity'] = $query->_tables
['source_contact'] = $query->_whereTables
['source_contact'] = 1;
142 if (!empty($query->_returnProperties
['source_contact_id'])) {
143 $query->_select
['source_contact_id'] = 'source_contact.id as source_contact_id';
144 $query->_element
['source_contact_id'] = 1;
145 $query->_tables
['civicrm_activity'] = $query->_tables
['source_contact'] = $query->_whereTables
['source_contact'] = 1;
148 if (!empty($query->_returnProperties
['activity_result'])) {
149 $query->_select
['activity_result'] = 'civicrm_activity.result as activity_result';
150 $query->_element
['result'] = 1;
151 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
154 if (CRM_Utils_Array
::value('parent_id', $query->_returnProperties
)) {
155 $query->_tables
['parent_id'] = 1;
156 $query->_whereTables
['parent_id'] = 1;
157 $query->_element
['parent_id'] = 1;
160 if (!empty($query->_returnProperties
['activity_priority'])) {
161 $query->_select
['activity_priority'] = 'activity_priority.label as activity_priority,
162 civicrm_activity.priority_id as priority_id';
163 $query->_element
['activity_priority'] = 1;
164 $query->_tables
['activity_priority'] = 1;
165 $query->_whereTables
['activity_priority'] = 1;
166 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
171 * Given a list of conditions in query generate the required where clause.
175 public static function where(&$query) {
176 foreach (array_keys($query->_params
) as $id) {
177 if (substr($query->_params
[$id][0], 0, 9) == 'activity_') {
178 if ($query->_mode
== CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
179 $query->_useDistinct
= TRUE;
181 $query->_params
[$id][3];
182 self
::whereClauseSingle($query->_params
[$id], $query);
188 * Where clause for a single field.
190 * @param array $values
191 * @param CRM_Contact_BAO_Query $query
193 public static function whereClauseSingle(&$values, &$query) {
194 list($name, $op, $value, $grouping) = $values;
196 $fields = CRM_Activity_BAO_Activity
::exportableFields();
197 $query->_tables
['civicrm_activity'] = $query->_whereTables
['civicrm_activity'] = 1;
198 if ($query->_mode
& CRM_Contact_BAO_Query
::MODE_ACTIVITY
) {
199 $query->_skipDeleteClause
= TRUE;
203 case 'activity_type_id':
204 case 'activity_status_id':
205 case 'activity_engagement_level':
207 case 'activity_campaign_id':
208 case 'activity_priority_id':
209 // We no longer expect "subject" as a specific criteria (as of CRM-19447),
210 // but we still use activity_subject in Activity.Get API
211 case 'activity_subject':
214 if (in_array($name, ['activity_engagement_level', 'activity_id'])) {
215 $name = $qillName = str_replace('activity_', '', $name);
217 if (in_array($name, [
218 'activity_status_id',
220 'activity_priority_id',
222 $name = str_replace('activity_', '', $name);
223 $qillName = str_replace('_id', '', $qillName);
225 if ($name == 'activity_campaign_id') {
226 $name = 'campaign_id';
229 $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type
::typeToString($fields[$qillName]['type']) : 'String';
231 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_activity.$name", $op, $value, $dataType);
232 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
233 $query->_qill
[$grouping][] = ts('%1 %2 %3', [
234 1 => $fields[$qillName]['title'],
240 case 'activity_text':
241 self
::whereClauseSingleActivityText($values, $query);
244 case 'activity_type':
245 case 'activity_status':
246 case 'activity_priority':
247 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("$name.label", $op, $value, 'String');
248 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
249 $query->_qill
[$grouping][] = ts('%1 %2 %3', [
250 1 => $fields[$name]['title'],
254 $query->_tables
[$name] = $query->_whereTables
[$name] = 1;
257 case 'activity_survey_id':
261 $value = CRM_Utils_Type
::escape($value, 'Integer');
262 $query->_where
[$grouping][] = " civicrm_activity.source_record_id = $value";
263 $query->_qill
[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
266 case 'activity_role':
267 CRM_Contact_BAO_Query
::$_activityRole = $values[2];
268 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
269 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
270 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
271 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
274 $query->_tables
['civicrm_activity_contact'] = $query->_whereTables
['civicrm_activity_contact'] = 1;
275 if ($values[2] == 1) {
276 $query->_where
[$grouping][] = " civicrm_activity_contact.record_type_id = $sourceID";
277 $query->_qill
[$grouping][] = ts('Activity created by');
279 elseif ($values[2] == 2) {
280 $query->_where
[$grouping][] = " civicrm_activity_contact.record_type_id = $assigneeID";
281 $query->_qill
[$grouping][] = ts('Activity assigned to');
283 elseif ($values[2] == 3) {
284 $query->_where
[$grouping][] = " civicrm_activity_contact.record_type_id = $targetID";
285 $query->_qill
[$grouping][] = ts('Activity targeted to');
290 case 'activity_test':
291 // We don't want to include all tests for sql OR CRM-7827
292 if (!$value ||
$query->getOperator() != 'OR') {
293 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_activity.is_test", $op, $value, "Boolean");
295 $query->_qill
[$grouping][] = ts('Activity is a Test');
300 case 'activity_date':
301 case 'activity_date_low':
302 case 'activity_date_high':
303 case 'activity_date_time_low':
304 case 'activity_date_time_high':
305 $query->dateQueryBuilder($values,
306 'civicrm_activity', str_replace([
309 ], '', $name), 'activity_date_time', ts('Activity Date')
313 case 'activity_taglist':
316 foreach ($taglist as $val) {
318 $val = explode(',', $val);
319 foreach ($val as $tId) {
320 if (is_numeric($tId)) {
327 case 'activity_tags':
328 $activityTags = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]);
330 if (!is_array($value)) {
331 $value = explode(',', $value);
335 foreach ($value as $k => $v) {
336 $names[] = $activityTags[$v];
339 $query->_where
[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")";
340 $query->_qill
[$grouping][] = ts('Activity Tag %1', [1 => $op]) . ' ' . implode(' ' . ts('OR') . ' ', $names);
341 $query->_tables
['civicrm_activity_tag'] = $query->_whereTables
['civicrm_activity_tag'] = 1;
344 case 'activity_result':
345 if (is_array($value)) {
347 foreach ($value as $id => $k) {
348 $safe[] = "'" . CRM_Utils_Type
::escape($k, 'String') . "'";
350 $query->_where
[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")";
351 $query->_qill
[$grouping][] = ts("Activity Result - %1", [1 => implode(' or ', $safe)]);
357 $query->_where
[$grouping][] = "civicrm_activity.parent_id IS NOT NULL";
358 $query->_qill
[$grouping][] = ts('Activities which have Followup Activities');
360 elseif ($value == 2) {
361 $query->_where
[$grouping][] = "civicrm_activity.parent_id IS NULL";
362 $query->_qill
[$grouping][] = ts('Activities without Followup Activities');
366 case 'followup_parent_id':
368 $query->_where
[$grouping][] = "civicrm_activity.parent_id IS NOT NULL";
369 $query->_qill
[$grouping][] = ts('Activities which are Followup Activities');
371 elseif ($value == 2) {
372 $query->_where
[$grouping][] = "civicrm_activity.parent_id IS NULL";
373 $query->_qill
[$grouping][] = ts('Activities which are not Followup Activities');
377 case 'source_contact':
378 case 'source_contact_id':
379 $columnName = strstr($name, '_id') ?
'id' : 'sort_name';
380 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("source_contact.{$columnName}", $op, $value, CRM_Utils_Type
::typeToString($fields[$name]['type']));
381 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Contact_DAO_Contact', $columnName, $value, $op);
382 $query->_qill
[$grouping][] = ts('%1 %2 %3', [
383 1 => $fields[$name]['title'],
392 * @param string $name
396 * @return null|string
398 public static function from($name, $mode, $side) {
401 case 'civicrm_activity':
402 //CRM-7480 we are going to civicrm_activity table either
403 //from civicrm_activity_target or civicrm_activity_assignment.
404 //as component specific activities does not have entry in
405 //activity target table so lets consider civicrm_activity_assignment.
406 $from .= " $side JOIN civicrm_activity_contact
407 ON ( civicrm_activity_contact.contact_id = contact_a.id ) ";
408 $from .= " $side JOIN civicrm_activity
409 ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
410 AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )";
411 // Do not show deleted contact's activity
412 $from .= " INNER JOIN civicrm_contact
413 ON ( civicrm_activity_contact.contact_id = civicrm_contact.id and civicrm_contact.is_deleted != 1 )";
416 case 'activity_status':
417 $from .= " $side JOIN civicrm_option_group option_group_activity_status ON (option_group_activity_status.name = 'activity_status')";
418 $from .= " $side JOIN civicrm_option_value activity_status ON (civicrm_activity.status_id = activity_status.value
419 AND option_group_activity_status.id = activity_status.option_group_id ) ";
422 case 'activity_type':
423 $from .= " $side JOIN civicrm_option_group option_group_activity_type ON (option_group_activity_type.name = 'activity_type')";
424 $from .= " $side JOIN civicrm_option_value activity_type ON (civicrm_activity.activity_type_id = activity_type.value
425 AND option_group_activity_type.id = activity_type.option_group_id ) ";
428 case 'activity_priority':
429 $from .= " $side JOIN civicrm_option_group option_group_activity_priority ON (option_group_activity_priority.name = 'priority')";
430 $from .= " $side JOIN civicrm_option_value activity_priority ON (civicrm_activity.priority_id = activity_priority.value
431 AND option_group_activity_priority.id = activity_priority.option_group_id ) ";
434 case 'civicrm_activity_tag':
435 $from .= " $side JOIN civicrm_entity_tag as civicrm_activity_tag ON ( civicrm_activity_tag.entity_table = 'civicrm_activity' AND civicrm_activity_tag.entity_id = civicrm_activity.id ) ";
438 case 'source_contact':
439 $sourceID = CRM_Core_PseudoConstant
::getKey(
440 'CRM_Activity_BAO_ActivityContact',
445 LEFT JOIN civicrm_activity_contact source_activity
446 ON (source_activity.activity_id = civicrm_activity_contact.activity_id
447 AND source_activity.record_type_id = {$sourceID})
448 LEFT JOIN civicrm_contact source_contact ON (source_activity.contact_id = source_contact.id)";
452 $from = "$side JOIN civicrm_activity AS parent_id ON civicrm_activity.id = parent_id.parent_id";
460 * Get the metadata for fields to be included on the activity search form.
462 * @todo ideally this would be a trait included on the activity search & advanced search
463 * rather than a static function.
465 public static function getSearchFieldMetadata() {
466 $fields = ['activity_type_id', 'activity_date_time', 'priority_id', 'activity_location'];
467 $metadata = civicrm_api3('Activity', 'getfields', [])['values'];
468 return array_intersect_key($metadata, array_flip($fields));
472 * Add all the elements shared between case activity search and advanced search.
474 * @param CRM_Core_Form_Search $form
476 public static function buildSearchForm(&$form) {
477 $form->addSearchFieldMetadata(['Activity' => self
::getSearchFieldMetadata()]);
478 $form->addFormFieldsFromMetadata();
480 $followUpActivity = [
484 $form->addRadio('parent_id', NULL, $followUpActivity, ['allowClear' => TRUE]);
485 $form->addRadio('followup_parent_id', NULL, $followUpActivity, ['allowClear' => TRUE]);
488 2 => ts('Assigned to'),
491 $form->addRadio('activity_role', NULL, $activityRoles, ['allowClear' => TRUE]);
492 $form->setDefaults(['activity_role' => 3]);
493 $activityStatus = CRM_Core_PseudoConstant
::get('CRM_Activity_DAO_Activity', 'status_id', [
495 'labelColumn' => 'name',
497 $form->addSelect('status_id',
499 'entity' => 'activity',
500 'multiple' => 'multiple',
501 'option_url' => NULL,
502 'placeholder' => ts('- any -'),
505 $ssID = $form->get('ssID');
506 $status = [$activityStatus['Completed'], $activityStatus['Scheduled']];
507 //If status is saved in smart group.
508 if (!empty($ssID) && !empty($form->_formValues
['activity_status_id'])) {
509 $status = $form->_formValues
['activity_status_id'];
511 $form->setDefaults(['status_id' => $status]);
513 $form->addElement('text', 'activity_text', ts('Activity Text'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
515 $form->addRadio('activity_option', '', CRM_Core_SelectValues
::activityTextOptions());
516 $form->setDefaults(['activity_option' => 'both']);
518 $form->addYesNo('activity_test', ts('Activity is a Test?'));
519 $activity_tags = CRM_Core_BAO_Tag
::getColorTags('civicrm_activity');
521 if ($activity_tags) {
522 $form->add('select2', 'activity_tags', ts('Activity Tag(s)'),
523 $activity_tags, FALSE, [
524 'id' => 'activity_tags',
527 'class' => 'crm-select2',
528 'placeholder' => ts('- select -'),
533 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_activity');
534 CRM_Core_Form_Tag
::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE);
536 $surveys = CRM_Campaign_BAO_Survey
::getSurveys(TRUE, FALSE, FALSE, TRUE);
538 $form->add('select', 'activity_survey_id', ts('Survey / Petition'),
539 ['' => ts('- none -')] +
$surveys, FALSE,
540 ['class' => 'crm-select2']
544 CRM_Core_BAO_Query
::addCustomFormFields($form, ['Activity']);
546 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($form, 'activity_campaign_id');
548 // Add engagement level CRM-7775.
549 $buildEngagementLevel = FALSE;
550 $buildSurveyResult = FALSE;
551 if (CRM_Campaign_BAO_Campaign
::isCampaignEnable() &&
552 CRM_Campaign_BAO_Campaign
::accessCampaign()
554 $buildEngagementLevel = TRUE;
555 $form->addSelect('activity_engagement_level', [
556 'entity' => 'activity',
557 'context' => 'search',
560 // Add survey result field.
561 $optionGroups = CRM_Campaign_BAO_Survey
::getResultSets('name');
563 foreach ($optionGroups as $gid => $name) {
565 $value = CRM_Core_OptionGroup
::values($name);
566 if (!empty($value)) {
567 foreach ($value as $k => $v) {
568 $resultOptions[$v] = $v;
573 // If no survey result options have been created, don't build
574 // the field to avoid clutter.
575 if (count($resultOptions) > 0) {
576 $buildSurveyResult = TRUE;
577 asort($resultOptions);
578 $form->add('select', 'activity_result', ts("Survey Result"),
579 $resultOptions, FALSE,
581 'id' => 'activity_result',
582 'multiple' => 'multiple',
583 'class' => 'crm-select2',
589 $form->assign('buildEngagementLevel', $buildEngagementLevel);
590 $form->assign('buildSurveyResult', $buildSurveyResult);
591 $form->setDefaults(['activity_test' => 0]);
596 * @param bool $includeCustomFields
600 public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) {
602 if ($mode & CRM_Contact_BAO_Query
::MODE_ACTIVITY
) {
606 'contact_sub_type' => 1,
609 'activity_type' => 1,
610 'activity_type_id' => 1,
611 'activity_subject' => 1,
612 'activity_date_time' => 1,
613 'activity_duration' => 1,
614 'activity_location' => 1,
615 'activity_details' => 1,
616 'activity_status' => 1,
617 'activity_priority' => 1,
618 'source_contact' => 1,
619 'source_record_id' => 1,
620 'activity_is_test' => 1,
621 'activity_campaign_id' => 1,
623 'activity_engagement_level' => 1,
627 if ($includeCustomFields) {
628 // also get all the custom activity properties
629 $fields = CRM_Core_BAO_CustomField
::getFieldsForImport('Activity');
630 if (!empty($fields)) {
631 foreach ($fields as $name => $dontCare) {
632 $properties[$name] = 1;
642 * Get the list of fields required to populate the selector.
644 * The default return properties array returns far too many fields for 'everyday use. Every field you add to this array
645 * kills a small kitten so add carefully.
647 public static function selectorReturnProperties() {
651 'contact_sub_type' => 1,
654 'activity_type_id' => 1,
655 'activity_subject' => 1,
656 'activity_date_time' => 1,
657 'activity_status_id' => 1,
658 'source_contact' => 1,
659 'source_record_id' => 1,
660 'activity_is_test' => 1,
661 'activity_campaign_id' => 1,
662 'activity_engagement_level' => 1,
669 * Where/qill clause for notes
671 * @param array $values
672 * @param CRM_Contact_BAO_Query $query
674 * @throws \CRM_Core_Exception
676 public static function whereClauseSingleActivityText(&$values, &$query) {
677 list($name, $op, $value, $grouping, $wildcard) = $values;
678 $activityOptionValues = $query->getWhereValues('activity_option', $grouping);
679 $activityOption = CRM_Utils_Array
::value(2, $activityOptionValues, 6);
681 $query->_useDistinct
= TRUE;
683 $label = ts('Activity Text (%1)', [1 => CRM_Utils_Array
::value($activityOption, CRM_Core_SelectValues
::activityTextOptions())]);
685 if ($activityOption %
2 == 0) {
686 $clauses[] = $query->buildClause('civicrm_activity.details', $op, $value, 'String');
688 if ($activityOption %
3 == 0) {
689 $clauses[] = $query->buildClause('civicrm_activity.subject', $op, $value, 'String');
692 $query->_where
[$grouping][] = "( " . implode(' OR ', $clauses) . " )";
693 list($qillOp, $qillVal) = $query->buildQillForFieldValue(NULL, $name, $value, $op);
694 $query->_qill
[$grouping][] = ts("%1 %2 '%3'", [