Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
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 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates view mode for CiviCase. |
6a488035 TO |
36 | */ |
37 | class CRM_Case_Form_CaseView extends CRM_Core_Form { | |
c490a46a | 38 | /** |
100fef9d | 39 | * Check for merge cases. |
c490a46a CW |
40 | * @var bool |
41 | */ | |
6a488035 TO |
42 | private $_mergeCases = FALSE; |
43 | ||
44 | /** | |
fe482240 | 45 | * Set variables up before form is built. |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
0ee2ad76 | 48 | $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET); |
6a488035 TO |
49 | |
50 | $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); | |
51 | $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); | |
52 | $this->assign('multiClient', $isMultiClient); | |
53 | ||
54 | //pull the related cases. | |
55 | $this->assign('showRelatedCases', FALSE); | |
56 | if ($this->_showRelatedCases) { | |
57 | $relatedCases = $this->get('relatedCases'); | |
58 | if (!isset($relatedCases)) { | |
353ffa53 TO |
59 | $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); |
60 | $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject); | |
6a488035 TO |
61 | $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId); |
62 | } | |
63 | $this->assign('relatedCases', $relatedCases); | |
64 | $this->assign('showRelatedCases', TRUE); | |
5ffd5a35 | 65 | CRM_Utils_System::setTitle(ts('Related Cases')); |
6a488035 TO |
66 | return; |
67 | } | |
68 | ||
69 | //check for civicase access. | |
70 | if (!CRM_Case_BAO_Case::accessCiviCase()) { | |
71 | CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); | |
72 | } | |
73 | $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); | |
74 | $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases); | |
75 | ||
76 | $this->_contactID = $this->get('cid'); | |
77 | $this->_caseID = $this->get('id'); | |
78 | ||
79 | $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject); | |
80 | if ($fulltext == 'fulltext') { | |
81 | $this->assign('fulltext', $fulltext); | |
82 | } | |
83 | ||
84 | $this->assign('caseID', $this->_caseID); | |
85 | $this->assign('contactID', $this->_contactID); | |
86 | ||
87 | //validate case id. | |
88 | $this->_userCases = array(); | |
353ffa53 TO |
89 | $session = CRM_Core_Session::singleton(); |
90 | $userID = $session->get('userID'); | |
6a488035 | 91 | if (!$this->_hasAccessToAllCases) { |
90319720 | 92 | $this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'any'); |
6a488035 TO |
93 | if (!array_key_exists($this->_caseID, $this->_userCases)) { |
94 | CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); | |
95 | } | |
96 | } | |
97 | $this->assign('userID', $userID); | |
98 | ||
99 | if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) { | |
100 | $this->_mergeCases = TRUE; | |
101 | } | |
102 | $this->assign('mergeCases', $this->_mergeCases); | |
103 | ||
104 | //retrieve details about case | |
105 | $params = array('id' => $this->_caseID); | |
106 | ||
107 | $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date'); | |
108 | CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties); | |
109 | ||
353ffa53 | 110 | $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); |
6a488035 | 111 | $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); |
353ffa53 | 112 | $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); |
6a488035 TO |
113 | |
114 | $this->_caseDetails = array( | |
115 | 'case_type' => $caseType, | |
dc047163 | 116 | 'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses), |
6a488035 TO |
117 | 'case_subject' => CRM_Utils_Array::value('subject', $values), |
118 | 'case_start_date' => $values['case_start_date'], | |
119 | ); | |
120 | $this->_caseType = $caseTypeName; | |
121 | $this->assign('caseDetails', $this->_caseDetails); | |
122 | ||
6a488035 TO |
123 | $reportUrl = CRM_Utils_System::url('civicrm/case/report', |
124 | "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", | |
125 | FALSE, NULL, FALSE | |
126 | ); | |
127 | $this->assign('reportUrl', $reportUrl); | |
128 | ||
129 | // add to recently viewed | |
130 | ||
131 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
132 | "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home" | |
133 | ); | |
134 | ||
135 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); | |
136 | $this->assign('displayName', $displayName); | |
137 | ||
b74958a4 | 138 | CRM_Utils_System::setTitle($displayName . ' - ' . $caseType); |
6a488035 TO |
139 | |
140 | $recentOther = array(); | |
141 | if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) { | |
142 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', | |
143 | "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home" | |
144 | ); | |
145 | } | |
146 | ||
b74958a4 | 147 | // Add the recently viewed case |
6a488035 TO |
148 | CRM_Utils_Recent::add($displayName . ' - ' . $caseType, |
149 | $url, | |
150 | $this->_caseID, | |
151 | 'Case', | |
152 | $this->_contactID, | |
153 | NULL, | |
154 | $recentOther | |
155 | ); | |
156 | ||
6a488035 TO |
157 | //get the related cases for given case. |
158 | $relatedCases = $this->get('relatedCases'); | |
159 | if (!isset($relatedCases)) { | |
160 | $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID); | |
161 | $relatedCases = empty($relatedCases) ? FALSE : $relatedCases; | |
162 | $this->set('relatedCases', $relatedCases); | |
163 | } | |
5ffd5a35 CW |
164 | $this->assign('hasRelatedCases', (bool) $relatedCases); |
165 | if ($relatedCases) { | |
353ffa53 TO |
166 | $this->assign('relatedCaseLabel', ts('%1 Related Case', array( |
167 | 'count' => count($relatedCases), | |
8d7a9d07 | 168 | 'plural' => '%1 Related Cases', |
353ffa53 | 169 | ))); |
5ffd5a35 CW |
170 | $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array( |
171 | 'id' => $this->_caseID, | |
172 | 'cid' => $this->_contactID, | |
173 | 'relatedCases' => 1, | |
174 | 'action' => 'view', | |
175 | ))); | |
176 | } | |
6a488035 | 177 | |
8ffdec17 | 178 | $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL; |
6a488035 TO |
179 | $this->assign('caseTypeID', $entitySubType); |
180 | $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Case', | |
181 | $this, | |
182 | $this->_caseID, | |
183 | NULL, | |
184 | $entitySubType | |
185 | ); | |
186 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, | |
187 | $groupTree | |
188 | ); | |
189 | } | |
190 | ||
191 | /** | |
3819f101 | 192 | * Set default values for the form. |
6a488035 | 193 | * |
3819f101 | 194 | * @return array; |
6a488035 | 195 | */ |
00be9182 | 196 | public function setDefaultValues() { |
6a488035 TO |
197 | $defaults = array(); |
198 | return $defaults; | |
199 | } | |
200 | ||
201 | /** | |
fe482240 | 202 | * Build the form object. |
6a488035 TO |
203 | */ |
204 | public function buildQuickForm() { | |
205 | //this call is for show related cases. | |
206 | if ($this->_showRelatedCases) { | |
207 | return; | |
208 | } | |
209 | ||
5ffd5a35 | 210 | CRM_Core_Resources::singleton() |
96ed17aa CW |
211 | ->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header') |
212 | ->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header'); | |
5ffd5a35 | 213 | |
6a488035 | 214 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); |
353ffa53 TO |
215 | $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); |
216 | $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); | |
6a488035 TO |
217 | |
218 | //adding case manager.CRM-4510. | |
219 | $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); | |
220 | if (!empty($managerRoleId)) { | |
221 | $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; | |
222 | } | |
223 | ||
224 | $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); | |
225 | ||
226 | $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); | |
227 | ||
5ffd5a35 | 228 | $emailActivityType = array_search('Email', $allActTypes); |
fd54c68d | 229 | $pdfActivityType = array_search('Print PDF Letter', $allActTypes); |
5ffd5a35 | 230 | |
6a488035 | 231 | // remove Open Case activity type since we're inside an existing case |
5ffd5a35 | 232 | if ($openActTypeId = array_search('Open Case', $allActTypes)) { |
6a488035 TO |
233 | unset($aTypes[$openActTypeId]); |
234 | } | |
235 | ||
236 | //check for link cases. | |
237 | $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); | |
5ffd5a35 | 238 | if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { |
6a488035 TO |
239 | unset($aTypes[$linkActTypeId]); |
240 | } | |
241 | ||
242 | if (!$xmlProcessor->getNaturalActivityTypeSort()) { | |
243 | asort($aTypes); | |
244 | } | |
245 | ||
5ffd5a35 CW |
246 | $activityLinks = array('' => ts('Add Activity')); |
247 | foreach ($aTypes as $type => $label) { | |
248 | if ($type == $emailActivityType) { | |
249 | $url = CRM_Utils_System::url('civicrm/activity/email/add', | |
250 | "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type", | |
251 | FALSE, NULL, FALSE | |
252 | ); | |
ed92d614 | 253 | } |
481a74f4 | 254 | elseif ($type == $pdfActivityType) { |
e547f744 | 255 | $url = CRM_Utils_System::url('civicrm/activity/pdf/add', |
fd54c68d | 256 | "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type", |
481a74f4 | 257 | FALSE, NULL, FALSE); |
5e54ab6c | 258 | } |
5ffd5a35 CW |
259 | else { |
260 | $url = CRM_Utils_System::url('civicrm/case/activity', | |
261 | "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type", | |
262 | FALSE, NULL, FALSE | |
263 | ); | |
264 | } | |
265 | $activityLinks[$url] = $label; | |
266 | } | |
267 | ||
941539e7 | 268 | $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty')); |
6a488035 | 269 | if ($this->_hasAccessToAllCases) { |
2a06342c | 270 | $this->add('select', 'report_id', '', |
f7737fc0 | 271 | array('' => ts('Activity Audit')) + $reports, |
2a06342c | 272 | FALSE, |
941539e7 | 273 | array('class' => 'crm-select2 crm-action-menu action-icon-clipboard') |
6a488035 | 274 | ); |
2a06342c CW |
275 | $this->add('select', 'timeline_id', '', |
276 | array('' => ts('Add Timeline')) + $reports, | |
277 | FALSE, | |
941539e7 | 278 | array('class' => 'crm-select2 crm-action-menu action-icon-play') |
6a488035 TO |
279 | ); |
280 | } | |
2a06342c | 281 | $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); |
6a488035 TO |
282 | |
283 | if ($this->_mergeCases) { | |
284 | $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); | |
285 | $otherCases = array(); | |
286 | foreach ($allCases as $caseId => $details) { | |
287 | //filter current and own cases. | |
288 | if (($caseId == $this->_caseID) || | |
289 | (!$this->_hasAccessToAllCases && | |
290 | !array_key_exists($caseId, $this->_userCases) | |
291 | ) | |
292 | ) { | |
293 | continue; | |
294 | } | |
295 | ||
296 | $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; | |
297 | } | |
298 | if (empty($otherCases)) { | |
299 | $this->_mergeCases = FALSE; | |
300 | $this->assign('mergeCases', $this->_mergeCases); | |
301 | } | |
302 | else { | |
303 | $this->add('select', 'merge_case_id', | |
304 | ts('Select Case for Merge'), | |
305 | array( | |
8d7a9d07 | 306 | '' => ts('- select case -'), |
353ffa53 | 307 | ) + $otherCases, |
2a06342c CW |
308 | FALSE, |
309 | array('class' => 'crm-select2 huge') | |
6a488035 TO |
310 | ); |
311 | $this->addElement('submit', | |
312 | $this->getButtonName('next', 'merge_case'), | |
313 | ts('Merge'), | |
314 | array( | |
d731c8c6 | 315 | 'class' => 'hiddenElement', |
6a488035 TO |
316 | ) |
317 | ); | |
318 | } | |
319 | } | |
320 | ||
fc7d8951 | 321 | //call activity form |
504f0f9c | 322 | self::activityForm($this, $aTypes); |
6a488035 TO |
323 | |
324 | //get case related relationships (Case Role) | |
325 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); | |
326 | ||
327 | //save special label because we unset it in the loop | |
328 | $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; | |
329 | ||
6a488035 | 330 | foreach ($caseRelationships as $key => & $value) { |
6a488035 TO |
331 | if (!empty($managerRoleId)) { |
332 | if ($managerRoleId == $value['relation_type']) { | |
333 | $value['relation'] = $managerLabel; | |
334 | } | |
335 | } | |
336 | ||
337 | //calculate roles that don't have relationships | |
a7488080 | 338 | if (!empty($caseRoles[$value['relation_type']])) { |
6a488035 TO |
339 | unset($caseRoles[$value['relation_type']]); |
340 | } | |
341 | } | |
342 | ||
6a488035 TO |
343 | $this->assign('caseRelationships', $caseRelationships); |
344 | ||
345 | //also add client as role. CRM-4438 | |
346 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); | |
347 | ||
348 | $this->assign('caseRoles', $caseRoles); | |
349 | ||
6a488035 TO |
350 | // Retrieve ALL client relationships |
351 | $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, | |
352 | CRM_Contact_BAO_Relationship::CURRENT, | |
353 | 0, 0, 0, NULL, NULL, FALSE | |
354 | ); | |
355 | ||
356 | // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles | |
357 | // so they don't show up twice. | |
358 | $clientRelationships = array(); | |
359 | foreach ($relClient as $r) { | |
360 | if (!array_key_exists($r['id'], $caseRelationships)) { | |
361 | $clientRelationships[] = $r; | |
362 | } | |
363 | } | |
364 | $this->assign('clientRelationships', $clientRelationships); | |
365 | ||
366 | // Now global contact list that appears on all cases. | |
367 | $globalGroupInfo = array(); | |
d79c94d5 | 368 | CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); |
6a488035 TO |
369 | $this->assign('globalGroupInfo', $globalGroupInfo); |
370 | ||
371 | // List of relationship types | |
353ffa53 TO |
372 | $baoRel = new CRM_Contact_BAO_Relationship(); |
373 | $relType = $baoRel->getRelationType('Individual'); | |
6a488035 TO |
374 | $roleTypes = array(); |
375 | foreach ($relType as $k => $v) { | |
376 | $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; | |
377 | } | |
c91df8b4 | 378 | $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty')); |
6a488035 TO |
379 | |
380 | $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); | |
381 | if (is_array($hookCaseSummary)) { | |
382 | $this->assign('hookCaseSummary', $hookCaseSummary); | |
383 | } | |
384 | ||
6c6c5975 | 385 | CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL, |
386 | ' ', TRUE); | |
6a488035 TO |
387 | |
388 | if (!empty($allTags)) { | |
389 | $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, | |
ab345ca5 | 390 | array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
391 | ); |
392 | ||
393 | $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); | |
394 | ||
395 | $this->setDefaults(array('case_tag' => $tags)); | |
396 | ||
397 | foreach ($tags as $tid) { | |
6fd5424b | 398 | if (isset($allTags[$tid])) { |
399 | $tags[$tid] = $allTags[$tid]; | |
400 | } | |
401 | else { | |
402 | unset($tags[$tid]); | |
403 | } | |
6a488035 TO |
404 | } |
405 | ||
406 | $this->assign('tags', implode(', ', array_filter($tags))); | |
407 | $this->assign('showTags', TRUE); | |
408 | } | |
409 | else { | |
410 | $this->assign('showTags', FALSE); | |
411 | } | |
412 | ||
413 | // build tagset widget | |
414 | ||
415 | // see if we have any tagsets which can be assigned to cases | |
416 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); | |
417 | if ($parentNames) { | |
418 | $this->assign('showTagsets', TRUE); | |
419 | } | |
420 | else { | |
421 | $this->assign('showTagsets', FALSE); | |
422 | } | |
95ef220a | 423 | CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); |
6a488035 TO |
424 | |
425 | $this->addButtons(array( | |
426 | array( | |
427 | 'type' => 'cancel', | |
428 | 'name' => ts('Done'), | |
429 | 'spacing' => ' ', | |
430 | 'isDefault' => TRUE, | |
431 | ), | |
432 | ) | |
433 | ); | |
434 | } | |
435 | ||
436 | /** | |
fe482240 | 437 | * Process the form. |
6a488035 TO |
438 | */ |
439 | public function postProcess() { | |
440 | $params = $this->controller->exportValues($this->_name); | |
441 | $buttonName = $this->controller->getButtonName(); | |
442 | ||
443 | // user context | |
444 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
445 | "reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1" | |
446 | ); | |
447 | $session = CRM_Core_Session::singleton(); | |
448 | $session->pushUserContext($url); | |
449 | ||
8cc574cf | 450 | if (!empty($params['timeline_id']) && !empty($_POST['_qf_CaseView_next'])) { |
353ffa53 TO |
451 | $session = CRM_Core_Session::singleton(); |
452 | $this->_uid = $session->get('userID'); | |
453 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); | |
6a488035 TO |
454 | $xmlProcessorParams = array( |
455 | 'clientID' => $this->_contactID, | |
456 | 'creatorID' => $this->_uid, | |
457 | 'standardTimeline' => 0, | |
458 | 'activity_date_time' => date('YmdHis'), | |
459 | 'caseID' => $this->_caseID, | |
460 | 'caseType' => $this->_caseType, | |
461 | 'activitySetName' => $params['timeline_id'], | |
462 | ); | |
463 | $xmlProcessor->run($this->_caseType, $xmlProcessorParams); | |
464 | $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); | |
465 | ||
466 | CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.', | |
353ffa53 | 467 | array(1 => $reports[$params['timeline_id']]) |
6a488035 TO |
468 | ), ts('Done'), 'success'); |
469 | } | |
470 | elseif ($this->_mergeCases && | |
471 | $buttonName == '_qf_CaseView_next_merge_case' | |
472 | ) { | |
473 | ||
474 | $mainCaseId = $params['merge_case_id']; | |
475 | $otherCaseId = $this->_caseID; | |
476 | ||
477 | //merge two cases. | |
478 | CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId); | |
479 | ||
480 | //redirect user to main case view. | |
481 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
482 | "reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1" | |
483 | ); | |
484 | $session = CRM_Core_Session::singleton(); | |
485 | $session->pushUserContext($url); | |
486 | } | |
6a488035 | 487 | } |
85859f88 CW |
488 | |
489 | /** | |
490 | * Build the activity selector/datatable | |
491 | * @param CRM_Core_Form $form | |
64bd5a0e TO |
492 | * @param array $aTypes |
493 | * To include acivities related to current case id $form->_caseID. | |
85859f88 | 494 | */ |
00be9182 | 495 | public static function activityForm($form, $aTypes = array()) { |
85859f88 CW |
496 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID); |
497 | //build reporter select | |
498 | $reporters = array("" => ts(' - any reporter - ')); | |
499 | foreach ($caseRelationships as $key => & $value) { | |
500 | $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; | |
501 | } | |
92fcb95f | 502 | $form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, array('id' => 'reporter_id_' . $form->_caseID)); |
85859f88 CW |
503 | |
504 | // take all case activity types for search filter, CRM-7187 | |
505 | $aTypesFilter = array(); | |
506 | $allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType(); | |
507 | foreach ($allCaseActTypes as $typeDetails) { | |
508 | if (!in_array($typeDetails['name'], array('Open Case'))) { | |
509 | $aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails); | |
510 | } | |
511 | } | |
504f0f9c | 512 | $aTypesFilter = $aTypesFilter + $aTypes; |
85859f88 | 513 | asort($aTypesFilter); |
92fcb95f | 514 | $form->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter, FALSE, array('id' => 'activity_type_filter_id_' . $form->_caseID)); |
85859f88 CW |
515 | |
516 | $activityStatus = CRM_Core_PseudoConstant::activityStatus(); | |
92fcb95f | 517 | $form->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus, FALSE, array('id' => 'status_id_' . $form->_caseID)); |
85859f88 CW |
518 | |
519 | // activity dates | |
92fcb95f TO |
520 | $form->addDate('activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), FALSE, array('formatType' => 'searchDate')); |
521 | $form->addDate('activity_date_high_' . $form->_caseID, ts('To'), FALSE, array('formatType' => 'searchDate')); | |
85859f88 CW |
522 | |
523 | if (CRM_Core_Permission::check('administer CiviCRM')) { | |
92fcb95f | 524 | $form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, array('id' => 'activity_deleted_' . $form->_caseID)); |
85859f88 CW |
525 | } |
526 | } | |
96025800 | 527 | |
ed92d614 | 528 | } |