Merge pull request #15840 from yashodha/participant_edit
[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 $hook = empty($params['id']) ? 'create' : 'edit';
33 CRM_Utils_Hook::pre($hook, 'CaseContact', CRM_Utils_Array::value('id', $params), $params);
34
35 $caseContact = new self();
36 $caseContact->copyValues($params);
37 $caseContact->save();
38
39 CRM_Utils_Hook::post($hook, 'CaseContact', $caseContact->id, $caseContact);
40
41 // add to recently viewed
42 $caseType = CRM_Case_BAO_Case::getCaseType($caseContact->case_id);
43 $url = CRM_Utils_System::url('civicrm/contact/view/case',
44 "action=view&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
45 );
46
47 $title = CRM_Contact_BAO_Contact::displayName($caseContact->contact_id) . ' - ' . $caseType;
48
49 $recentOther = [];
50 if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
51 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
52 "action=delete&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
53 );
54 }
55
56 // add the recently created case
57 CRM_Utils_Recent::add($title,
58 $url,
59 $caseContact->case_id,
60 'Case',
61 $caseContact->contact_id,
62 NULL,
63 $recentOther
64 );
65
66 return $caseContact;
67 }
68
69 /**
70 * @inheritDoc
71 */
72 public function addSelectWhereClause() {
73 return [
74 // Reuse case acls
75 'case_id' => CRM_Utils_SQL::mergeSubquery('Case'),
76 // Case acls already check for contact access so we can just mark contact_id as handled
77 'contact_id' => [],
78 ];
79 // Don't call hook selectWhereClause, the case query already did
80 }
81
82 }