| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
| 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-2020 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * This class is used to retrieve and display a range of contacts that match the given criteria. |
| 36 | */ |
| 37 | class CRM_Case_Selector_Search extends CRM_Core_Selector_Base { |
| 38 | |
| 39 | /** |
| 40 | * This defines two actions- View and Edit. |
| 41 | * |
| 42 | * @var array |
| 43 | */ |
| 44 | public static $_links = NULL; |
| 45 | |
| 46 | /** |
| 47 | * The action links that we need to display for the browse screen. |
| 48 | * |
| 49 | * @var array |
| 50 | */ |
| 51 | private static $_actionLinks; |
| 52 | |
| 53 | /** |
| 54 | * We use desc to remind us what that column is, name is used in the tpl |
| 55 | * |
| 56 | * @var array |
| 57 | */ |
| 58 | public static $_columnHeaders; |
| 59 | |
| 60 | /** |
| 61 | * Properties of contact we're interested in displaying |
| 62 | * @var array |
| 63 | */ |
| 64 | public static $_properties = [ |
| 65 | 'contact_id', |
| 66 | 'contact_type', |
| 67 | 'sort_name', |
| 68 | 'display_name', |
| 69 | 'case_id', |
| 70 | 'case_subject', |
| 71 | 'case_status_id', |
| 72 | 'case_status', |
| 73 | 'case_type_id', |
| 74 | 'case_type', |
| 75 | 'case_role', |
| 76 | 'phone', |
| 77 | ]; |
| 78 | |
| 79 | /** |
| 80 | * Are we restricting ourselves to a single contact |
| 81 | * |
| 82 | * @var bool |
| 83 | */ |
| 84 | protected $_single = FALSE; |
| 85 | |
| 86 | /** |
| 87 | * Are we restricting ourselves to a single contact |
| 88 | * |
| 89 | * @var bool |
| 90 | */ |
| 91 | protected $_limit = NULL; |
| 92 | |
| 93 | /** |
| 94 | * What context are we being invoked from |
| 95 | * |
| 96 | * @var string |
| 97 | */ |
| 98 | protected $_context = NULL; |
| 99 | |
| 100 | /** |
| 101 | * QueryParams is the array returned by exportValues called on |
| 102 | * the HTML_QuickForm_Controller for that page. |
| 103 | * |
| 104 | * @var array |
| 105 | */ |
| 106 | public $_queryParams; |
| 107 | |
| 108 | /** |
| 109 | * Represent the type of selector |
| 110 | * |
| 111 | * @var int |
| 112 | */ |
| 113 | protected $_action; |
| 114 | |
| 115 | /** |
| 116 | * The additional clause that we restrict the search with |
| 117 | * |
| 118 | * @var string |
| 119 | */ |
| 120 | protected $_additionalClause = NULL; |
| 121 | |
| 122 | /** |
| 123 | * The query object |
| 124 | * |
| 125 | * @var string |
| 126 | */ |
| 127 | protected $_query; |
| 128 | |
| 129 | /** |
| 130 | * Class constructor. |
| 131 | * |
| 132 | * @param array $queryParams |
| 133 | * Array of parameters for query. |
| 134 | * @param \const|int $action - action of search basic or advanced. |
| 135 | * @param string $additionalClause |
| 136 | * If the caller wants to further restrict the search (used in participations). |
| 137 | * @param bool $single |
| 138 | * Are we dealing only with one contact?. |
| 139 | * @param int $limit |
| 140 | * How many signers do we want returned. |
| 141 | * |
| 142 | * @param string $context |
| 143 | * |
| 144 | * @return \CRM_Case_Selector_Search |
| 145 | */ |
| 146 | public function __construct( |
| 147 | &$queryParams, |
| 148 | $action = CRM_Core_Action::NONE, |
| 149 | $additionalClause = NULL, |
| 150 | $single = FALSE, |
| 151 | $limit = NULL, |
| 152 | $context = 'search' |
| 153 | ) { |
| 154 | // submitted form values |
| 155 | $this->_queryParams = &$queryParams; |
| 156 | |
| 157 | $this->_single = $single; |
| 158 | $this->_limit = $limit; |
| 159 | $this->_context = $context; |
| 160 | |
| 161 | $this->_additionalClause = $additionalClause; |
| 162 | |
| 163 | // type of selector |
| 164 | $this->_action = $action; |
| 165 | |
| 166 | $this->_query = new CRM_Contact_BAO_Query($this->_queryParams, |
| 167 | CRM_Case_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CASE, |
| 168 | FALSE |
| 169 | ), |
| 170 | NULL, FALSE, FALSE, |
| 171 | CRM_Contact_BAO_Query::MODE_CASE |
| 172 | ); |
| 173 | |
| 174 | $this->_query->_distinctComponentClause = " civicrm_case.id "; |
| 175 | $this->_query->_groupByComponentClause = " GROUP BY civicrm_case.id "; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * This method returns the links that are given for each search row. |
| 180 | * currently the links added for each row are |
| 181 | * |
| 182 | * - View |
| 183 | * - Edit |
| 184 | * |
| 185 | * @param bool $isDeleted |
| 186 | * @param null $key |
| 187 | * |
| 188 | * @return array |
| 189 | */ |
| 190 | public static function &links($isDeleted = FALSE, $key = NULL) { |
| 191 | $extraParams = ($key) ? "&key={$key}" : NULL; |
| 192 | |
| 193 | if ($isDeleted) { |
| 194 | self::$_links = [ |
| 195 | CRM_Core_Action::RENEW => [ |
| 196 | 'name' => ts('Restore'), |
| 197 | 'url' => 'civicrm/contact/view/case', |
| 198 | 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, |
| 199 | 'ref' => 'restore-case', |
| 200 | 'title' => ts('Restore Case'), |
| 201 | ], |
| 202 | ]; |
| 203 | } |
| 204 | else { |
| 205 | self::$_links = [ |
| 206 | CRM_Core_Action::VIEW => [ |
| 207 | 'name' => ts('Manage'), |
| 208 | 'url' => 'civicrm/contact/view/case', |
| 209 | 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams, |
| 210 | 'ref' => 'manage-case', |
| 211 | 'class' => 'no-popup', |
| 212 | 'title' => ts('Manage Case'), |
| 213 | ], |
| 214 | CRM_Core_Action::DELETE => [ |
| 215 | 'name' => ts('Delete'), |
| 216 | 'url' => 'civicrm/contact/view/case', |
| 217 | 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, |
| 218 | 'ref' => 'delete-case', |
| 219 | 'title' => ts('Delete Case'), |
| 220 | ], |
| 221 | CRM_Core_Action::UPDATE => [ |
| 222 | 'name' => ts('Assign to Another Client'), |
| 223 | 'url' => 'civicrm/contact/view/case/editClient', |
| 224 | 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, |
| 225 | 'ref' => 'reassign', |
| 226 | 'class' => 'medium-popup', |
| 227 | 'title' => ts('Assign to Another Client'), |
| 228 | ], |
| 229 | ]; |
| 230 | } |
| 231 | |
| 232 | $actionLinks = []; |
| 233 | foreach (self::$_links as $key => $value) { |
| 234 | $actionLinks['primaryActions'][$key] = $value; |
| 235 | } |
| 236 | |
| 237 | return $actionLinks; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Getter for array of the parameters required for creating pager. |
| 242 | * |
| 243 | * @param $action |
| 244 | * @param array $params |
| 245 | */ |
| 246 | public function getPagerParams($action, &$params) { |
| 247 | $params['status'] = ts('Case') . ' %%StatusMessage%%'; |
| 248 | $params['csvString'] = NULL; |
| 249 | if ($this->_limit) { |
| 250 | $params['rowCount'] = $this->_limit; |
| 251 | } |
| 252 | else { |
| 253 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; |
| 254 | } |
| 255 | |
| 256 | $params['buttonTop'] = 'PagerTopButton'; |
| 257 | $params['buttonBottom'] = 'PagerBottomButton'; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Returns total number of rows for the query. |
| 262 | * |
| 263 | * @param |
| 264 | * |
| 265 | * @return int |
| 266 | * Total number of rows |
| 267 | */ |
| 268 | public function getTotalCount($action) { |
| 269 | return $this->_query->searchQuery(0, 0, NULL, |
| 270 | TRUE, FALSE, |
| 271 | FALSE, FALSE, |
| 272 | FALSE, |
| 273 | $this->_additionalClause |
| 274 | ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Returns all the rows in the given offset and rowCount. |
| 279 | * |
| 280 | * @param string $action |
| 281 | * The action being performed. |
| 282 | * @param int $offset |
| 283 | * The row number to start from. |
| 284 | * @param int $rowCount |
| 285 | * The number of rows to return. |
| 286 | * @param string $sort |
| 287 | * The sql string that describes the sort order. |
| 288 | * @param string $output |
| 289 | * What should the result set include (web/email/csv). |
| 290 | * |
| 291 | * @return int |
| 292 | * the total number of rows for this action |
| 293 | */ |
| 294 | public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { |
| 295 | $result = $this->_query->searchQuery($offset, $rowCount, $sort, |
| 296 | FALSE, FALSE, |
| 297 | FALSE, FALSE, |
| 298 | FALSE, |
| 299 | $this->_additionalClause |
| 300 | ); |
| 301 | // process the result of the query |
| 302 | $rows = []; |
| 303 | |
| 304 | //CRM-4418 check for view, edit, delete |
| 305 | $permissions = [CRM_Core_Permission::VIEW]; |
| 306 | if (CRM_Core_Permission::check('access all cases and activities') |
| 307 | || CRM_Core_Permission::check('access my cases and activities') |
| 308 | ) { |
| 309 | $permissions[] = CRM_Core_Permission::EDIT; |
| 310 | } |
| 311 | if (CRM_Core_Permission::check('delete in CiviCase')) { |
| 312 | $permissions[] = CRM_Core_Permission::DELETE; |
| 313 | } |
| 314 | $mask = CRM_Core_Action::mask($permissions); |
| 315 | |
| 316 | $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' "); |
| 317 | |
| 318 | $scheduledInfo = []; |
| 319 | |
| 320 | while ($result->fetch()) { |
| 321 | $row = []; |
| 322 | // the columns we are interested in |
| 323 | foreach (self::$_properties as $property) { |
| 324 | if (isset($result->$property)) { |
| 325 | $row[$property] = $result->$property; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | $isDeleted = FALSE; |
| 330 | if ($result->case_deleted) { |
| 331 | $isDeleted = TRUE; |
| 332 | $row['case_status_id'] = empty($row['case_status_id']) ? "" : $row['case_status_id'] . '<br />' . ts('(deleted)'); |
| 333 | } |
| 334 | |
| 335 | $scheduledInfo['case_id'][] = $result->case_id; |
| 336 | $scheduledInfo['contact_id'][] = $result->contact_id; |
| 337 | $scheduledInfo['case_deleted'] = $result->case_deleted; |
| 338 | $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->case_id; |
| 339 | |
| 340 | $links = self::links($isDeleted, $this->_key); |
| 341 | $row['action'] = CRM_Core_Action::formLink($links['primaryActions'], |
| 342 | $mask, [ |
| 343 | 'id' => $result->case_id, |
| 344 | 'cid' => $result->contact_id, |
| 345 | 'cxt' => $this->_context, |
| 346 | ], |
| 347 | ts('more'), |
| 348 | FALSE, |
| 349 | 'case.selector.actions', |
| 350 | 'Case', |
| 351 | $result->case_id |
| 352 | ); |
| 353 | |
| 354 | $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type |
| 355 | ); |
| 356 | |
| 357 | //adding case manager to case selector.CRM-4510. |
| 358 | $caseType = CRM_Case_BAO_Case::getCaseType($result->case_id, 'name'); |
| 359 | $row['casemanager'] = CRM_Case_BAO_Case::getCaseManagerContact($caseType, $result->case_id); |
| 360 | |
| 361 | if (isset($result->case_status_id) && |
| 362 | array_key_exists($result->case_status_id, $caseStatus) |
| 363 | ) { |
| 364 | $row['class'] = "status-urgent"; |
| 365 | } |
| 366 | else { |
| 367 | $row['class'] = "status-normal"; |
| 368 | } |
| 369 | |
| 370 | $rows[$result->case_id] = $row; |
| 371 | } |
| 372 | |
| 373 | //retrive the scheduled & recent Activity type and date for selector |
| 374 | if (!empty($scheduledInfo)) { |
| 375 | $schdeduledActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'upcoming'); |
| 376 | foreach ($schdeduledActivity as $key => $value) { |
| 377 | $rows[$key]['case_scheduled_activity_date'] = $value['date']; |
| 378 | $rows[$key]['case_scheduled_activity_type'] = $value['type']; |
| 379 | } |
| 380 | $recentActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'recent'); |
| 381 | foreach ($recentActivity as $key => $value) { |
| 382 | $rows[$key]['case_recent_activity_date'] = $value['date']; |
| 383 | $rows[$key]['case_recent_activity_type'] = $value['type']; |
| 384 | } |
| 385 | } |
| 386 | return $rows; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * @inheritDoc |
| 391 | */ |
| 392 | public function getQILL() { |
| 393 | return $this->_query->qill(); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Returns the column headers as an array of tuples: |
| 398 | * (name, sortName (key to the sort array)) |
| 399 | * |
| 400 | * @param string $action |
| 401 | * The action being performed. |
| 402 | * @param string $output |
| 403 | * What should the result set include (web/email/csv). |
| 404 | * |
| 405 | * @return array |
| 406 | * the column headers that need to be displayed |
| 407 | */ |
| 408 | public function &getColumnHeaders($action = NULL, $output = NULL) { |
| 409 | if (!isset(self::$_columnHeaders)) { |
| 410 | self::$_columnHeaders = [ |
| 411 | [ |
| 412 | 'name' => ts('Subject'), |
| 413 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 414 | ], |
| 415 | [ |
| 416 | 'name' => ts('Status'), |
| 417 | 'sort' => 'case_status', |
| 418 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 419 | ], |
| 420 | [ |
| 421 | 'name' => ts('Case Type'), |
| 422 | 'sort' => 'case_type', |
| 423 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 424 | ], |
| 425 | [ |
| 426 | 'name' => ts('My Role'), |
| 427 | 'sort' => 'case_role', |
| 428 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 429 | ], |
| 430 | [ |
| 431 | 'name' => ts('Case Manager'), |
| 432 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 433 | ], |
| 434 | [ |
| 435 | 'name' => ts('Most Recent'), |
| 436 | 'sort' => 'case_recent_activity_date', |
| 437 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 438 | ], |
| 439 | [ |
| 440 | 'name' => ts('Next Sched.'), |
| 441 | 'sort' => 'case_scheduled_activity_date', |
| 442 | 'direction' => CRM_Utils_Sort::DONTCARE, |
| 443 | ], |
| 444 | ['name' => ts('Actions')], |
| 445 | ]; |
| 446 | |
| 447 | if (!$this->_single) { |
| 448 | $pre = [ |
| 449 | [ |
| 450 | 'name' => ts('Client'), |
| 451 | 'sort' => 'sort_name', |
| 452 | 'direction' => CRM_Utils_Sort::ASCENDING, |
| 453 | ], |
| 454 | ]; |
| 455 | |
| 456 | self::$_columnHeaders = array_merge($pre, self::$_columnHeaders); |
| 457 | } |
| 458 | } |
| 459 | return self::$_columnHeaders; |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * @return mixed |
| 464 | */ |
| 465 | public function alphabetQuery() { |
| 466 | return $this->_query->alphabetQuery(); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * @return string |
| 471 | */ |
| 472 | public function &getQuery() { |
| 473 | return $this->_query; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Name of export file. |
| 478 | * |
| 479 | * @param string $output |
| 480 | * Type of output. |
| 481 | * |
| 482 | * @return string |
| 483 | * name of the file |
| 484 | */ |
| 485 | public function getExportFileName($output = 'csv') { |
| 486 | return ts('Case Search'); |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Add the set of "actionLinks" to the case activity |
| 491 | * |
| 492 | * @param int $caseID |
| 493 | * @param int $contactID |
| 494 | * @param int $userID |
| 495 | * @param string $context |
| 496 | * @param \CRM_Activity_BAO_Activity $dao |
| 497 | * @param bool $allowView |
| 498 | * |
| 499 | * @return string $linksMarkup |
| 500 | */ |
| 501 | public static function addCaseActivityLinks($caseID, $contactID, $userID, $context, $dao, $allowView = TRUE) { |
| 502 | $caseDeleted = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseID, 'is_deleted'); |
| 503 | $actionLinks = self::actionLinks(); |
| 504 | // Check logged in user for permission. |
| 505 | if (CRM_Case_BAO_Case::checkPermission($dao->id, 'view', $dao->activity_type_id, $userID)) { |
| 506 | $permissions[] = CRM_Core_Permission::VIEW; |
| 507 | } |
| 508 | if (!$allowView) { |
| 509 | unset($actionLinks[CRM_Core_Action::VIEW]); |
| 510 | } |
| 511 | if (!$dao->deleted) { |
| 512 | // Activity is not deleted, allow user to edit/delete if they have permission |
| 513 | // hide Edit link if: |
| 514 | // 1. User does not have edit permission. |
| 515 | // 2. Activity type is NOT editable (special case activities).CRM-5871 |
| 516 | if (CRM_Case_BAO_Case::checkPermission($dao->id, 'edit', $dao->activity_type_id, $userID)) { |
| 517 | $permissions[] = CRM_Core_Permission::EDIT; |
| 518 | } |
| 519 | if (in_array($dao->activity_type_id, CRM_Activity_BAO_Activity::getViewOnlyActivityTypeIDs())) { |
| 520 | unset($actionLinks[CRM_Core_Action::UPDATE]); |
| 521 | } |
| 522 | if (CRM_Case_BAO_Case::checkPermission($dao->id, 'delete', $dao->activity_type_id, $userID)) { |
| 523 | $permissions[] = CRM_Core_Permission::DELETE; |
| 524 | } |
| 525 | unset($actionLinks[CRM_Core_Action::RENEW]); |
| 526 | } |
| 527 | $extraMask = 0; |
| 528 | if ($dao->deleted && !$caseDeleted |
| 529 | && (CRM_Case_BAO_Case::checkPermission($dao->id, 'delete', $dao->activity_type_id, $userID))) { |
| 530 | // Case is not deleted but activity is. |
| 531 | // Allow user to restore activity if they have delete permissions |
| 532 | unset($actionLinks[CRM_Core_Action::DELETE]); |
| 533 | $extraMask = CRM_Core_Action::RENEW; |
| 534 | } |
| 535 | if (!CRM_Case_BAO_Case::checkPermission($dao->id, 'Move To Case', $dao->activity_type_id)) { |
| 536 | unset($actionLinks[CRM_Core_Action::DETACH]); |
| 537 | } |
| 538 | if (!CRM_Case_BAO_Case::checkPermission($dao->id, 'Copy To Case', $dao->activity_type_id)) { |
| 539 | unset($actionLinks[CRM_Core_Action::COPY]); |
| 540 | } |
| 541 | $actionMask = CRM_Core_Action::mask($permissions) | $extraMask; |
| 542 | $values = [ |
| 543 | 'aid' => $dao->id, |
| 544 | 'cid' => $contactID, |
| 545 | 'cxt' => empty($context) ? '' : "&context={$context}", |
| 546 | 'caseid' => $caseID, |
| 547 | ]; |
| 548 | $linksMarkup = CRM_Core_Action::formLink($actionLinks, |
| 549 | $actionMask, |
| 550 | $values, |
| 551 | ts('more'), |
| 552 | FALSE, |
| 553 | 'case.tab.row', |
| 554 | 'Activity', |
| 555 | $dao->id |
| 556 | ); |
| 557 | // if there are file attachments we will return how many and, if only one, add a link to it |
| 558 | if (!empty($dao->attachment_ids)) { |
| 559 | $linksMarkup .= implode(' ', CRM_Core_BAO_File::paperIconAttachment('civicrm_activity', $dao->id)); |
| 560 | } |
| 561 | return $linksMarkup; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * @param int $caseID |
| 566 | * @param int $contactID |
| 567 | * @param int $userID |
| 568 | * @param string $context |
| 569 | * @param int $activityTypeID |
| 570 | * @param int $activityDeleted |
| 571 | * @param int $activityID |
| 572 | * @param bool $allowView |
| 573 | * |
| 574 | * @return array|null |
| 575 | */ |
| 576 | public static function permissionedActionLinks($caseID, $contactID, $userID, $context, $activityTypeID, $activityDeleted, $activityID, $allowView = TRUE) { |
| 577 | $caseDeleted = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseID, 'is_deleted'); |
| 578 | $values = [ |
| 579 | 'aid' => $activityID, |
| 580 | 'cid' => $contactID, |
| 581 | 'cxt' => empty($context) ? '' : "&context={$context}", |
| 582 | 'caseid' => $caseID, |
| 583 | ]; |
| 584 | $actionLinks = self::actionLinks(); |
| 585 | |
| 586 | // Check logged in user for permission. |
| 587 | if (CRM_Case_BAO_Case::checkPermission($activityID, 'view', $activityTypeID, $userID)) { |
| 588 | $permissions[] = CRM_Core_Permission::VIEW; |
| 589 | } |
| 590 | if (!$allowView) { |
| 591 | unset($actionLinks[CRM_Core_Action::VIEW]); |
| 592 | } |
| 593 | if (!$activityDeleted) { |
| 594 | // Activity is not deleted, allow user to edit/delete if they have permission |
| 595 | |
| 596 | // hide Edit link if: |
| 597 | // 1. User does not have edit permission. |
| 598 | // 2. Activity type is NOT editable (special case activities).CRM-5871 |
| 599 | if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit', $activityTypeID, $userID)) { |
| 600 | $permissions[] = CRM_Core_Permission::EDIT; |
| 601 | } |
| 602 | if (in_array($activityTypeID, CRM_Activity_BAO_Activity::getViewOnlyActivityTypeIDs())) { |
| 603 | unset($actionLinks[CRM_Core_Action::UPDATE]); |
| 604 | } |
| 605 | if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete', $activityTypeID, $userID)) { |
| 606 | $permissions[] = CRM_Core_Permission::DELETE; |
| 607 | } |
| 608 | unset($actionLinks[CRM_Core_Action::RENEW]); |
| 609 | } |
| 610 | $extraMask = 0; |
| 611 | if ($activityDeleted && !$caseDeleted |
| 612 | && (CRM_Case_BAO_Case::checkPermission($activityID, 'delete', $activityTypeID, $userID))) { |
| 613 | // Case is not deleted but activity is. |
| 614 | // Allow user to restore activity if they have delete permissions |
| 615 | unset($actionLinks[CRM_Core_Action::DELETE]); |
| 616 | $extraMask = CRM_Core_Action::RENEW; |
| 617 | } |
| 618 | if (!CRM_Case_BAO_Case::checkPermission($activityID, 'Move To Case', $activityTypeID)) { |
| 619 | unset($actionLinks[CRM_Core_Action::DETACH]); |
| 620 | } |
| 621 | if (!CRM_Case_BAO_Case::checkPermission($activityID, 'Copy To Case', $activityTypeID)) { |
| 622 | unset($actionLinks[CRM_Core_Action::COPY]); |
| 623 | } |
| 624 | |
| 625 | $actionMask = CRM_Core_Action::mask($permissions) | $extraMask; |
| 626 | return CRM_Core_Action::filterLinks($actionLinks, $actionMask, $values, 'case.activity', 'Activity', $activityID); |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Get the action links for this page. |
| 631 | * |
| 632 | * @return array |
| 633 | */ |
| 634 | public static function actionLinks() { |
| 635 | // check if variable _actionsLinks is populated |
| 636 | if (!isset(self::$_actionLinks)) { |
| 637 | self::$_actionLinks = [ |
| 638 | CRM_Core_Action::VIEW => [ |
| 639 | 'name' => ts('View'), |
| 640 | 'url' => 'civicrm/case/activity/view', |
| 641 | 'qs' => 'reset=1&cid=%%cid%%&caseid=%%caseid%%&aid=%%aid%%', |
| 642 | 'title' => ts('View'), |
| 643 | ], |
| 644 | CRM_Core_Action::UPDATE => [ |
| 645 | 'name' => ts('Edit'), |
| 646 | 'url' => 'civicrm/case/activity', |
| 647 | 'qs' => 'reset=1&cid=%%cid%%&caseid=%%caseid%%&id=%%aid%%&action=update%%cxt%%', |
| 648 | 'title' => ts('Edit'), |
| 649 | 'icon' => 'fa-pencil', |
| 650 | ], |
| 651 | CRM_Core_Action::DELETE => [ |
| 652 | 'name' => ts('Delete'), |
| 653 | 'url' => 'civicrm/case/activity', |
| 654 | 'qs' => 'reset=1&cid=%%cid%%&caseid=%%caseid%%&id=%%aid%%&action=delete%%cxt%%', |
| 655 | 'title' => ts('Delete'), |
| 656 | 'icon' => 'fa-trash', |
| 657 | ], |
| 658 | CRM_Core_Action::RENEW => [ |
| 659 | 'name' => ts('Restore'), |
| 660 | 'url' => 'civicrm/case/activity', |
| 661 | 'qs' => 'reset=1&cid=%%cid%%&caseid=%%caseid%%&id=%%aid%%&action=renew%%cxt%%', |
| 662 | 'title' => ts('Restore'), |
| 663 | 'icon' => 'fa-undo', |
| 664 | ], |
| 665 | CRM_Core_Action::DETACH => [ |
| 666 | 'name' => ts('Move To Case'), |
| 667 | 'ref' => 'move_to_case_action', |
| 668 | 'title' => ts('Move To Case'), |
| 669 | 'extra' => 'onclick = "Javascript:fileOnCase( \'move\', %%aid%%, %%caseid%%, this ); return false;"', |
| 670 | 'icon' => 'fa-clipboard', |
| 671 | ], |
| 672 | CRM_Core_Action::COPY => [ |
| 673 | 'name' => ts('Copy To Case'), |
| 674 | 'ref' => 'copy_to_case_action', |
| 675 | 'title' => ts('Copy To Case'), |
| 676 | 'extra' => 'onclick = "Javascript:fileOnCase( \'copy\', %%aid%%, %%caseid%%, this ); return false;"', |
| 677 | 'icon' => 'fa-files-o', |
| 678 | ], |
| 679 | ]; |
| 680 | } |
| 681 | return self::$_actionLinks; |
| 682 | } |
| 683 | |
| 684 | } |