Commit | Line | Data |
---|---|---|
ff9340a4 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
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 | * This api exposes CiviCRM CaseContact records. | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | */ | |
33 | ||
34 | /** | |
35 | * Save a CaseContact. | |
36 | * | |
37 | * @param array $params | |
38 | * | |
39 | * @return array | |
40 | */ | |
41 | function civicrm_api3_case_contact_create($params) { | |
42 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
43 | } | |
44 | ||
1816ac4c CW |
45 | /** |
46 | * @param array $fields | |
47 | */ | |
48 | function _civicrm_api3_case_contact_create_spec(&$fields) { | |
49 | $fields['contact_id']['api.required'] = $fields['case_id']['api.required'] = 1; | |
50 | } | |
51 | ||
ff9340a4 CW |
52 | /** |
53 | * Get a CaseContact. | |
54 | * | |
55 | * @param array $params | |
56 | * | |
57 | * @return array | |
58 | * Array of retrieved case_contact property values. | |
59 | */ | |
60 | function civicrm_api3_case_contact_get($params) { | |
61 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Delete a CaseContact. | |
66 | * | |
67 | * @param array $params | |
68 | * | |
69 | * @return array | |
70 | * Array of deleted values. | |
71 | */ | |
72 | function civicrm_api3_case_contact_delete($params) { | |
73 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Results formatting for Case entityRef lookups. | |
78 | * | |
79 | * @param array $result | |
80 | * @param array $request | |
81 | * @param string $entity | |
82 | * @param array $fields | |
83 | * | |
84 | * @return array | |
85 | */ | |
86 | function _civicrm_api3_case_contact_getlist_output($result, $request, $entity, $fields) { | |
87 | $output = array(); | |
88 | if (!empty($result['values'])) { | |
89 | foreach ($result['values'] as $row) { | |
90 | $data = array( | |
91 | 'id' => $row[$request['id_field']], | |
92 | 'label' => $row[$request['label_field']] . ' - ' . $row['case_id.case_type_id.title'], | |
93 | ); | |
94 | $status = CRM_Core_PseudoConstant::getLabel('CRM_Case_BAO_Case', 'status_id', $row['case_id.status_id']); | |
95 | $date = CRM_Utils_Date::customFormat($row['case_id.start_date']); | |
96 | $data['description'] = array( | |
97 | "#{$row['case_id']}: $status " . ts('(opened %1)', array(1 => $date)), | |
98 | $row['case_id.subject'], | |
99 | ); | |
100 | if (!empty($request['image_field'])) { | |
101 | $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : ''; | |
102 | } | |
103 | $output[] = $data; | |
104 | } | |
105 | } | |
106 | return $output; | |
107 | } |