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