CRM-12550 avoid extraneous log_civicrm_email entries
[civicrm-core.git] / CRM / Activity / BAO / Query.php
CommitLineData
6a488035
TO
1<?php
2
3/*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29/**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2013
33 * $Id$
34 *
35 */
36class CRM_Activity_BAO_Query {
37
38 /**
39 * build select for Case
40 *
41 * @return void
42 * @access public
43 */
44 static function select(&$query) {
45 if (CRM_Utils_Array::value('activity_id', $query->_returnProperties)) {
46 $query->_select['activity_id'] = "civicrm_activity.id as activity_id";
47 $query->_element['activity_id'] = 1;
48 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
49 }
50
51 if (CRM_Utils_Array::value('activity_type_id', $query->_returnProperties)) {
52 $query->_select['activity_type_id'] = "activity_type.id as activity_type_id";
53 $query->_element['activity_type_id'] = 1;
54 $query->_tables['civicrm_activity'] = 1;
55 $query->_tables['activity_type'] = 1;
56 $query->_whereTables['civicrm_activity'] = 1;
57 $query->_whereTables['activity_type'] = 1;
58 }
59
60 if (CRM_Utils_Array::value('activity_type', $query->_returnProperties)) {
61 $query->_select['activity_type'] = "activity_type.label as activity_type";
62 $query->_element['activity_type'] = 1;
63 $query->_tables['civicrm_activity'] = 1;
64 $query->_tables['activity_type'] = 1;
65 $query->_whereTables['civicrm_activity'] = 1;
66 $query->_whereTables['activity_type'] = 1;
67 }
68
69 if (CRM_Utils_Array::value('activity_subject', $query->_returnProperties)) {
70 $query->_select['activity_subject'] = "civicrm_activity.subject as activity_subject";
71 $query->_element['activity_subject'] = 1;
72 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
73 }
74
75 if (CRM_Utils_Array::value('activity_date_time', $query->_returnProperties)) {
76 $query->_select['activity_date_time'] = "civicrm_activity.activity_date_time as activity_date_time";
77 $query->_element['activity_date_time'] = 1;
78 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
79 }
80
81 if (CRM_Utils_Array::value('activity_status_id', $query->_returnProperties)) {
82 $query->_select['activity_status_id'] = "activity_status.value as activity_status_id";
83 $query->_element['activity_status_id'] = 1;
84 $query->_tables['civicrm_activity'] = 1;
85 $query->_tables['activity_status'] = 1;
86 $query->_whereTables['civicrm_activity'] = 1;
87 $query->_whereTables['activity_status'] = 1;
88 }
89
90 if (CRM_Utils_Array::value('activity_status', $query->_returnProperties)) {
91 $query->_select['activity_status'] = "activity_status.label as activity_status";
92 $query->_element['activity_status'] = 1;
93 $query->_tables['civicrm_activity'] = 1;
94 $query->_tables['activity_status'] = 1;
95 $query->_whereTables['civicrm_activity'] = 1;
96 $query->_whereTables['activity_status'] = 1;
97 }
98
99 if (CRM_Utils_Array::value('activity_duration', $query->_returnProperties)) {
100 $query->_select['activity_duration'] = "civicrm_activity.duration as activity_duration";
101 $query->_element['activity_duration'] = 1;
102 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
103 }
104
105 if (CRM_Utils_Array::value('activity_location', $query->_returnProperties)) {
106 $query->_select['activity_location'] = "civicrm_activity.location as activity_location";
107 $query->_element['activity_location'] = 1;
108 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
109 }
110
111 if (CRM_Utils_Array::value('activity_details', $query->_returnProperties)) {
112 $query->_select['activity_details'] = "civicrm_activity.details as activity_details";
113 $query->_element['activity_details'] = 1;
114 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
115 }
116
117 if (CRM_Utils_Array::value('source_record_id', $query->_returnProperties)) {
118 $query->_select['source_record_id'] = "civicrm_activity.source_record_id as source_record_id";
119 $query->_element['source_record_id'] = 1;
120 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
121 }
122
123 if (CRM_Utils_Array::value('activity_is_test', $query->_returnProperties)) {
124 $query->_select['activity_is_test'] = "civicrm_activity.is_test as activity_is_test";
125 $query->_element['activity_is_test'] = 1;
126 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
127 }
128
129 if (CRM_Utils_Array::value('activity_campaign_id', $query->_returnProperties)) {
130 $query->_select['activity_campaign_id'] = 'civicrm_activity.campaign_id as activity_campaign_id';
131 $query->_element['activity_campaign_id'] = 1;
132 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
133 }
134
135 if (CRM_Utils_Array::value('activity_engagement_level', $query->_returnProperties)) {
136 $query->_select['activity_engagement_level'] = 'civicrm_activity.engagement_level as activity_engagement_level';
137 $query->_element['activity_engagement_level'] = 1;
138 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
139 }
140
141 if (CRM_Utils_Array::value('source_contact', $query->_returnProperties)) {
142 $query->_select['source_contact'] = 'source_contact.display_name as source_contact';
143 $query->_element['source_contact'] = 1;
144 $query->_tables['source_contact'] = $query->_whereTables['source_contact'] = 1;
145 }
146 }
147
148 /**
149 * Given a list of conditions in query generate the required
150 * where clause
151 *
152 * @return void
153 * @access public
154 */
155 static function where(&$query) {
156 $grouping = $testCondition = NULL;
157 foreach (array_keys($query->_params) as $id) {
158 if (substr($query->_params[$id][0], 0, 9) == 'activity_') {
159 if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) {
160 $query->_useDistinct = TRUE;
161 }
162 if ($query->_params[$id][0] == 'activity_test') {
163 $testCondition = $id;
164 continue;
165 }
166 $grouping = $query->_params[$id][3];
167 self::whereClauseSingle($query->_params[$id], $query);
168 }
169 }
170 // Only add test condition if other fields are selected
171 if ($grouping !== NULL && $testCondition &&
172 // we dont want to include all tests for sql OR CRM-7827
173 $query->getOperator() != 'OR'
174 ) {
175 self::whereClauseSingle($query->_params[$testCondition], $query);
176 }
177 }
178
179 /**
180 * where clause for a single field
181 *
182 * @return void
183 * @access public
184 */
185 static function whereClauseSingle(&$values, &$query) {
186 list($name, $op, $value, $grouping, $wildcard) = $values;
187
188 $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
189 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
190 if ($query->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
191 $query->_skipDeleteClause = TRUE;
192 }
193
194 switch ($name) {
195 case 'activity_type_id':
196 $types = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
197
198 //get the component activity types.
199 $compActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, TRUE);
200
201 $clause = array();
202 if (is_array($value)) {
203 foreach ($value as $id => $dontCare) {
204 if (array_key_exists($id, $types) && $dontCare) {
205 $clause[] = "'" . CRM_Utils_Type::escape($types[$id], 'String') . "'";
206 if (array_key_exists($id, $compActTypes)) {
207 CRM_Contact_BAO_Query::$_considerCompActivities = TRUE;
208 }
209 }
210 }
211 $activityTypes = implode(',', array_keys($value));
212 }
213 else {
214 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
215 $activityTypes = $value;
216 if (array_key_exists($value, $compActTypes)) {
217 CRM_Contact_BAO_Query::$_considerCompActivities = TRUE;
218 }
219 }
220 $query->_where[$grouping][] = ' civicrm_activity.activity_type_id IN (' . $activityTypes . ')';
221 $query->_qill[$grouping][] = ts('Activity Type') . ' ' . implode(' ' . ts('or') . ' ', $clause);
222 break;
223
224 case 'activity_survey_id':
225 if (!$value) {
226 break;
227 }
228 $value = CRM_Utils_Type::escape($value, 'Integer');
229 $query->_where[$grouping][] = " source_record_id = $value";
230 $query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
231 break;
232
233 case 'activity_engagement_level':
234 if (!$value) {
235 break;
236 }
237
238 $value = CRM_Utils_Type::escape($value, 'Integer');
239 $query->_where[$grouping][] = " engagement_level = $value";
240 $query->_qill[$grouping][] = ts('Engagement Index') . ' - ' . CRM_Core_OptionGroup::getLabel('engagement_index', $value);
241 break;
242
243 case 'activity_role':
244 CRM_Contact_BAO_Query::$_activityRole = $values[2];
245
246 //for activity target name
247 $activityTargetName = $query->getWhereValues('activity_contact_name', $grouping);
248 if (!$activityTargetName[2]) {
249 $name = NULL;
250 }
251 else {
252 $name = trim($activityTargetName[2]);
253 $name = strtolower(CRM_Core_DAO::escapeString($name));
254 }
255
256 $query->_where[$grouping][] = " contact_activity_source.is_deleted = 0 AND contact_activity_source.sort_name LIKE '%{$name}%'";
257 if ($values[2] == 1) {
258 $query->_where[$grouping][] = " civicrm_activity.source_contact_id = contact_activity_source.id";
259 $query->_qill[$grouping][] = ts('Activity created by') . " '$name'";
260 $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
261 }
262 elseif ($values[2] == 2) {
263 $query->_where[$grouping][] = " civicrm_activity_assignment.activity_id = civicrm_activity.id AND civicrm_activity_assignment.assignee_contact_id = contact_activity_source.id";
264 $query->_tables['civicrm_activity_assignment'] = $query->_whereTables['civicrm_activity_assignment'] = 1;
265 $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
266 $query->_qill[$grouping][] = ts('Activity assigned to') . " '$name'";
267 }
268 break;
269
270 case 'activity_status':
271 $status = CRM_Core_PseudoConstant::activityStatus();
272 $clause = array();
273 if (is_array($value)) {
274 foreach ($value as $k => $v) {
275 if ($k) {
276 $clause[] = "'" . CRM_Utils_Type::escape($status[$k], 'String') . "'";
277 }
278 }
279 }
280 else {
281 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
282 }
283 $query->_where[$grouping][] = ' civicrm_activity.status_id IN (' . implode(',', array_keys($value)) . ')';
284 $query->_qill[$grouping][] = ts('Activity Status') . ' - ' . implode(' ' . ts('or') . ' ', $clause);
285 break;
286
287 case 'activity_subject':
288 $n = trim($value);
289 $value = strtolower(CRM_Core_DAO::escapeString($n));
290 if ($wildcard) {
291 if (strpos($value, '%') !== FALSE) {
292 // only add wild card if not there
293 $value = "'$value'";
294 }
295 else {
296 $value = "'%$value%'";
297 }
298 $op = 'LIKE';
299 }
300 else {
301 $value = "'$value'";
302 }
303 $wc = ($op != 'LIKE') ? "LOWER(civicrm_activity.subject)" : "civicrm_activity.subject";
304 $query->_where[$grouping][] = " $wc $op $value";
305 $query->_qill[$grouping][] = ts('Subject') . " $op - '$n'";
306 break;
307
308 case 'activity_test':
309 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.is_test", $op, $value, "Boolean");
310 if ($value) {
311 $query->_qill[$grouping][] = ts('Activity is a Test');
312 }
313 break;
314
315 case 'activity_date':
316 case 'activity_date_low':
317 case 'activity_date_high':
318 $query->dateQueryBuilder($values,
319 'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date')
320 );
321 break;
322
323 case 'activity_id':
324 if (empty($value)) {
325 break;
326 }
327
328 if (is_array($value)) {
329 foreach ($value as $k => $v) {
330 $value[$k] = CRM_Utils_Type::escape($v, 'Integer');
331 }
332 }
333 else {
334 $value = array(CRM_Utils_Type::escape($value, 'Integer'));
335 }
336 $query->_where[$grouping][] = "civicrm_activity.id IN (" . implode(",", $value) . ")";
337 $query->_qill[$grouping][] = ts('Activity Id(s) %1', array(1 => implode($value)));
338 break;
339
340 case 'activity_taglist':
341 $taglist = $value;
342 $value = array();
343 foreach ($taglist as $val) {
344 if ($val) {
345 $val = explode(',', $val);
346 foreach ($val as $tId) {
347 if (is_numeric($tId)) {
348 $value[$tId] = 1;
349 }
350 }
351 }
352 }
353 case 'activity_tags':
354 $value = array_keys($value);
355 $activityTags = CRM_Core_PseudoConstant::tag();
356
357 $names = array();
358 $val = array();
359 if (is_array($value)) {
360 foreach ($value as $k => $v) {
361 $names[] = $activityTags[$v];
362 }
363 }
364 $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")";
365 $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names);
366 $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1;
367 break;
368
369 case 'activity_campaign_id':
370 $campParams = array(
371 'op' => $op,
372 'campaign' => $value,
373 'grouping' => $grouping,
374 'tableName' => 'civicrm_activity',
375 );
376 CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query);
377 return;
378 }
379 }
380
381 static function from($name, $mode, $side) {
382 $from = NULL;
383 switch ($name) {
384 case 'civicrm_activity':
385 //CRM-7480 we are going to civicrm_activitty table either
386 //from civicrm_activity_target or civicrm_activity_assignment.
387 //as component specific activities does not have entry in
388 //activity target table so lets consider civicrm_activity_assignment.
389 if (CRM_Contact_BAO_Query::$_considerCompActivities) {
390 $from .= " $side JOIN civicrm_activity_target
391 ON ( civicrm_activity_target.target_contact_id = contact_a.id ) ";
392
393 $from .= " $side JOIN civicrm_activity_assignment activity_assignment
394 ON ( activity_assignment.assignee_contact_id = contact_a.id )";
395
396 $from .= " $side JOIN civicrm_activity
397 ON ( civicrm_activity.id = civicrm_activity_target.activity_id
398 AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )";
399 }
400 elseif (CRM_Contact_BAO_Query::$_withContactActivitiesOnly) {
401 //force the civicrm_activity_target table.
402 $from .= " $side JOIN civicrm_activity_target ON civicrm_activity_target.target_contact_id = contact_a.id ";
403 $from .= " $side JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
404 AND civicrm_activity.is_deleted = 0
405 AND civicrm_activity.is_current_revision = 1 )";
406 }
407 else {
408 $activityRole = CRM_Contact_BAO_Query::$_activityRole;
409 switch ($activityRole) {
410 case 1:
411 $from .= " $side JOIN civicrm_activity ON ( civicrm_activity.source_contact_id = contact_a.id
412 AND civicrm_activity.is_deleted = 0
413 AND civicrm_activity.is_current_revision = 1 )";
414 break;
415
416 case 2:
417 $from .= " $side JOIN civicrm_activity_assignment activity_assignment ON ( activity_assignment.assignee_contact_id = contact_a.id )";
418 $from .= " $side JOIN civicrm_activity ON ( civicrm_activity.id = activity_assignment.activity_id
419 AND civicrm_activity.is_deleted = 0
420 AND civicrm_activity.is_current_revision = 1 )";
421 break;
422
423 default:
424 $from .= " $side JOIN civicrm_activity_target ON civicrm_activity_target.target_contact_id = contact_a.id ";
425 $from .= " $side JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
426 AND civicrm_activity.is_deleted = 0
427 AND civicrm_activity.is_current_revision = 1 )";
428 }
429 }
430 break;
431
432 case 'civicrm_activity_contact':
433 $activityRole = CRM_Contact_BAO_Query::$_activityRole;
434 if ($activityRole == 1) {
435 $from .= " $side JOIN civicrm_contact contact_activity_source ON civicrm_activity.source_contact_id = contact_activity_source.id
436 LEFT JOIN civicrm_email email_activity_source ON (contact_activity_source.id = email_activity_source.contact_id AND email_activity_source.is_primary = 1)";
437 }
438 elseif ($activityRole == 2) {
439 $from .= " $side JOIN civicrm_activity_assignment ON civicrm_activity.id = civicrm_activity_assignment.activity_id ";
440 $from .= " $side JOIN civicrm_contact contact_activity_source ON civicrm_activity_assignment.assignee_contact_id = contact_activity_source.id
441 LEFT JOIN civicrm_email email_activity_source ON (contact_activity_source.id = email_activity_source.contact_id AND email_activity_source.is_primary = 1)";
442 }
443 break;
444
445 case 'activity_status':
446 $from = " $side JOIN civicrm_option_group option_group_activity_status ON (option_group_activity_status.name = 'activity_status')";
447 $from .= " $side JOIN civicrm_option_value activity_status ON (civicrm_activity.status_id = activity_status.value
448 AND option_group_activity_status.id = activity_status.option_group_id ) ";
449 break;
450
451 case 'activity_type':
452 $from = " $side JOIN civicrm_option_group option_group_activity_type ON (option_group_activity_type.name = 'activity_type')";
453 $from .= " $side JOIN civicrm_option_value activity_type ON (civicrm_activity.activity_type_id = activity_type.value
454 AND option_group_activity_type.id = activity_type.option_group_id ) ";
455 break;
456
457 case 'civicrm_activity_tag':
458 $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 ) ";
459 break;
460
461 case 'source_contact':
462 $from = " $side JOIN civicrm_contact source_contact ON source_contact.id = civicrm_activity.source_contact_id";
463 break;
464 }
465
466 return $from;
467 }
468
469 /**
470 * getter for the qill object
471 *
472 * @return string
473 * @access public
474 */
475 function qill() {
476 return (isset($this->_qill)) ? $this->_qill : "";
477 }
478
479 /**
480 * add all the elements shared between case activity search and advanaced search
481 *
482 * @access public
483 *
484 * @return void
485 * @static
486 */
487 static function buildSearchForm(&$form) {
488 $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
489 asort($activityOptions);
490 foreach ($activityOptions as $activityID => $activity) {
491 $form->_activityElement =&
492 $form->addElement(
493 'checkbox',
494 "activity_type_id[$activityID]",
495 NULL,
496 $activity,
497 array('onClick' => 'showCustomData( this.id );')
498 );
499 }
500
501 CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
502
503 $activityRoles = array(1 => ts('Created by'), 2 => ts('Assigned to'));
504 $form->addRadio('activity_role', NULL, $activityRoles);
505
506 $form->addElement('text', 'activity_contact_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
507
508 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
509 foreach ($activityStatus as $activityStatusID => $activityStatusName) {
510 $activity_status[] = $form->createElement('checkbox', $activityStatusID, NULL, $activityStatusName);
511 }
512 $form->addGroup($activity_status, 'activity_status', ts('Activity Status'));
513 $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1));
514 $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
515 $form->addYesNo('activity_test', ts('Activity is a Test?'));
516 $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
517 if ($activity_tags) {
518 foreach ($activity_tags as $tagID => $tagName) {
519 $form->_tagElement = &$form->addElement('checkbox', "activity_tags[$tagID]",
520 NULL, $tagName
521 );
522 }
523 }
524
525 $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
526 CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE, TRUE);
527
528 $surveys = CRM_Campaign_BAO_Survey::getSurveys();
529 if ($surveys) $form->add('select', 'activity_survey_id', ts('Survey'),
530 array(
531 '' => ts('- none -')) + $surveys, FALSE
532 );
533
534 $extends = array('Activity');
535 $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
536 if ($groupDetails) {
537 $form->assign('activityGroupTree', $groupDetails);
538 foreach ($groupDetails as $group) {
539 foreach ($group['fields'] as $field) {
540 $fieldId = $field['id'];
541 $elementName = 'custom_' . $fieldId;
542 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
543 }
544 }
545 }
546
547 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id');
548
549 //add engagement level CRM-7775
550 $buildEngagementLevel = FALSE;
551 if (CRM_Campaign_BAO_Campaign::isCampaignEnable() &&
552 CRM_Campaign_BAO_Campaign::accessCampaign()
553 ) {
554 $buildEngagementLevel = TRUE;
555 $form->add('select', 'activity_engagement_level',
556 ts('Engagement Index'),
557 array('' => ts('- any -')) + CRM_Campaign_PseudoConstant::engagementLevel()
558 );
559 }
560
561 $form->assign('buildEngagementLevel', $buildEngagementLevel);
562 $form->setDefaults(array('activity_test' => 0));
563 }
564
565 static function addShowHide(&$showHide) {
566 $showHide->addHide('caseActivityForm');
567 $showHide->addShow('caseActivityForm_show');
568 }
569
570 static function defaultReturnProperties($mode, $includeCustomFields = TRUE) {
571 $properties = NULL;
572 if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
573 $properties = array(
574 'activity_id' => 1,
575 'contact_type' => 1,
576 'contact_sub_type' => 1,
577 'sort_name' => 1,
578 'display_name' => 1,
579 'activity_type' => 1,
580 'activity_subject' => 1,
581 'activity_date_time' => 1,
582 'activity_duration' => 1,
583 'activity_location' => 1,
584 'activity_details' => 1,
585 'activity_status' => 1,
586 'source_contact_id' => 1,
587 'source_record_id' => 1,
588 'activity_is_test' => 1,
589 'activity_campaign_id' => 1,
590 'activity_engagement_level' => 1,
591 );
592
593 if ($includeCustomFields) {
594 // also get all the custom activity properties
595 $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Activity');
596 if (!empty($fields)) {
597 foreach ($fields as $name => $dontCare) {
598 $properties[$name] = 1;
599 }
600 }
601 }
602 }
603
604 return $properties;
605 }
606}
607