CRM-14106 - Regex targeting the first part of if statements
[civicrm-core.git] / CRM / Activity / BAO / Query.php
CommitLineData
6a488035
TO
1<?php
2
3/*
4 +--------------------------------------------------------------------+
232624b1 5 | CiviCRM version 4.4 |
6a488035
TO
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) {
a7488080 45 if (!empty($query->_returnProperties['activity_id'])) {
6a488035
TO
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
a7488080 51 if (!empty($query->_returnProperties['activity_type_id'])) {
6a488035
TO
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
a7488080 60 if (!empty($query->_returnProperties['activity_type'])) {
6a488035
TO
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
a7488080 69 if (!empty($query->_returnProperties['activity_subject'])) {
6a488035
TO
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
a7488080 75 if (!empty($query->_returnProperties['activity_date_time'])) {
6a488035
TO
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
a7488080 81 if (!empty($query->_returnProperties['activity_status_id'])) {
6a488035
TO
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
a7488080 90 if (!empty($query->_returnProperties['activity_status'])) {
6a488035
TO
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
a7488080 99 if (!empty($query->_returnProperties['activity_duration'])) {
6a488035
TO
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
a7488080 105 if (!empty($query->_returnProperties['activity_location'])) {
6a488035
TO
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
a7488080 111 if (!empty($query->_returnProperties['activity_details'])) {
6a488035
TO
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
a7488080 117 if (!empty($query->_returnProperties['source_record_id'])) {
6a488035
TO
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
a7488080 123 if (!empty($query->_returnProperties['activity_is_test'])) {
6a488035
TO
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
a7488080 129 if (!empty($query->_returnProperties['activity_campaign_id'])) {
6a488035
TO
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
a7488080 135 if (!empty($query->_returnProperties['activity_engagement_level'])) {
6a488035
TO
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
a7488080 141 if (!empty($query->_returnProperties['source_contact'])) {
37eb6ff9 142 $query->_select['source_contact'] = 'source_contact.sort_name as source_contact';
6a488035
TO
143 $query->_element['source_contact'] = 1;
144 $query->_tables['source_contact'] = $query->_whereTables['source_contact'] = 1;
145 }
4041c9b6 146
a7488080 147 if (!empty($query->_returnProperties['activity_result'])) {
4041c9b6
DG
148 $query->_select['activity_result'] = 'civicrm_activity.result as activity_result';
149 $query->_element['result'] = 1;
150 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
151 }
6a488035
TO
152 }
153
154 /**
155 * Given a list of conditions in query generate the required
156 * where clause
157 *
158 * @return void
159 * @access public
160 */
161 static function where(&$query) {
28c666be 162 $grouping = NULL;
6a488035
TO
163 foreach (array_keys($query->_params) as $id) {
164 if (substr($query->_params[$id][0], 0, 9) == 'activity_') {
165 if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) {
166 $query->_useDistinct = TRUE;
167 }
6a488035
TO
168 $grouping = $query->_params[$id][3];
169 self::whereClauseSingle($query->_params[$id], $query);
170 }
171 }
6a488035
TO
172 }
173
174 /**
175 * where clause for a single field
176 *
177 * @return void
178 * @access public
179 */
180 static function whereClauseSingle(&$values, &$query) {
181 list($name, $op, $value, $grouping, $wildcard) = $values;
182
183 $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
184 $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
185 if ($query->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
186 $query->_skipDeleteClause = TRUE;
187 }
188
189 switch ($name) {
190 case 'activity_type_id':
191 $types = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
192
193 //get the component activity types.
194 $compActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, TRUE);
195
196 $clause = array();
197 if (is_array($value)) {
198 foreach ($value as $id => $dontCare) {
199 if (array_key_exists($id, $types) && $dontCare) {
200 $clause[] = "'" . CRM_Utils_Type::escape($types[$id], 'String') . "'";
201 if (array_key_exists($id, $compActTypes)) {
202 CRM_Contact_BAO_Query::$_considerCompActivities = TRUE;
203 }
204 }
205 }
206 $activityTypes = implode(',', array_keys($value));
207 }
208 else {
209 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
210 $activityTypes = $value;
211 if (array_key_exists($value, $compActTypes)) {
212 CRM_Contact_BAO_Query::$_considerCompActivities = TRUE;
213 }
214 }
215 $query->_where[$grouping][] = ' civicrm_activity.activity_type_id IN (' . $activityTypes . ')';
216 $query->_qill[$grouping][] = ts('Activity Type') . ' ' . implode(' ' . ts('or') . ' ', $clause);
217 break;
218
219 case 'activity_survey_id':
220 if (!$value) {
221 break;
222 }
223 $value = CRM_Utils_Type::escape($value, 'Integer');
224 $query->_where[$grouping][] = " source_record_id = $value";
225 $query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
226 break;
227
228 case 'activity_engagement_level':
229 if (!$value) {
230 break;
231 }
232
233 $value = CRM_Utils_Type::escape($value, 'Integer');
234 $query->_where[$grouping][] = " engagement_level = $value";
235 $query->_qill[$grouping][] = ts('Engagement Index') . ' - ' . CRM_Core_OptionGroup::getLabel('engagement_index', $value);
236 break;
237
238 case 'activity_role':
239 CRM_Contact_BAO_Query::$_activityRole = $values[2];
e7e657f0 240 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
a24b3694 241 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
242 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
243 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
f813f78e 244
91da6cd5 245 if ($values[2]) {
6a488035 246 $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
91da6cd5 247 if ($values[2] == 1) {
a24b3694 248 $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = $sourceID";
91da6cd5
DL
249 $query->_qill[$grouping][] = ts('Activity created by');
250 }
251 else if ($values[2] == 2) {
a24b3694 252 $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = $assigneeID";
91da6cd5
DL
253 $query->_qill[$grouping][] = ts('Activity assigned to');
254 }
255 else if ($values[2] == 3) {
a24b3694 256 $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = $targetID";
91da6cd5
DL
257 $query->_qill[$grouping][] = ts('Activity targeted to');
258 }
6a488035
TO
259 }
260 break;
261
262 case 'activity_status':
263 $status = CRM_Core_PseudoConstant::activityStatus();
264 $clause = array();
265 if (is_array($value)) {
266 foreach ($value as $k => $v) {
267 if ($k) {
268 $clause[] = "'" . CRM_Utils_Type::escape($status[$k], 'String') . "'";
269 }
270 }
271 }
272 else {
273 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
274 }
275 $query->_where[$grouping][] = ' civicrm_activity.status_id IN (' . implode(',', array_keys($value)) . ')';
276 $query->_qill[$grouping][] = ts('Activity Status') . ' - ' . implode(' ' . ts('or') . ' ', $clause);
277 break;
278
279 case 'activity_subject':
280 $n = trim($value);
281 $value = strtolower(CRM_Core_DAO::escapeString($n));
282 if ($wildcard) {
283 if (strpos($value, '%') !== FALSE) {
284 // only add wild card if not there
285 $value = "'$value'";
286 }
287 else {
288 $value = "'%$value%'";
289 }
290 $op = 'LIKE';
291 }
292 else {
293 $value = "'$value'";
294 }
295 $wc = ($op != 'LIKE') ? "LOWER(civicrm_activity.subject)" : "civicrm_activity.subject";
296 $query->_where[$grouping][] = " $wc $op $value";
297 $query->_qill[$grouping][] = ts('Subject') . " $op - '$n'";
298 break;
299
300 case 'activity_test':
28c666be
CW
301 // We dont want to include all tests for sql OR CRM-7827
302 if (!$value || $query->getOperator() != 'OR') {
303 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.is_test", $op, $value, "Boolean");
304 if ($value) {
305 $query->_qill[$grouping][] = ts('Activity is a Test');
306 }
6a488035
TO
307 }
308 break;
309
310 case 'activity_date':
311 case 'activity_date_low':
312 case 'activity_date_high':
313 $query->dateQueryBuilder($values,
314 'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date')
315 );
316 break;
317
318 case 'activity_id':
319 if (empty($value)) {
320 break;
321 }
322
323 if (is_array($value)) {
324 foreach ($value as $k => $v) {
325 $value[$k] = CRM_Utils_Type::escape($v, 'Integer');
326 }
327 }
328 else {
329 $value = array(CRM_Utils_Type::escape($value, 'Integer'));
330 }
331 $query->_where[$grouping][] = "civicrm_activity.id IN (" . implode(",", $value) . ")";
332 $query->_qill[$grouping][] = ts('Activity Id(s) %1', array(1 => implode($value)));
333 break;
334
335 case 'activity_taglist':
336 $taglist = $value;
337 $value = array();
338 foreach ($taglist as $val) {
339 if ($val) {
340 $val = explode(',', $val);
341 foreach ($val as $tId) {
342 if (is_numeric($tId)) {
343 $value[$tId] = 1;
344 }
345 }
346 }
347 }
91da6cd5 348
6a488035
TO
349 case 'activity_tags':
350 $value = array_keys($value);
cd43c5e3 351 $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
6a488035
TO
352
353 $names = array();
354 $val = array();
355 if (is_array($value)) {
356 foreach ($value as $k => $v) {
357 $names[] = $activityTags[$v];
358 }
359 }
360 $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")";
361 $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names);
362 $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1;
363 break;
364
365 case 'activity_campaign_id':
366 $campParams = array(
367 'op' => $op,
368 'campaign' => $value,
369 'grouping' => $grouping,
370 'tableName' => 'civicrm_activity',
371 );
372 CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query);
4041c9b6
DG
373 break;
374 case 'activity_result':
375 if(is_array($value)) {
376 $safe = NULL;
377 while(list(,$k) = each($value)) {
378 $safe[] = "'" . CRM_Utils_Type::escape($k, 'String') . "'";
379 }
380 $query->_where[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")";
381 $query->_qill[$grouping][] = ts("Activity Result - %1", array(1 => implode(' or ', $safe)));
382 }
383 break;
6a488035
TO
384 }
385 }
386
387 static function from($name, $mode, $side) {
388 $from = NULL;
389 switch ($name) {
390 case 'civicrm_activity':
9393897f 391 //CRM-7480 we are going to civicrm_activity table either
6a488035
TO
392 //from civicrm_activity_target or civicrm_activity_assignment.
393 //as component specific activities does not have entry in
394 //activity target table so lets consider civicrm_activity_assignment.
91da6cd5
DL
395 $from .= " INNER JOIN civicrm_activity_contact
396 ON ( civicrm_activity_contact.contact_id = contact_a.id ) ";
397 $from .= " INNER JOIN civicrm_activity
398 ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
399 AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )";
6a488035 400
6a488035 401 $activityRole = CRM_Contact_BAO_Query::$_activityRole;
6a488035
TO
402 break;
403
404 case 'activity_status':
1d85d241 405 $from .= " $side JOIN civicrm_option_group option_group_activity_status ON (option_group_activity_status.name = 'activity_status')";
6a488035
TO
406 $from .= " $side JOIN civicrm_option_value activity_status ON (civicrm_activity.status_id = activity_status.value
407 AND option_group_activity_status.id = activity_status.option_group_id ) ";
408 break;
409
410 case 'activity_type':
1d85d241 411 $from .= " $side JOIN civicrm_option_group option_group_activity_type ON (option_group_activity_type.name = 'activity_type')";
6a488035
TO
412 $from .= " $side JOIN civicrm_option_value activity_type ON (civicrm_activity.activity_type_id = activity_type.value
413 AND option_group_activity_type.id = activity_type.option_group_id ) ";
414 break;
415
416 case 'civicrm_activity_tag':
417 $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 ) ";
418 break;
419
420 case 'source_contact':
37eb6ff9 421 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
422 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
423 $from = "
424 LEFT JOIN civicrm_activity_contact ac
425 ON ( ac.activity_id = civicrm_activity_contact.activity_id AND ac.record_type_id = {$sourceID})
426 INNER JOIN civicrm_contact source_contact ON (ac.contact_id = source_contact.id)";
6a488035
TO
427 break;
428 }
429
430 return $from;
431 }
432
433 /**
434 * getter for the qill object
435 *
436 * @return string
437 * @access public
438 */
439 function qill() {
440 return (isset($this->_qill)) ? $this->_qill : "";
441 }
442
443 /**
444 * add all the elements shared between case activity search and advanaced search
445 *
446 * @access public
447 *
448 * @return void
449 * @static
450 */
451 static function buildSearchForm(&$form) {
452 $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
453 asort($activityOptions);
454 foreach ($activityOptions as $activityID => $activity) {
455 $form->_activityElement =&
456 $form->addElement(
457 'checkbox',
458 "activity_type_id[$activityID]",
459 NULL,
460 $activity,
461 array('onClick' => 'showCustomData( this.id );')
462 );
463 }
464
465 CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
466
91da6cd5 467 $activityRoles = array(
18d2d5e2 468 3 => ts('With'),
91da6cd5 469 2 => ts('Assigned to'),
18d2d5e2 470 1 => ts('Added by'),
91da6cd5 471 );
6a488035 472 $form->addRadio('activity_role', NULL, $activityRoles);
18d2d5e2 473 $form->setDefaults(array('activity_role' => 3));
6a488035
TO
474 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
475 foreach ($activityStatus as $activityStatusID => $activityStatusName) {
476 $activity_status[] = $form->createElement('checkbox', $activityStatusID, NULL, $activityStatusName);
477 }
478 $form->addGroup($activity_status, 'activity_status', ts('Activity Status'));
479 $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1));
480 $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
481 $form->addYesNo('activity_test', ts('Activity is a Test?'));
482 $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
483 if ($activity_tags) {
484 foreach ($activity_tags as $tagID => $tagName) {
485 $form->_tagElement = &$form->addElement('checkbox', "activity_tags[$tagID]",
486 NULL, $tagName
487 );
488 }
489 }
490
491 $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
492 CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE, TRUE);
493
9231464f
KJ
494 $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE);
495 if ($surveys) $form->add('select', 'activity_survey_id', ts('Survey / Petition'),
6a488035
TO
496 array(
497 '' => ts('- none -')) + $surveys, FALSE
498 );
499
500 $extends = array('Activity');
501 $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
502 if ($groupDetails) {
503 $form->assign('activityGroupTree', $groupDetails);
504 foreach ($groupDetails as $group) {
505 foreach ($group['fields'] as $field) {
506 $fieldId = $field['id'];
507 $elementName = 'custom_' . $fieldId;
508 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
509 }
510 }
511 }
512
513 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id');
514
515 //add engagement level CRM-7775
516 $buildEngagementLevel = FALSE;
4041c9b6 517 $buildSurveyResult = FALSE;
6a488035
TO
518 if (CRM_Campaign_BAO_Campaign::isCampaignEnable() &&
519 CRM_Campaign_BAO_Campaign::accessCampaign()
520 ) {
521 $buildEngagementLevel = TRUE;
522 $form->add('select', 'activity_engagement_level',
523 ts('Engagement Index'),
524 array('' => ts('- any -')) + CRM_Campaign_PseudoConstant::engagementLevel()
525 );
6a488035 526
4041c9b6
DG
527 // Add survey result field.
528 $optionGroups = CRM_Campaign_BAO_Survey::getResultSets( 'name' );
529 $resultOptions = array();
530 foreach ( $optionGroups as $gid => $name ) {
531 if ( $name ) {
532 $value = array();
533 $value = CRM_Core_OptionGroup::values($name);
534 if (!empty($value)) {
535 while(list($k,$v) = each($value)) {
536 $resultOptions[$v] = $v;
537 }
538 }
539 }
540 }
541 // If no survey result options have been created, don't build
542 // the field to avoid clutter.
543 if(count($resultOptions) > 0) {
544 $buildSurveyResult = TRUE;
545 asort($resultOptions);
546 $form->add('select', 'activity_result', ts("Survey Result"),
547 $resultOptions, FALSE,
548 array('id' => 'activity_result', 'multiple' => 'multiple', 'title' => ts('- select -'))
549 );
550 }
551 }
552
6a488035 553 $form->assign('buildEngagementLevel', $buildEngagementLevel);
4041c9b6 554 $form->assign('buildSurveyResult', $buildSurveyResult);
6a488035
TO
555 $form->setDefaults(array('activity_test' => 0));
556 }
557
6a488035
TO
558 static function defaultReturnProperties($mode, $includeCustomFields = TRUE) {
559 $properties = NULL;
560 if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
561 $properties = array(
562 'activity_id' => 1,
563 'contact_type' => 1,
564 'contact_sub_type' => 1,
565 'sort_name' => 1,
566 'display_name' => 1,
567 'activity_type' => 1,
568 'activity_subject' => 1,
569 'activity_date_time' => 1,
570 'activity_duration' => 1,
571 'activity_location' => 1,
572 'activity_details' => 1,
573 'activity_status' => 1,
37eb6ff9 574 'source_contact' => 1,
6a488035
TO
575 'source_record_id' => 1,
576 'activity_is_test' => 1,
577 'activity_campaign_id' => 1,
4041c9b6 578 'result' => 1,
6a488035
TO
579 'activity_engagement_level' => 1,
580 );
581
582 if ($includeCustomFields) {
583 // also get all the custom activity properties
584 $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Activity');
585 if (!empty($fields)) {
586 foreach ($fields as $name => $dontCare) {
587 $properties[$name] = 1;
588 }
589 }
590 }
591 }
592
593 return $properties;
594 }
595}
596