Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 | 32 | * $Id$ |
6a488035 TO |
33 | */ |
34 | class CRM_Activity_BAO_Query { | |
35 | ||
36 | /** | |
2e2605fe | 37 | * Build select for Case. |
6a488035 | 38 | * |
77b97be7 | 39 | * @param $query |
6a488035 | 40 | */ |
00be9182 | 41 | public static function select(&$query) { |
a7488080 | 42 | if (!empty($query->_returnProperties['activity_id'])) { |
6a488035 TO |
43 | $query->_select['activity_id'] = "civicrm_activity.id as activity_id"; |
44 | $query->_element['activity_id'] = 1; | |
45 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
46 | } | |
47 | ||
a7488080 | 48 | if (!empty($query->_returnProperties['activity_type_id'])) { |
5fa296f7 | 49 | $query->_select['activity_type_id'] = "activity_type.value as activity_type_id"; |
6a488035 TO |
50 | $query->_element['activity_type_id'] = 1; |
51 | $query->_tables['civicrm_activity'] = 1; | |
52 | $query->_tables['activity_type'] = 1; | |
53 | $query->_whereTables['civicrm_activity'] = 1; | |
54 | $query->_whereTables['activity_type'] = 1; | |
55 | } | |
56 | ||
a7488080 | 57 | if (!empty($query->_returnProperties['activity_type'])) { |
5fa296f7 | 58 | $query->_select['activity_type'] = "activity_type.label as activity_type"; |
6a488035 TO |
59 | $query->_element['activity_type'] = 1; |
60 | $query->_tables['civicrm_activity'] = 1; | |
61 | $query->_tables['activity_type'] = 1; | |
62 | $query->_whereTables['civicrm_activity'] = 1; | |
63 | $query->_whereTables['activity_type'] = 1; | |
64 | } | |
65 | ||
a7488080 | 66 | if (!empty($query->_returnProperties['activity_subject'])) { |
6a488035 TO |
67 | $query->_select['activity_subject'] = "civicrm_activity.subject as activity_subject"; |
68 | $query->_element['activity_subject'] = 1; | |
69 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
70 | } | |
71 | ||
a7488080 | 72 | if (!empty($query->_returnProperties['activity_date_time'])) { |
6a488035 TO |
73 | $query->_select['activity_date_time'] = "civicrm_activity.activity_date_time as activity_date_time"; |
74 | $query->_element['activity_date_time'] = 1; | |
75 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
76 | } | |
77 | ||
a7488080 | 78 | if (!empty($query->_returnProperties['activity_status_id'])) { |
6a488035 TO |
79 | $query->_select['activity_status_id'] = "activity_status.value as activity_status_id"; |
80 | $query->_element['activity_status_id'] = 1; | |
81 | $query->_tables['civicrm_activity'] = 1; | |
82 | $query->_tables['activity_status'] = 1; | |
83 | $query->_whereTables['civicrm_activity'] = 1; | |
84 | $query->_whereTables['activity_status'] = 1; | |
85 | } | |
86 | ||
a7488080 | 87 | if (!empty($query->_returnProperties['activity_status'])) { |
5fa296f7 | 88 | $query->_select['activity_status'] = "activity_status.label as activity_status, |
89 | civicrm_activity.status_id as status_id"; | |
6a488035 TO |
90 | $query->_element['activity_status'] = 1; |
91 | $query->_tables['civicrm_activity'] = 1; | |
92 | $query->_tables['activity_status'] = 1; | |
93 | $query->_whereTables['civicrm_activity'] = 1; | |
94 | $query->_whereTables['activity_status'] = 1; | |
95 | } | |
96 | ||
a7488080 | 97 | if (!empty($query->_returnProperties['activity_duration'])) { |
6a488035 TO |
98 | $query->_select['activity_duration'] = "civicrm_activity.duration as activity_duration"; |
99 | $query->_element['activity_duration'] = 1; | |
100 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
101 | } | |
102 | ||
a7488080 | 103 | if (!empty($query->_returnProperties['activity_location'])) { |
6a488035 TO |
104 | $query->_select['activity_location'] = "civicrm_activity.location as activity_location"; |
105 | $query->_element['activity_location'] = 1; | |
106 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
107 | } | |
108 | ||
a7488080 | 109 | if (!empty($query->_returnProperties['activity_details'])) { |
6a488035 TO |
110 | $query->_select['activity_details'] = "civicrm_activity.details as activity_details"; |
111 | $query->_element['activity_details'] = 1; | |
112 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
113 | } | |
114 | ||
a7488080 | 115 | if (!empty($query->_returnProperties['source_record_id'])) { |
6a488035 TO |
116 | $query->_select['source_record_id'] = "civicrm_activity.source_record_id as source_record_id"; |
117 | $query->_element['source_record_id'] = 1; | |
118 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
119 | } | |
120 | ||
a7488080 | 121 | if (!empty($query->_returnProperties['activity_is_test'])) { |
6a488035 TO |
122 | $query->_select['activity_is_test'] = "civicrm_activity.is_test as activity_is_test"; |
123 | $query->_element['activity_is_test'] = 1; | |
124 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
125 | } | |
126 | ||
a7488080 | 127 | if (!empty($query->_returnProperties['activity_campaign_id'])) { |
6a488035 TO |
128 | $query->_select['activity_campaign_id'] = 'civicrm_activity.campaign_id as activity_campaign_id'; |
129 | $query->_element['activity_campaign_id'] = 1; | |
130 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
131 | } | |
132 | ||
a7488080 | 133 | if (!empty($query->_returnProperties['activity_engagement_level'])) { |
6a488035 TO |
134 | $query->_select['activity_engagement_level'] = 'civicrm_activity.engagement_level as activity_engagement_level'; |
135 | $query->_element['activity_engagement_level'] = 1; | |
136 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
137 | } | |
138 | ||
a7488080 | 139 | if (!empty($query->_returnProperties['source_contact'])) { |
37eb6ff9 | 140 | $query->_select['source_contact'] = 'source_contact.sort_name as source_contact'; |
6a488035 TO |
141 | $query->_element['source_contact'] = 1; |
142 | $query->_tables['source_contact'] = $query->_whereTables['source_contact'] = 1; | |
143 | } | |
4041c9b6 | 144 | |
a7488080 | 145 | if (!empty($query->_returnProperties['activity_result'])) { |
4041c9b6 DG |
146 | $query->_select['activity_result'] = 'civicrm_activity.result as activity_result'; |
147 | $query->_element['result'] = 1; | |
148 | $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1; | |
149 | } | |
ffd93213 | 150 | |
4c24c842 PN |
151 | if (CRM_Utils_Array::value('parent_id', $query->_returnProperties)) { |
152 | $query->_tables['parent_id'] = 1; | |
153 | $query->_whereTables['parent_id'] = 1; | |
154 | $query->_element['parent_id'] = 1; | |
155 | } | |
6a488035 TO |
156 | } |
157 | ||
158 | /** | |
fe482240 | 159 | * Given a list of conditions in query generate the required. |
6a488035 TO |
160 | * where clause |
161 | * | |
da6b46f4 EM |
162 | * @param $query |
163 | * | |
6a488035 | 164 | * @return void |
6a488035 | 165 | */ |
00be9182 | 166 | public static function where(&$query) { |
6a488035 TO |
167 | foreach (array_keys($query->_params) as $id) { |
168 | if (substr($query->_params[$id][0], 0, 9) == 'activity_') { | |
169 | if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { | |
170 | $query->_useDistinct = TRUE; | |
171 | } | |
56bf8668 | 172 | $query->_params[$id][3]; |
6a488035 TO |
173 | self::whereClauseSingle($query->_params[$id], $query); |
174 | } | |
175 | } | |
6a488035 TO |
176 | } |
177 | ||
178 | /** | |
fe482240 | 179 | * Where clause for a single field. |
6a488035 | 180 | * |
da6b46f4 EM |
181 | * @param $values |
182 | * @param $query | |
6a488035 | 183 | * @return void |
6a488035 | 184 | */ |
00be9182 | 185 | public static function whereClauseSingle(&$values, &$query) { |
56bf8668 | 186 | list($name, $op, $value, $grouping) = $values; |
6a488035 | 187 | |
9ab34172 | 188 | $fields = CRM_Activity_BAO_Activity::exportableFields(); |
6a488035 TO |
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': | |
9ab34172 | 196 | case 'activity_status_id': |
9ab34172 | 197 | case 'activity_engagement_level': |
198 | case 'activity_subject': | |
199 | case 'activity_id': | |
6f56dc34 | 200 | case 'activity_campaign_id': |
201 | ||
9ab34172 | 202 | $qillName = $name; |
9ab34172 | 203 | if (in_array($name, array('activity_engagement_level', 'activity_id'))) { |
204 | $name = $qillName = str_replace('activity_', '', $name); | |
6a488035 | 205 | } |
9ab34172 | 206 | if (in_array($name, array('activity_status_id', 'activity_subject'))) { |
207 | $name = str_replace('activity_', '', $name); | |
208 | $qillName = str_replace('_id', '', $qillName); | |
209 | } | |
6f56dc34 | 210 | if ($name == 'activity_campaign_id') { |
211 | $name = 'campaign_id'; | |
212 | } | |
213 | ||
9ab34172 | 214 | $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; |
215 | ||
afa0b07c | 216 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.$name", $op, $value, $dataType); |
9ab34172 | 217 | list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op); |
218 | $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); | |
6a488035 TO |
219 | break; |
220 | ||
afa0b07c | 221 | case 'activity_type': |
222 | case 'activity_status': | |
223 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String'); | |
224 | list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op); | |
225 | $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value)); | |
226 | $query->_tables[$name] = $query->_whereTables[$name] = 1; | |
227 | break; | |
228 | ||
6a488035 TO |
229 | case 'activity_survey_id': |
230 | if (!$value) { | |
231 | break; | |
232 | } | |
233 | $value = CRM_Utils_Type::escape($value, 'Integer'); | |
56a5616a | 234 | $query->_where[$grouping][] = " civicrm_activity.source_record_id = $value"; |
6a488035 TO |
235 | $query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title'); |
236 | break; | |
237 | ||
6a488035 TO |
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 | } | |
4c9b6178 | 251 | elseif ($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 | } | |
4c9b6178 | 255 | elseif ($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 | ||
6a488035 | 262 | case 'activity_test': |
56bf8668 | 263 | // We don't want to include all tests for sql OR CRM-7827 |
28c666be | 264 | if (!$value || $query->getOperator() != 'OR') { |
353ffa53 | 265 | $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.is_test", $op, $value, "Boolean"); |
28c666be CW |
266 | if ($value) { |
267 | $query->_qill[$grouping][] = ts('Activity is a Test'); | |
268 | } | |
6a488035 TO |
269 | } |
270 | break; | |
271 | ||
272 | case 'activity_date': | |
273 | case 'activity_date_low': | |
274 | case 'activity_date_high': | |
275 | $query->dateQueryBuilder($values, | |
276 | 'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date') | |
277 | ); | |
278 | break; | |
279 | ||
6a488035 TO |
280 | case 'activity_taglist': |
281 | $taglist = $value; | |
282 | $value = array(); | |
283 | foreach ($taglist as $val) { | |
284 | if ($val) { | |
285 | $val = explode(',', $val); | |
286 | foreach ($val as $tId) { | |
287 | if (is_numeric($tId)) { | |
288 | $value[$tId] = 1; | |
289 | } | |
290 | } | |
291 | } | |
292 | } | |
91da6cd5 | 293 | |
6a488035 TO |
294 | case 'activity_tags': |
295 | $value = array_keys($value); | |
cd43c5e3 | 296 | $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); |
6a488035 TO |
297 | |
298 | $names = array(); | |
6a488035 TO |
299 | if (is_array($value)) { |
300 | foreach ($value as $k => $v) { | |
301 | $names[] = $activityTags[$v]; | |
302 | } | |
303 | } | |
304 | $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")"; | |
305 | $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names); | |
306 | $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1; | |
307 | break; | |
308 | ||
4041c9b6 | 309 | case 'activity_result': |
22e263ad | 310 | if (is_array($value)) { |
4041c9b6 | 311 | $safe = NULL; |
353ffa53 | 312 | while (list(, $k) = each($value)) { |
4041c9b6 DG |
313 | $safe[] = "'" . CRM_Utils_Type::escape($k, 'String') . "'"; |
314 | } | |
315 | $query->_where[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")"; | |
316 | $query->_qill[$grouping][] = ts("Activity Result - %1", array(1 => implode(' or ', $safe))); | |
317 | } | |
318 | break; | |
4c24c842 PN |
319 | |
320 | case 'parent_id': | |
321 | if ($value == 1) { | |
322 | $query->_where[$grouping][] = "parent_id.parent_id IS NOT NULL"; | |
323 | $query->_qill[$grouping][] = ts('Activities which have Followup Activities'); | |
324 | } | |
325 | elseif ($value == 2) { | |
326 | $query->_where[$grouping][] = "parent_id.parent_id IS NULL"; | |
327 | $query->_qill[$grouping][] = ts('Activities without Followup Activities'); | |
328 | } | |
329 | break; | |
ffd93213 | 330 | |
4c24c842 PN |
331 | case 'followup_parent_id': |
332 | if ($value == 1) { | |
333 | $query->_where[$grouping][] = "civicrm_activity.parent_id IS NOT NULL"; | |
334 | $query->_qill[$grouping][] = ts('Activities which are Followup Activities'); | |
335 | } | |
336 | elseif ($value == 2) { | |
337 | $query->_where[$grouping][] = "civicrm_activity.parent_id IS NULL"; | |
353ffa53 | 338 | $query->_qill[$grouping][] = ts('Activities which are not Followup Activities'); |
4c24c842 PN |
339 | } |
340 | break; | |
6a488035 TO |
341 | } |
342 | } | |
343 | ||
ffd93213 | 344 | /** |
100fef9d | 345 | * @param string $name |
ffd93213 EM |
346 | * @param $mode |
347 | * @param $side | |
348 | * | |
349 | * @return null|string | |
350 | */ | |
00be9182 | 351 | public static function from($name, $mode, $side) { |
6a488035 TO |
352 | $from = NULL; |
353 | switch ($name) { | |
354 | case 'civicrm_activity': | |
9393897f | 355 | //CRM-7480 we are going to civicrm_activity table either |
6a488035 TO |
356 | //from civicrm_activity_target or civicrm_activity_assignment. |
357 | //as component specific activities does not have entry in | |
358 | //activity target table so lets consider civicrm_activity_assignment. | |
91da6cd5 DL |
359 | $from .= " INNER JOIN civicrm_activity_contact |
360 | ON ( civicrm_activity_contact.contact_id = contact_a.id ) "; | |
361 | $from .= " INNER JOIN civicrm_activity | |
362 | ON ( civicrm_activity.id = civicrm_activity_contact.activity_id | |
363 | AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )"; | |
6a488035 | 364 | |
6a488035 TO |
365 | break; |
366 | ||
367 | case 'activity_status': | |
1d85d241 | 368 | $from .= " $side JOIN civicrm_option_group option_group_activity_status ON (option_group_activity_status.name = 'activity_status')"; |
6a488035 TO |
369 | $from .= " $side JOIN civicrm_option_value activity_status ON (civicrm_activity.status_id = activity_status.value |
370 | AND option_group_activity_status.id = activity_status.option_group_id ) "; | |
371 | break; | |
372 | ||
373 | case 'activity_type': | |
1d85d241 | 374 | $from .= " $side JOIN civicrm_option_group option_group_activity_type ON (option_group_activity_type.name = 'activity_type')"; |
6a488035 TO |
375 | $from .= " $side JOIN civicrm_option_value activity_type ON (civicrm_activity.activity_type_id = activity_type.value |
376 | AND option_group_activity_type.id = activity_type.option_group_id ) "; | |
377 | break; | |
378 | ||
379 | case 'civicrm_activity_tag': | |
380 | $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 ) "; | |
381 | break; | |
382 | ||
383 | case 'source_contact': | |
37eb6ff9 | 384 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); |
385 | $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); | |
386 | $from = " | |
387 | LEFT JOIN civicrm_activity_contact ac | |
388 | ON ( ac.activity_id = civicrm_activity_contact.activity_id AND ac.record_type_id = {$sourceID}) | |
389 | INNER JOIN civicrm_contact source_contact ON (ac.contact_id = source_contact.id)"; | |
6a488035 | 390 | break; |
ffd93213 | 391 | |
4c24c842 PN |
392 | case 'parent_id': |
393 | $from = "$side JOIN civicrm_activity AS parent_id ON civicrm_activity.id = parent_id.parent_id"; | |
394 | break; | |
6a488035 TO |
395 | } |
396 | ||
397 | return $from; | |
398 | } | |
399 | ||
400 | /** | |
fe482240 | 401 | * Getter for the qill object. |
6a488035 TO |
402 | * |
403 | * @return string | |
6a488035 | 404 | */ |
00be9182 | 405 | public function qill() { |
6a488035 TO |
406 | return (isset($this->_qill)) ? $this->_qill : ""; |
407 | } | |
408 | ||
409 | /** | |
fe482240 | 410 | * Add all the elements shared between case activity search and advanced search. |
6a488035 | 411 | * |
6a488035 | 412 | * |
100fef9d | 413 | * @param CRM_Core_Form $form |
6a488035 | 414 | * @return void |
6a488035 | 415 | */ |
00be9182 | 416 | public static function buildSearchForm(&$form) { |
6a488035 | 417 | $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); |
9ab34172 | 418 | $form->addSelect('activity_type_id', |
419 | array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) | |
420 | ); | |
6a488035 TO |
421 | |
422 | CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); | |
4c24c842 PN |
423 | $followUpActivity = array( |
424 | 1 => ts('Yes'), | |
425 | 2 => ts('No'), | |
426 | ); | |
427 | $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); | |
428 | $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); | |
91da6cd5 | 429 | $activityRoles = array( |
18d2d5e2 | 430 | 3 => ts('With'), |
91da6cd5 | 431 | 2 => ts('Assigned to'), |
18d2d5e2 | 432 | 1 => ts('Added by'), |
91da6cd5 | 433 | ); |
b847e6e7 | 434 | $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); |
18d2d5e2 | 435 | $form->setDefaults(array('activity_role' => 3)); |
9ab34172 | 436 | $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); |
437 | $form->addSelect('status_id', | |
438 | array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) | |
439 | ); | |
440 | $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); | |
6a488035 TO |
441 | $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); |
442 | $form->addYesNo('activity_test', ts('Activity is a Test?')); | |
443 | $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); | |
444 | if ($activity_tags) { | |
445 | foreach ($activity_tags as $tagID => $tagName) { | |
446 | $form->_tagElement = &$form->addElement('checkbox', "activity_tags[$tagID]", | |
447 | NULL, $tagName | |
448 | ); | |
449 | } | |
450 | } | |
451 | ||
452 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); | |
95ef220a | 453 | CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); |
6a488035 | 454 | |
9231464f | 455 | $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); |
28a04ea9 | 456 | if ($surveys) { |
457 | $form->add('select', 'activity_survey_id', ts('Survey / Petition'), | |
458 | array('' => ts('- none -')) + $surveys, FALSE, | |
459 | array('class' => 'crm-select2') | |
460 | ); | |
461 | } | |
6a488035 TO |
462 | $extends = array('Activity'); |
463 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); | |
464 | if ($groupDetails) { | |
465 | $form->assign('activityGroupTree', $groupDetails); | |
466 | foreach ($groupDetails as $group) { | |
467 | foreach ($group['fields'] as $field) { | |
468 | $fieldId = $field['id']; | |
469 | $elementName = 'custom_' . $fieldId; | |
470 | CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); | |
471 | } | |
472 | } | |
473 | } | |
474 | ||
475 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); | |
476 | ||
477 | //add engagement level CRM-7775 | |
478 | $buildEngagementLevel = FALSE; | |
4041c9b6 | 479 | $buildSurveyResult = FALSE; |
6a488035 TO |
480 | if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && |
481 | CRM_Campaign_BAO_Campaign::accessCampaign() | |
482 | ) { | |
483 | $buildEngagementLevel = TRUE; | |
76773c5a | 484 | $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); |
6a488035 | 485 | |
4041c9b6 | 486 | // Add survey result field. |
353ffa53 | 487 | $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); |
4041c9b6 | 488 | $resultOptions = array(); |
481a74f4 TO |
489 | foreach ($optionGroups as $gid => $name) { |
490 | if ($name) { | |
4041c9b6 DG |
491 | $value = array(); |
492 | $value = CRM_Core_OptionGroup::values($name); | |
493 | if (!empty($value)) { | |
353ffa53 | 494 | while (list($k, $v) = each($value)) { |
4041c9b6 DG |
495 | $resultOptions[$v] = $v; |
496 | } | |
497 | } | |
498 | } | |
499 | } | |
500 | // If no survey result options have been created, don't build | |
501 | // the field to avoid clutter. | |
22e263ad | 502 | if (count($resultOptions) > 0) { |
4041c9b6 DG |
503 | $buildSurveyResult = TRUE; |
504 | asort($resultOptions); | |
505 | $form->add('select', 'activity_result', ts("Survey Result"), | |
506 | $resultOptions, FALSE, | |
02ddf039 | 507 | array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2') |
4041c9b6 DG |
508 | ); |
509 | } | |
510 | } | |
77b97be7 | 511 | |
6a488035 | 512 | $form->assign('buildEngagementLevel', $buildEngagementLevel); |
4041c9b6 | 513 | $form->assign('buildSurveyResult', $buildSurveyResult); |
6a488035 TO |
514 | $form->setDefaults(array('activity_test' => 0)); |
515 | } | |
516 | ||
ffd93213 EM |
517 | /** |
518 | * @param $mode | |
519 | * @param bool $includeCustomFields | |
520 | * | |
521 | * @return array|null | |
522 | */ | |
00be9182 | 523 | public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { |
6a488035 TO |
524 | $properties = NULL; |
525 | if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) { | |
526 | $properties = array( | |
527 | 'activity_id' => 1, | |
528 | 'contact_type' => 1, | |
529 | 'contact_sub_type' => 1, | |
530 | 'sort_name' => 1, | |
531 | 'display_name' => 1, | |
532 | 'activity_type' => 1, | |
5511233c | 533 | 'activity_type_id' => 1, |
6a488035 TO |
534 | 'activity_subject' => 1, |
535 | 'activity_date_time' => 1, | |
536 | 'activity_duration' => 1, | |
537 | 'activity_location' => 1, | |
538 | 'activity_details' => 1, | |
539 | 'activity_status' => 1, | |
37eb6ff9 | 540 | 'source_contact' => 1, |
6a488035 TO |
541 | 'source_record_id' => 1, |
542 | 'activity_is_test' => 1, | |
543 | 'activity_campaign_id' => 1, | |
4041c9b6 | 544 | 'result' => 1, |
6a488035 | 545 | 'activity_engagement_level' => 1, |
4c24c842 | 546 | 'parent_id' => 1, |
6a488035 TO |
547 | ); |
548 | ||
549 | if ($includeCustomFields) { | |
550 | // also get all the custom activity properties | |
551 | $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Activity'); | |
552 | if (!empty($fields)) { | |
553 | foreach ($fields as $name => $dontCare) { | |
554 | $properties[$name] = 1; | |
555 | } | |
556 | } | |
557 | } | |
558 | } | |
559 | ||
560 | return $properties; | |
561 | } | |
96025800 | 562 | |
6a488035 | 563 | } |