Merge pull request #18544 from magnolia61/participant_status_notification_default
[civicrm-core.git] / CRM / Case / BAO / CaseContact.php
CommitLineData
ff9340a4
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
ff9340a4 5 | |
bc77d7c0
TO
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 |
ff9340a4
CW
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
ff9340a4
CW
16 */
17
18/**
19 * This class contains the functions for Case Contact management.
20 */
21class 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) {
0419bf7b 32 $caseContact = self::writeRecord($params);
0a6eb46f 33
ff9340a4
CW
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
be2fb01f 42 $recentOther = [];
ff9340a4
CW
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 */
20e41014 65 public function addSelectWhereClause() {
be2fb01f 66 return [
0b80f0b4 67 // Reuse case acls
d1d3c04a 68 'case_id' => CRM_Utils_SQL::mergeSubquery('Case'),
ff9340a4 69 // Case acls already check for contact access so we can just mark contact_id as handled
be2fb01f
CW
70 'contact_id' => [],
71 ];
0b80f0b4 72 // Don't call hook selectWhereClause, the case query already did
ff9340a4
CW
73 }
74
75}