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