Merge pull request #18393 from eileenmcnaughton/just_load
[civicrm-core.git] / api / v3 / CaseContact.php
... / ...
CommitLineData
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 * This api exposes CiviCRM CaseContact records.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18/**
19 * Save a CaseContact.
20 *
21 * @param array $params
22 *
23 * @return array
24 */
25function civicrm_api3_case_contact_create($params) {
26 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'CaseContact');
27}
28
29/**
30 * @param array $fields
31 */
32function _civicrm_api3_case_contact_create_spec(&$fields) {
33 $fields['contact_id']['api.required'] = $fields['case_id']['api.required'] = 1;
34}
35
36/**
37 * Get a CaseContact.
38 *
39 * @param array $params
40 *
41 * @return array
42 * Array of retrieved case_contact property values.
43 */
44function civicrm_api3_case_contact_get($params) {
45 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
46}
47
48/**
49 * Delete a CaseContact.
50 *
51 * @param array $params
52 *
53 * @return array
54 * Array of deleted values.
55 */
56function civicrm_api3_case_contact_delete($params) {
57 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
58}
59
60/**
61 * Results formatting for Case entityRef lookups.
62 *
63 * @param array $result
64 * @param array $request
65 * @param string $entity
66 * @param array $fields
67 *
68 * @return array
69 */
70function _civicrm_api3_case_contact_getlist_output($result, $request, $entity, $fields) {
71 $output = [];
72 if (!empty($result['values'])) {
73 foreach ($result['values'] as $row) {
74 $data = [
75 'id' => $row[$request['id_field']],
76 'label' => $row[$request['label_field']] . ' - ' . $row['case_id.case_type_id.title'],
77 ];
78 $status = CRM_Core_PseudoConstant::getLabel('CRM_Case_BAO_Case', 'status_id', $row['case_id.status_id']);
79 $date = CRM_Utils_Date::customFormat($row['case_id.start_date']);
80 $data['description'] = [
81 "#{$row['case_id']}: $status " . ts('(opened %1)', [1 => $date]),
82 $row['case_id.subject'],
83 ];
84 if (!empty($request['image_field'])) {
85 $data['image'] = $row[$request['image_field']] ?? '';
86 }
87 $output[] = $data;
88 }
89 }
90 return $output;
91}