Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * |
33 | */ | |
34 | ||
35 | /** | |
3924e596 | 36 | * This class contains all case related functions that are called using AJAX |
6a488035 TO |
37 | */ |
38 | class CRM_Case_Page_AJAX { | |
39 | ||
3924e596 CW |
40 | /** |
41 | * @throws \CRM_Core_Exception | |
42 | */ | |
00be9182 | 43 | public function processCaseTags() { |
6a488035 | 44 | |
077dbf5e | 45 | $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive'); |
6a488035 | 46 | $tags = CRM_Utils_Type::escape($_POST['tag'], 'String'); |
6fd5424b | 47 | $tagList = $_POST['taglist']; |
6a488035 | 48 | |
077dbf5e CW |
49 | if (!CRM_Case_BAO_Case::accessCase($caseId)) { |
50 | CRM_Utils_System::permissionDenied(); | |
6a488035 TO |
51 | } |
52 | ||
53 | $tagIds = array(); | |
54 | if ($tags) { | |
55 | $tagIds = explode(',', $tags); | |
56 | } | |
57 | ||
79564bd4 CW |
58 | $params = array( |
59 | 'entity_id' => $caseId, | |
60 | 'entity_table' => 'civicrm_case', | |
61 | ); | |
6a488035 | 62 | |
79564bd4 | 63 | CRM_Core_BAO_EntityTag::del($params); |
6a488035 | 64 | |
79564bd4 CW |
65 | foreach ($tagIds as $tagid) { |
66 | if (is_numeric($tagid)) { | |
67 | $params['tag_id'] = $tagid; | |
68 | CRM_Core_BAO_EntityTag::add($params); | |
6a488035 TO |
69 | } |
70 | } | |
71 | ||
6fd5424b | 72 | if (!empty($tagList)) { |
79564bd4 | 73 | CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case'); |
6fd5424b | 74 | } |
75 | ||
6a488035 TO |
76 | $session = CRM_Core_Session::singleton(); |
77 | ||
78 | $activityParams = array(); | |
79 | $activityParams['source_contact_id'] = $session->get('userID'); | |
9c248a42 | 80 | $activityParams['activity_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Case Tags'); |
6a488035 | 81 | $activityParams['activity_date_time'] = date('YmdHis'); |
9c248a42 | 82 | $activityParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'); |
6a488035 TO |
83 | $activityParams['case_id'] = $caseId; |
84 | $activityParams['is_auto'] = 0; | |
85 | $activityParams['subject'] = 'Change Case Tags'; | |
86 | ||
87 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
88 | ||
89 | $caseParams = array( | |
90 | 'activity_id' => $activity->id, | |
91 | 'case_id' => $caseId, | |
92 | ); | |
93 | ||
94 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
95 | ||
96 | echo 'true'; | |
97 | CRM_Utils_System::civiExit(); | |
98 | } | |
99 | ||
3924e596 CW |
100 | /** |
101 | * @throws \CiviCRM_API3_Exception | |
102 | */ | |
00be9182 | 103 | public function caseDetails() { |
077dbf5e CW |
104 | $caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Positive'); |
105 | ||
0a1a8b63 CW |
106 | $case = civicrm_api3('Case', 'getsingle', array( |
107 | 'id' => $caseId, | |
108 | 'check_permissions' => TRUE, | |
109 | 'return' => array('subject', 'case_type_id', 'status_id', 'start_date', 'end_date')) | |
110 | ); | |
077dbf5e | 111 | |
3924e596 CW |
112 | $caseStatuses = CRM_Case_PseudoConstant::caseStatus(); |
113 | $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE); | |
114 | $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$case['subject']}</td></tr> | |
115 | <tr><td>" . ts('Case Type') . "</td><td>{$caseTypes[$case['case_type_id']]}</td></tr> | |
116 | <tr><td>" . ts('Case Status') . "</td><td>{$caseStatuses[$case['status_id']]}</td></tr> | |
117 | <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($case['start_date']) . "</td></tr> | |
118 | <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($case['end_date']) . "</table>"; | |
119 | ||
120 | if (CRM_Utils_Array::value('snippet', $_GET) == 'json') { | |
121 | CRM_Core_Page_AJAX::returnJsonResponse($caseDetails); | |
6a488035 | 122 | } |
3924e596 CW |
123 | |
124 | echo $caseDetails; | |
6a488035 TO |
125 | CRM_Utils_System::civiExit(); |
126 | } | |
127 | ||
3924e596 CW |
128 | /** |
129 | * @throws \CRM_Core_Exception | |
130 | */ | |
00be9182 | 131 | public function addClient() { |
077dbf5e CW |
132 | $caseId = CRM_Utils_Type::escape($_POST['caseID'], 'Positive'); |
133 | $contactId = CRM_Utils_Type::escape($_POST['contactID'], 'Positive'); | |
134 | ||
135 | if (!$contactId || !CRM_Case_BAO_Case::accessCase($caseId)) { | |
136 | CRM_Utils_System::permissionDenied(); | |
137 | } | |
6a488035 TO |
138 | |
139 | $params = array( | |
140 | 'case_id' => $caseId, | |
141 | 'contact_id' => $contactId, | |
142 | ); | |
143 | ||
ff9340a4 | 144 | CRM_Case_BAO_CaseContact::create($params); |
6a488035 | 145 | |
44466d80 KJ |
146 | // add case relationships |
147 | CRM_Case_BAO_Case::addCaseRelationships($caseId, $contactId); | |
148 | ||
6a488035 TO |
149 | $session = CRM_Core_Session::singleton(); |
150 | ||
151 | $activityParams = array(); | |
152 | $activityParams['source_contact_id'] = $session->get('userID'); | |
9c248a42 | 153 | $activityParams['activity_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Add Client To Case'); |
6a488035 | 154 | $activityParams['activity_date_time'] = date('YmdHis'); |
9c248a42 | 155 | $activityParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'); |
6a488035 TO |
156 | $activityParams['case_id'] = $caseId; |
157 | $activityParams['is_auto'] = 0; | |
158 | $activityParams['subject'] = 'Client Added To Case'; | |
159 | ||
160 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
161 | ||
162 | $caseParams = array( | |
163 | 'activity_id' => $activity->id, | |
164 | 'case_id' => $caseId, | |
165 | ); | |
166 | ||
167 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
ecdef330 | 168 | CRM_Utils_JSON::output(TRUE); |
6a488035 | 169 | } |
4cd35744 KJ |
170 | |
171 | /** | |
fe482240 | 172 | * Delete relationships specific to case and relationship type. |
4cd35744 | 173 | */ |
00be9182 | 174 | public static function deleteCaseRoles() { |
353ffa53 | 175 | $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive'); |
3b1c37fe CW |
176 | $cid = CRM_Utils_Type::escape($_POST['cid'], 'Positive'); |
177 | $relType = CRM_Utils_Request::retrieve('rel_type', 'String', CRM_Core_DAO::$_nullObject, TRUE); | |
077dbf5e | 178 | |
3b1c37fe | 179 | if (!$cid || !CRM_Case_BAO_Case::accessCase($caseId)) { |
077dbf5e CW |
180 | CRM_Utils_System::permissionDenied(); |
181 | } | |
4cd35744 | 182 | |
3b1c37fe | 183 | list($relTypeId, $a, $b) = explode('_', $relType); |
4cd35744 | 184 | |
3b1c37fe | 185 | CRM_Case_BAO_Case::endCaseRole($caseId, $b, $cid, $relTypeId); |
4cd35744 KJ |
186 | CRM_Utils_System::civiExit(); |
187 | } | |
96025800 | 188 | |
5f1c8c57 | 189 | public static function getCases() { |
190 | $requiredParameters = array( | |
191 | 'type' => 'String', | |
192 | ); | |
193 | $optionalParameters = array( | |
76ec1160 CW |
194 | 'case_type_id' => 'CommaSeparatedIntegers', |
195 | 'status_id' => 'CommaSeparatedIntegers', | |
5f1c8c57 | 196 | 'all' => 'Positive', |
197 | ); | |
198 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); | |
199 | $params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters); | |
200 | ||
201 | $allCases = (bool) $params['all']; | |
202 | ||
203 | $cases = CRM_Case_BAO_Case::getCases($allCases, $params); | |
204 | ||
205 | $casesDT = array( | |
206 | 'recordsFiltered' => $cases['total'], | |
207 | 'recordsTotal' => $cases['total'], | |
208 | ); | |
209 | unset($cases['total']); | |
bf5990e7 | 210 | $casesDT['data'] = array_values($cases); |
5f1c8c57 | 211 | |
212 | CRM_Utils_JSON::output($casesDT); | |
213 | } | |
214 | ||
6a488035 | 215 | } |