Merge pull request #19464 from eileenmcnaughton/menu
[civicrm-core.git] / CRM / Case / BAO / CaseContact.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class contains the functions for Case Contact management.
20 */
21 class CRM_Case_BAO_CaseContact extends CRM_Case_DAO_CaseContact {
22
23 /**
24 * Create case contact record.
25 *
26 * @param array $params
27 * case_id, contact_id
28 *
29 * @return CRM_Case_BAO_CaseContact
30 */
31 public static function create($params) {
32 $caseContact = self::writeRecord($params);
33
34 // add to recently viewed
35 $caseType = CRM_Case_BAO_Case::getCaseType($caseContact->case_id);
36 $url = CRM_Utils_System::url('civicrm/contact/view/case',
37 "action=view&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
38 );
39
40 $title = CRM_Contact_BAO_Contact::displayName($caseContact->contact_id) . ' - ' . $caseType;
41
42 $recentOther = [];
43 if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
44 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
45 "action=delete&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
46 );
47 }
48
49 // add the recently created case
50 CRM_Utils_Recent::add($title,
51 $url,
52 $caseContact->case_id,
53 'Case',
54 $caseContact->contact_id,
55 NULL,
56 $recentOther
57 );
58
59 return $caseContact;
60 }
61
62 /**
63 * @inheritDoc
64 */
65 public function addSelectWhereClause() {
66 return [
67 // Reuse case acls
68 'case_id' => CRM_Utils_SQL::mergeSubquery('Case'),
69 // Case acls already check for contact access so we can just mark contact_id as handled
70 'contact_id' => [],
71 ];
72 // Don't call hook selectWhereClause, the case query already did
73 }
74
75 }