Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
06b69b18 | 5 | | CiviCRM version 4.5 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
06b69b18 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | class CRM_Report_Form_Case_Detail extends CRM_Report_Form { | |
37 | ||
38 | protected $_relField = FALSE; | |
39 | ||
40 | protected $_addressField = FALSE; | |
41 | ||
42 | protected $_emailField = FALSE; | |
43 | ||
44 | protected $_phoneField = FALSE; | |
45 | ||
46 | protected $_worldRegionField = FALSE; | |
47 | ||
48 | protected $_activityLast = FALSE; | |
49 | ||
50 | protected $_activityLastCompleted = FALSE; | |
51 | ||
52 | protected $_includeCaseDetailExtra = FALSE; | |
53 | ||
9d72cede | 54 | protected $_caseDetailExtra = array(); |
430ae6dd | 55 | |
74cf4551 EM |
56 | /** |
57 | * | |
58 | */ | |
59 | /** | |
60 | * | |
61 | */ | |
430ae6dd | 62 | function __construct() { |
01bf13dc | 63 | $this->case_statuses = CRM_Core_OptionGroup::values('case_status'); |
9d72cede EM |
64 | $this->case_types = CRM_Case_PseudoConstant::caseType(); |
65 | $rels = CRM_Core_PseudoConstant::relationshipType(); | |
6a488035 TO |
66 | foreach ($rels as $relid => $v) { |
67 | $this->rel_types[$relid] = $v['label_b_a']; | |
68 | } | |
69 | ||
9d72cede EM |
70 | $this->deleted_labels = array( |
71 | '' => ts('- select -'), | |
72 | 0 => ts('No'), | |
73 | 1 => ts('Yes') | |
74 | ); | |
a31b650c | 75 | |
6a488035 TO |
76 | $this->caseActivityTypes = array(); |
77 | foreach (CRM_Case_PseudoConstant::caseActivityType() as $typeDetail) { | |
78 | $this->caseActivityTypes[$typeDetail['id']] = $typeDetail['label']; | |
79 | } | |
80 | ||
81 | $this->_columns = array( | |
9d72cede | 82 | 'civicrm_case' => array( |
6a488035 | 83 | 'dao' => 'CRM_Case_DAO_Case', |
9d72cede EM |
84 | 'fields' => array( |
85 | 'id' => array( | |
86 | 'title' => ts('Case ID'), | |
6a488035 TO |
87 | 'no_display' => TRUE, |
88 | 'required' => TRUE, | |
89 | ), | |
9d72cede EM |
90 | 'subject' => array( |
91 | 'title' => ts('Subject'), | |
6a488035 TO |
92 | 'required' => TRUE, |
93 | ), | |
9d72cede EM |
94 | 'start_date' => array( |
95 | 'title' => ts('Start Date'), | |
6a488035 TO |
96 | 'type' => CRM_Utils_Type::T_DATE, |
97 | ), | |
9d72cede EM |
98 | 'end_date' => array( |
99 | 'title' => ts('End Date'), | |
6a488035 TO |
100 | 'type' => CRM_Utils_Type::T_DATE, |
101 | ), | |
102 | 'status_id' => array('title' => ts('Case Status')), | |
103 | 'case_type_id' => array('title' => ts('Case Type')), | |
9d72cede EM |
104 | 'is_deleted' => array( |
105 | 'title' => ts('Deleted?'), | |
a31b650c RN |
106 | 'default' => FALSE, |
107 | 'type' => CRM_Utils_Type::T_INT, | |
108 | ), | |
6a488035 | 109 | ), |
9d72cede EM |
110 | 'filters' => array( |
111 | 'start_date' => array( | |
112 | 'title' => ts('Start Date'), | |
6a488035 TO |
113 | 'operatorType' => CRM_Report_Form::OP_DATE, |
114 | 'type' => CRM_Utils_Type::T_DATE, | |
115 | ), | |
9d72cede EM |
116 | 'end_date' => array( |
117 | 'title' => ts('End Date'), | |
6a488035 TO |
118 | 'operatorType' => CRM_Report_Form::OP_DATE, |
119 | 'type' => CRM_Utils_Type::T_DATE, | |
120 | ), | |
9d72cede EM |
121 | 'status_id' => array( |
122 | 'title' => ts('Case Status'), | |
6a488035 TO |
123 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
124 | 'options' => $this->case_statuses, | |
125 | ), | |
9d72cede EM |
126 | 'case_type_id' => array( |
127 | 'title' => ts('Case Type'), | |
6a488035 TO |
128 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
129 | 'options' => $this->case_types, | |
130 | ), | |
9d72cede EM |
131 | 'is_deleted' => array( |
132 | 'title' => ts('Deleted?'), | |
a31b650c RN |
133 | 'type' => CRM_Utils_Type::T_INT, |
134 | 'operatorType' => CRM_Report_Form::OP_SELECT, | |
135 | 'options' => $this->deleted_labels, | |
136 | 'default' => 0, | |
137 | ), | |
6a488035 TO |
138 | ), |
139 | ), | |
9d72cede | 140 | 'civicrm_contact' => array( |
6a488035 | 141 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede | 142 | 'fields' => array( |
6a488035 TO |
143 | 'client_sort_name' => array( |
144 | 'name' => 'sort_name', | |
145 | 'title' => ts('Client Name'), | |
146 | 'required' => TRUE, | |
147 | ), | |
148 | 'id' => array( | |
149 | 'no_display' => TRUE, | |
150 | 'required' => TRUE, | |
151 | ), | |
152 | ), | |
9d72cede | 153 | 'filters' => array( |
6a488035 TO |
154 | 'sort_name' => array('title' => ts('Client Name')), |
155 | ), | |
156 | ), | |
9d72cede | 157 | 'civicrm_relationship' => array( |
6a488035 | 158 | 'dao' => 'CRM_Contact_DAO_Relationship', |
9d72cede EM |
159 | 'fields' => array( |
160 | 'case_role' => array( | |
161 | 'name' => 'relationship_type_id', | |
6a488035 TO |
162 | 'title' => ts('Case Role(s)'), |
163 | ), | |
164 | ), | |
9d72cede EM |
165 | 'filters' => array( |
166 | 'case_role' => array( | |
6a488035 TO |
167 | 'name' => 'relationship_type_id', |
168 | 'title' => ts('Case Role(s)'), | |
169 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
170 | 'options' => $this->rel_types, | |
171 | ), | |
172 | ), | |
173 | ), | |
9d72cede | 174 | 'civicrm_email' => array( |
6a488035 | 175 | 'dao' => 'CRM_Core_DAO_Email', |
9d72cede EM |
176 | 'fields' => array( |
177 | 'email' => array( | |
178 | 'title' => ts('Email'), | |
6a488035 TO |
179 | 'no_repeat' => TRUE, |
180 | ), | |
181 | ), | |
182 | 'grouping' => 'contact-fields', | |
183 | ), | |
9d72cede | 184 | 'civicrm_phone' => array( |
6a488035 | 185 | 'dao' => 'CRM_Core_DAO_Phone', |
9d72cede EM |
186 | 'fields' => array( |
187 | 'phone' => array( | |
188 | 'title' => ts('Phone'), | |
6a488035 TO |
189 | 'no_repeat' => TRUE, |
190 | ), | |
191 | ), | |
192 | 'grouping' => 'contact-fields', | |
193 | ), | |
9d72cede | 194 | 'civicrm_address' => array( |
6a488035 | 195 | 'dao' => 'CRM_Core_DAO_Address', |
9d72cede | 196 | 'fields' => array( |
6a488035 | 197 | 'street_address' => NULL, |
9d72cede EM |
198 | 'state_province_id' => array( |
199 | 'title' => ts('State/Province'), | |
6a488035 TO |
200 | ), |
201 | 'country_id' => array('title' => ts('Country')), | |
202 | ), | |
203 | 'grouping' => 'contact-fields', | |
9d72cede EM |
204 | 'filters' => array( |
205 | 'country_id' => array( | |
206 | 'title' => ts('Country'), | |
6a488035 TO |
207 | 'type' => CRM_Utils_Type::T_INT, |
208 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
209 | 'options' => CRM_Core_PseudoConstant::country(), | |
210 | ), | |
9d72cede EM |
211 | 'state_province_id' => array( |
212 | 'title' => ts('State/Province'), | |
6a488035 TO |
213 | 'type' => CRM_Utils_Type::T_INT, |
214 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
215 | 'options' => CRM_Core_PseudoConstant::stateProvince(), | |
216 | ), | |
217 | ), | |
218 | ), | |
9d72cede | 219 | 'civicrm_worldregion' => array( |
6a488035 | 220 | 'dao' => 'CRM_Core_DAO_Worldregion', |
9d72cede | 221 | 'filters' => array( |
6a488035 TO |
222 | 'worldregion_id' => array( |
223 | 'name' => 'id', | |
f418f381 | 224 | 'title' => ts('World Region'), |
6a488035 TO |
225 | 'type' => CRM_Utils_Type::T_INT, |
226 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
227 | 'options' => CRM_Core_PseudoConstant::worldRegion(), | |
228 | ), | |
229 | ), | |
230 | ), | |
9d72cede | 231 | 'civicrm_country' => array( |
6a488035 TO |
232 | 'dao' => 'CRM_Core_DAO_Country', |
233 | ), | |
9d72cede | 234 | 'civicrm_activity_last' => array( |
6a488035 | 235 | 'dao' => 'CRM_Activity_DAO_Activity', |
9d72cede EM |
236 | 'filters' => array( |
237 | 'last_activity_date_time' => array( | |
6a488035 TO |
238 | 'name' => 'activity_date_time', |
239 | 'title' => ts('Last Action Date'), | |
240 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
241 | ), | |
242 | ), | |
243 | 'alias' => 'civireport_activity_last', | |
244 | ), | |
9d72cede | 245 | 'civicrm_activity_last_completed' => array( |
6a488035 | 246 | 'dao' => 'CRM_Activity_DAO_Activity', |
9d72cede EM |
247 | 'fields' => array( |
248 | 'last_completed_activity_subject' => array( | |
6a488035 TO |
249 | 'name' => 'subject', |
250 | 'title' => ts('Subject of the last completed activity in the case'), | |
251 | ), | |
9d72cede | 252 | 'last_completed_activity_type' => array( |
6a488035 TO |
253 | 'name' => 'activity_type_id', |
254 | 'title' => ts('Activity type of the last completed activity'), | |
255 | ), | |
256 | ), | |
257 | ), | |
258 | ); | |
259 | ||
260 | $this->_options = array( | |
9d72cede EM |
261 | 'my_cases' => array( |
262 | 'title' => ts('My Cases'), | |
6a488035 TO |
263 | 'type' => 'checkbox', |
264 | ), | |
265 | ); | |
266 | parent::__construct(); | |
267 | } | |
268 | ||
269 | function preProcess() { | |
270 | parent::preProcess(); | |
271 | } | |
272 | ||
273 | function buildQuickForm() { | |
274 | parent::buildQuickForm(); | |
275 | $this->caseDetailSpecialColumnsAdd(); | |
276 | } | |
277 | ||
278 | function caseDetailSpecialColumnsAdd() { | |
279 | $elements = array(); | |
280 | $elements[] = &$this->createElement('select', 'case_activity_all_dates', NULL, | |
281 | array( | |
9d72cede EM |
282 | '' => ts('- select -') |
283 | ) + $this->caseActivityTypes | |
6a488035 TO |
284 | ); |
285 | $this->addGroup($elements, 'case_detail_extra'); | |
286 | ||
9d72cede EM |
287 | $this->_caseDetailExtra = array( |
288 | 'case_activity_all_dates' => array( | |
289 | 'title' => ts('List of all dates of activities of Type'), | |
6a488035 TO |
290 | 'name' => 'activity_date_time', |
291 | ), | |
292 | ); | |
293 | ||
294 | $this->assign('caseDetailExtra', $this->_caseDetailExtra); | |
295 | } | |
296 | ||
297 | function select() { | |
298 | $select = array(); | |
299 | $this->_columnHeaders = array(); | |
300 | foreach ($this->_columns as $tableName => $table) { | |
301 | if (array_key_exists('fields', $table)) { | |
302 | foreach ($table['fields'] as $fieldName => $field) { | |
303 | if ($tableName == 'civicrm_address') { | |
304 | $this->_addressField = TRUE; | |
305 | } | |
9d72cede EM |
306 | if (!empty($field['required']) || |
307 | !empty($this->_params['fields'][$fieldName]) | |
308 | ) { | |
6a488035 TO |
309 | if ($tableName == 'civicrm_email') { |
310 | $this->_emailField = TRUE; | |
311 | } | |
312 | elseif ($tableName == 'civicrm_phone') { | |
313 | $this->_phoneField = TRUE; | |
314 | } | |
315 | elseif ($tableName == 'civicrm_relationship') { | |
316 | $this->_relField = TRUE; | |
317 | } | |
318 | if ($fieldName == 'sort_name') { | |
2f4c2f5d | 319 | $select[] = "GROUP_CONCAT({$field['dbAlias']} ORDER BY {$field['dbAlias']} ) |
6a488035 TO |
320 | as {$tableName}_{$fieldName}"; |
321 | } | |
322 | if ($tableName == 'civicrm_activity_last_completed') { | |
323 | $this->_activityLastCompleted = TRUE; | |
324 | } | |
325 | ||
326 | if ($fieldName == 'case_role') { | |
327 | $select[] = "GROUP_CONCAT(DISTINCT({$field['dbAlias']}) ORDER BY {$field['dbAlias']}) as {$tableName}_{$fieldName}"; | |
328 | } | |
329 | else { | |
330 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
331 | } | |
332 | ||
333 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
334 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
335 | } | |
336 | } | |
337 | } | |
338 | } | |
339 | ||
340 | $this->_select = 'SELECT ' . implode(', ', $select) . ' '; | |
341 | } | |
342 | ||
343 | function from() { | |
344 | ||
345 | $case = $this->_aliases['civicrm_case']; | |
346 | $conact = $this->_aliases['civicrm_contact']; | |
347 | ||
348 | $this->_from = " | |
349 | FROM civicrm_case $case | |
350 | LEFT JOIN civicrm_case_contact civireport_case_contact on civireport_case_contact.case_id = {$case}.id | |
351 | LEFT JOIN civicrm_contact $conact ON {$conact}.id = civireport_case_contact.contact_id | |
352 | "; | |
353 | if ($this->_relField) { | |
354 | $this->_from .= " | |
355 | LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']} ON {$this->_aliases['civicrm_relationship']}.case_id = {$case}.id | |
356 | "; | |
357 | } | |
358 | ||
359 | if ($this->_addressField) { | |
360 | $this->_from .= " | |
2f4c2f5d | 361 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} |
362 | ON {$conact}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
6a488035 TO |
363 | {$this->_aliases['civicrm_address']}.is_primary = 1 "; |
364 | } | |
365 | if ($this->_emailField) { | |
2f4c2f5d | 366 | $this->_from .= " |
367 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} | |
368 | ON {$conact}.id = {$this->_aliases['civicrm_email']}.contact_id AND | |
6a488035 TO |
369 | {$this->_aliases['civicrm_email']}.is_primary = 1 "; |
370 | } | |
371 | if ($this->_phoneField) { | |
372 | $this->_from .= " | |
2f4c2f5d | 373 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
374 | ON ( {$conact}.id = {$this->_aliases['civicrm_phone']}.contact_id AND | |
6a488035 TO |
375 | {$this->_aliases['civicrm_phone']}.is_primary = 1) "; |
376 | } | |
377 | if ($this->_worldRegionField) { | |
378 | $this->_from .= " | |
379 | LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']} | |
380 | ON {$this->_aliases['civicrm_country']}.id ={$this->_aliases['civicrm_address']}.country_id | |
381 | LEFT JOIN civicrm_worldregion {$this->_aliases['civicrm_worldregion']} | |
382 | ON {$this->_aliases['civicrm_country']}.region_id = {$this->_aliases['civicrm_worldregion']}.id "; | |
383 | } | |
384 | ||
385 | // Include clause for last activity of the case | |
386 | if ($this->_activityLast) { | |
387 | $this->_from .= " LEFT JOIN civicrm_activity {$this->_aliases['civicrm_activity_last']} ON ( {$this->_aliases['civicrm_activity_last']}.id = ( SELECT max(activity_id) FROM civicrm_case_activity WHERE case_id = {$case}.id) )"; | |
388 | } | |
389 | ||
390 | // Include clause for last completed activity of the case | |
391 | if ($this->_activityLastCompleted) { | |
392 | $this->_from .= " LEFT JOIN civicrm_activity {$this->_aliases['civicrm_activity_last_completed']} ON ( {$this->_aliases['civicrm_activity_last_completed']}.id = ( SELECT max(activity_id) FROM civicrm_case_activity cca, civicrm_activity ca WHERE ca.id = cca.activity_id AND cca.case_id = {$case}.id AND ca.status_id = 2 ) )"; | |
393 | } | |
394 | } | |
395 | ||
396 | function where() { | |
397 | $clauses = array(); | |
398 | $this->_having = ''; | |
399 | foreach ($this->_columns as $tableName => $table) { | |
400 | if (array_key_exists('filters', $table)) { | |
401 | foreach ($table['filters'] as $fieldName => $field) { | |
402 | $clause = NULL; | |
403 | ||
404 | if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { | |
405 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
9d72cede EM |
406 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
407 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 TO |
408 | |
409 | $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type']); | |
410 | } | |
411 | else { | |
412 | ||
413 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
9d72cede EM |
414 | if ($fieldName == 'case_type_id' && |
415 | !empty($this->_params['case_type_id_value']) | |
416 | ) { | |
6a488035 TO |
417 | foreach ($this->_params['case_type_id_value'] as $key => $value) { |
418 | if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) === FALSE) { | |
9d72cede EM |
419 | $value = CRM_Core_DAO::VALUE_SEPARATOR . $value . |
420 | CRM_Core_DAO::VALUE_SEPARATOR; | |
6a488035 TO |
421 | |
422 | $this->_params['case_type_id_value'][$key] = "'{$value}'"; | |
423 | } | |
424 | else { | |
425 | $this->_params['case_type_id_value'][$key] = $value; | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
430 | if ($op) { | |
431 | $clause = $this->whereClause($field, | |
432 | $op, | |
433 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
434 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
435 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
436 | ); | |
437 | } | |
438 | } | |
439 | ||
440 | if (!empty($clause)) { | |
441 | $clauses[] = $clause; | |
442 | } | |
443 | } | |
444 | } | |
445 | } | |
446 | ||
447 | if (isset($this->_params['options']['my_cases'])) { | |
9d72cede EM |
448 | $session = CRM_Core_Session::singleton(); |
449 | $userID = $session->get('userID'); | |
6a488035 TO |
450 | $clauses[] = "{$this->_aliases['civicrm_contact']}.id = {$userID}"; |
451 | } | |
452 | ||
453 | if (empty($clauses)) { | |
454 | $this->_where = 'WHERE ( 1 ) '; | |
455 | } | |
456 | else { | |
457 | $this->_where = 'WHERE ' . implode(' AND ', $clauses); | |
458 | } | |
459 | } | |
460 | ||
461 | function groupBy() { | |
462 | $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_case']}.id"; | |
463 | } | |
464 | ||
74cf4551 EM |
465 | /** |
466 | * @param $rows | |
467 | * | |
468 | * @return array | |
469 | */ | |
6a488035 TO |
470 | function statistics(&$rows) { |
471 | $statistics = parent::statistics($rows); | |
472 | ||
9d72cede EM |
473 | $select = "select COUNT( DISTINCT( {$this->_aliases['civicrm_address']}.country_id))"; |
474 | $sql = "{$select} {$this->_from} {$this->_where}"; | |
6a488035 TO |
475 | $countryCount = CRM_Core_DAO::singleValueQuery($sql); |
476 | ||
477 | //CaseType statistics | |
478 | if (array_key_exists('filters', $statistics)) { | |
479 | foreach ($statistics['filters'] as $id => $value) { | |
480 | if ($value['title'] == 'Case Type') { | |
9d72cede EM |
481 | $statistics['filters'][$id]['value'] = 'Is ' . |
482 | $this->case_types[substr($statistics['filters'][$id] | |
483 | ['value'], -3, -2 | |
484 | )]; | |
6a488035 TO |
485 | } |
486 | } | |
487 | } | |
488 | $statistics['counts']['case'] = array( | |
489 | 'title' => ts('Total Number of Cases '), | |
490 | 'value' => isset($statistics['counts']['rowsFound']) ? $statistics['counts']['rowsFound']['value'] : count($rows), | |
491 | ); | |
492 | $statistics['counts']['country'] = array( | |
493 | 'title' => ts('Total Number of Countries '), | |
494 | 'value' => $countryCount, | |
495 | ); | |
496 | ||
497 | return $statistics; | |
498 | } | |
499 | ||
500 | function orderBy() { | |
501 | $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_case']}.start_date DESC "; | |
502 | } | |
503 | ||
504 | function caseDetailSpecialColumnProcess() { | |
505 | if (!$this->_includeCaseDetailExtra) { | |
506 | return; | |
507 | } | |
508 | ||
509 | $from = $select = array(); | |
510 | $case = $this->_aliases['civicrm_case']; | |
511 | ||
512 | if ($activityType = CRM_Utils_Array::value('case_activity_all_dates', $this->_params['case_detail_extra'])) { | |
513 | $select[] = "GROUP_CONCAT(DISTINCT(civireport_activity_all_{$activityType}.{$this->_caseDetailExtra['case_activity_all_dates']['name']}) ORDER BY civireport_activity_all_{$activityType}.{$this->_caseDetailExtra['case_activity_all_dates']['name']}) as case_activity_all_dates"; | |
514 | ||
2f4c2f5d | 515 | $from[] = " LEFT JOIN civicrm_case_activity civireport_case_activity_all_{$activityType} ON ( civireport_case_activity_all_{$activityType}.case_id = {$case}.id) |
6a488035 TO |
516 | LEFT JOIN civicrm_activity civireport_activity_all_{$activityType} ON ( civireport_activity_all_{$activityType}.id = civireport_case_activity_all_{$activityType}.activity_id AND civireport_activity_all_{$activityType}.activity_type_id = {$activityType})"; |
517 | ||
518 | $this->_columnHeaders['case_activity_all_dates'] = array( | |
9d72cede EM |
519 | 'title' => $this->_caseDetailExtra['case_activity_all_dates']['title'] . |
520 | ": {$this->caseActivityTypes[$activityType]}", | |
6a488035 TO |
521 | 'type' => CRM_Utils_Array::value('type', $this->_caseDetailExtra['case_activity_all_dates']), |
522 | ); | |
523 | } | |
524 | ||
525 | $this->_select .= ', ' . implode(', ', $select) . ' '; | |
526 | $this->_from .= ' ' . implode(' ', $from) . ' '; | |
527 | } | |
528 | ||
529 | function postProcess() { | |
530 | ||
531 | $this->beginPostProcess(); | |
532 | ||
533 | $this->checkEnabledFields(); | |
534 | ||
535 | $this->buildQuery(TRUE); | |
536 | ||
537 | $this->caseDetailSpecialColumnProcess(); | |
538 | ||
539 | $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}"; | |
540 | ||
541 | $rows = $graphRows = array(); | |
542 | $this->buildRows($sql, $rows); | |
543 | ||
544 | $this->formatDisplay($rows); | |
545 | ||
546 | $this->doTemplateAssignment($rows); | |
547 | $this->endPostProcess($rows); | |
548 | } | |
549 | ||
550 | function checkEnabledFields() { | |
9d72cede EM |
551 | if (isset($this->_params['worldregion_id_value']) && |
552 | !empty($this->_params['worldregion_id_value']) | |
553 | ) { | |
6a488035 TO |
554 | $this->_addressField = TRUE; |
555 | $this->_worldRegionField = TRUE; | |
556 | } | |
557 | ||
558 | if (isset($this->_params['case_role_value']) | |
559 | && !empty($this->_params['case_role_value']) | |
560 | ) { | |
561 | $this->_relField = TRUE; | |
562 | } | |
563 | ||
9d72cede EM |
564 | if (!empty($this->_params['activity_date_time_relative']) || |
565 | !empty($this->_params['activity_date_time_from']) || | |
6a488035 TO |
566 | CRM_Utils_Array::value('activity_date_time_to', $this->_params) |
567 | ) { | |
568 | $this->_activityLast = TRUE; | |
569 | } | |
570 | ||
571 | foreach (array_keys($this->_caseDetailExtra) as $field) { | |
a7488080 | 572 | if (!empty($this->_params['case_detail_extra'][$field])) { |
6a488035 TO |
573 | $this->_includeCaseDetailExtra = TRUE; |
574 | break; | |
575 | } | |
576 | } | |
577 | } | |
578 | ||
74cf4551 EM |
579 | /** |
580 | * @param $rows | |
581 | */ | |
6a488035 TO |
582 | function alterDisplay(&$rows) { |
583 | $entryFound = FALSE; | |
584 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); | |
585 | ||
586 | foreach ($rows as $rowNum => $row) { | |
587 | if (array_key_exists('civicrm_case_status_id', $row)) { | |
588 | if ($value = $row['civicrm_case_status_id']) { | |
589 | $rows[$rowNum]['civicrm_case_status_id'] = $this->case_statuses[$value]; | |
590 | ||
591 | $entryFound = TRUE; | |
592 | } | |
593 | } | |
594 | if (array_key_exists('civicrm_case_case_type_id', $row)) { | |
595 | if ($value = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $row['civicrm_case_case_type_id'])) { | |
596 | $rows[$rowNum]['civicrm_case_case_type_id'] = $this->case_types[$value]; | |
597 | ||
598 | $entryFound = TRUE; | |
599 | } | |
600 | } | |
601 | if (array_key_exists('civicrm_case_subject', $row)) { | |
602 | if ($value = $row['civicrm_case_subject']) { | |
76bec9f7 CW |
603 | $url = CRM_Utils_System::url("civicrm/case/ajax/details", |
604 | "caseId={$row['civicrm_case_id']}&contactId={$row['civicrm_contact_id']}", | |
605 | $this->_absoluteUrl | |
606 | ); | |
607 | $rows[$rowNum]['civicrm_case_subject'] = "<a class=\"crm-popup\" href=\"$url\">$value</a>"; | |
6a488035 TO |
608 | $rows[$rowNum]['civicrm_case_subject_hover'] = ts('View Details of Case.'); |
609 | ||
610 | $entryFound = TRUE; | |
611 | } | |
612 | } | |
613 | if (array_key_exists('civicrm_relationship_case_role', $row)) { | |
614 | if ($value = $row['civicrm_relationship_case_role']) { | |
615 | $caseRoles = explode(',', $value); | |
616 | foreach ($caseRoles as $num => $caseRole) { | |
617 | $caseRoles[$num] = $this->rel_types[$caseRole]; | |
618 | } | |
619 | $rows[$rowNum]['civicrm_relationship_case_role'] = implode('; ', $caseRoles); | |
620 | } | |
621 | $entryFound = TRUE; | |
622 | } | |
623 | if (array_key_exists('civicrm_address_country_id', $row)) { | |
624 | if ($value = $row['civicrm_address_country_id']) { | |
625 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); | |
626 | } | |
627 | $entryFound = TRUE; | |
628 | } | |
629 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
630 | if ($value = $row['civicrm_address_state_province_id']) { | |
631 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); | |
632 | } | |
633 | $entryFound = TRUE; | |
634 | } | |
9d72cede EM |
635 | if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_subject', $row) && |
636 | empty($row['civicrm_activity_last_completed_last_completed_activity_subject']) | |
637 | ) { | |
2f186e81 | 638 | $rows[$rowNum]['civicrm_activity_last_completed_last_completed_activity_subject'] = ts('(no subject)'); |
6a488035 TO |
639 | $entryFound = TRUE; |
640 | } | |
641 | if (array_key_exists('civicrm_contact_client_sort_name', $row) && | |
642 | array_key_exists('civicrm_contact_id', $row) | |
643 | ) { | |
644 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
645 | 'reset=1&cid=' . $row['civicrm_contact_id'], | |
646 | $this->_absoluteUrl | |
647 | ); | |
648 | $rows[$rowNum]['civicrm_contact_client_sort_name_link'] = $url; | |
649 | $rows[$rowNum]['civicrm_contact_client_sort_name_hover'] = ts("View Contact Summary for this Contact"); | |
650 | $entryFound = TRUE; | |
651 | } | |
652 | if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_type', $row)) { | |
653 | if ($value = $row['civicrm_activity_last_completed_last_completed_activity_type']) { | |
654 | $rows[$rowNum]['civicrm_activity_last_completed_last_completed_activity_type'] = $activityTypes[$value]; | |
655 | } | |
656 | $entryFound = TRUE; | |
657 | } | |
658 | ||
659 | if (array_key_exists('case_activity_all_dates', $row)) { | |
660 | if ($value = $row['case_activity_all_dates']) { | |
661 | $activityDates = explode(',', $value); | |
662 | foreach ($activityDates as $num => $activityDate) { | |
663 | $activityDates[$num] = CRM_Utils_Date::customFormat($activityDate); | |
664 | } | |
665 | $rows[$rowNum]['case_activity_all_dates'] = implode('; ', $activityDates); | |
666 | } | |
667 | $entryFound = TRUE; | |
668 | } | |
669 | ||
a31b650c RN |
670 | if (array_key_exists('civicrm_case_is_deleted', $row)) { |
671 | $value = $row['civicrm_case_is_deleted']; | |
672 | $rows[$rowNum]['civicrm_case_is_deleted'] = $this->deleted_labels[$value]; | |
673 | $entryFound = TRUE; | |
674 | } | |
675 | ||
6a488035 TO |
676 | if (!$entryFound) { |
677 | break; | |
678 | } | |
679 | } | |
680 | } | |
681 | } | |
682 |