Merge pull request #15614 from seamuslee001/convert_case_date_jcalendar
[civicrm-core.git] / CRM / Case / BAO / CaseContact.php
CommitLineData
ff9340a4
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
ff9340a4 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
ff9340a4
CW
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
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
ff9340a4
CW
32 */
33
34/**
35 * This class contains the functions for Case Contact management.
36 */
37class CRM_Case_BAO_CaseContact extends CRM_Case_DAO_CaseContact {
38
39 /**
40 * Create case contact record.
41 *
42 * @param array $params
43 * case_id, contact_id
44 *
45 * @return CRM_Case_BAO_CaseContact
46 */
47 public static function create($params) {
0a6eb46f
AS
48 $hook = empty($params['id']) ? 'create' : 'edit';
49 CRM_Utils_Hook::pre($hook, 'CaseContact', CRM_Utils_Array::value('id', $params), $params);
50
ff9340a4
CW
51 $caseContact = new self();
52 $caseContact->copyValues($params);
53 $caseContact->save();
54
0a6eb46f
AS
55 CRM_Utils_Hook::post($hook, 'CaseContact', $caseContact->id, $caseContact);
56
ff9340a4
CW
57 // add to recently viewed
58 $caseType = CRM_Case_BAO_Case::getCaseType($caseContact->case_id);
59 $url = CRM_Utils_System::url('civicrm/contact/view/case',
60 "action=view&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
61 );
62
63 $title = CRM_Contact_BAO_Contact::displayName($caseContact->contact_id) . ' - ' . $caseType;
64
be2fb01f 65 $recentOther = [];
ff9340a4
CW
66 if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
67 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
68 "action=delete&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
69 );
70 }
71
72 // add the recently created case
73 CRM_Utils_Recent::add($title,
74 $url,
75 $caseContact->case_id,
76 'Case',
77 $caseContact->contact_id,
78 NULL,
79 $recentOther
80 );
81
82 return $caseContact;
83 }
84
85 /**
86 * @inheritDoc
87 */
20e41014 88 public function addSelectWhereClause() {
be2fb01f 89 return [
0b80f0b4 90 // Reuse case acls
d1d3c04a 91 'case_id' => CRM_Utils_SQL::mergeSubquery('Case'),
ff9340a4 92 // Case acls already check for contact access so we can just mark contact_id as handled
be2fb01f
CW
93 'contact_id' => [],
94 ];
0b80f0b4 95 // Don't call hook selectWhereClause, the case query already did
ff9340a4
CW
96 }
97
98}