Commit | Line | Data |
---|---|---|
eaefbeb2 N |
1 | <?php |
2 | /* | |
a30c801b TO |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
eaefbeb2 N |
11 | |
12 | /** | |
c28e1768 | 13 | * This api exposes CiviCRM Case. |
eaefbeb2 N |
14 | * |
15 | * @package CiviCRM_APIv3 | |
eaefbeb2 N |
16 | */ |
17 | ||
18 | /** | |
9d32e6f7 | 19 | * Create or update case type. |
eaefbeb2 | 20 | * |
cf470720 TO |
21 | * @param array $params |
22 | * Input parameters. | |
eaefbeb2 | 23 | * |
eaefbeb2 | 24 | * @throws API_Exception |
a6c01b45 | 25 | * @return array |
72b3a70c | 26 | * API result array |
eaefbeb2 N |
27 | */ |
28 | function civicrm_api3_case_type_create($params) { | |
c7bccb5f | 29 | civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__)); |
eaefbeb2 | 30 | |
32f1c917 TO |
31 | $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'CaseType'); |
32 | return _civicrm_api3_case_type_get_formatResult($result); | |
eaefbeb2 N |
33 | } |
34 | ||
35 | /** | |
9d32e6f7 | 36 | * Retrieve case types. |
eaefbeb2 | 37 | * |
c490a46a | 38 | * @param array $params |
77b97be7 | 39 | * |
a6c01b45 | 40 | * @return array |
72b3a70c | 41 | * case types keyed by id |
eaefbeb2 N |
42 | */ |
43 | function civicrm_api3_case_type_get($params) { | |
4771089b EM |
44 | if (!empty($params['options']) && !empty($params['options']['is_count'])) { |
45 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
46 | } | |
4e95e303 | 47 | $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
4e95e303 | 48 | // format case type, to fetch xml definition |
492121d2 CW |
49 | $options = _civicrm_api3_get_options_from_params($params); |
50 | return _civicrm_api3_case_type_get_formatResult($caseTypes, $options); | |
4e95e303 | 51 | } |
52 | ||
53 | /** | |
9d32e6f7 | 54 | * Format definition. |
4e95e303 | 55 | * |
645ee340 | 56 | * @param array $result |
492121d2 | 57 | * @param array $options |
9d32e6f7 | 58 | * |
c23f45d3 | 59 | * @return array |
645ee340 | 60 | * @throws \CRM_Core_Exception |
4e95e303 | 61 | */ |
cf8f0fff | 62 | function _civicrm_api3_case_type_get_formatResult(&$result, $options = []) { |
492121d2 | 63 | foreach ($result['values'] as $key => &$caseType) { |
96f09dda CW |
64 | if (!empty($caseType['definition']) || empty($options['return']) || !empty($options['return']['definition'])) { |
65 | $caseType += ['definition' => NULL]; | |
66 | CRM_Case_BAO_CaseType::formatOutputDefinition($caseType['definition'], $caseType); | |
c2f2bbe6 | 67 | } |
492121d2 CW |
68 | $caseType['is_forkable'] = CRM_Case_BAO_CaseType::isForkable($caseType['id']); |
69 | $caseType['is_forked'] = CRM_Case_BAO_CaseType::isForked($caseType['id']); | |
93d47462 TO |
70 | } |
71 | return $result; | |
eaefbeb2 N |
72 | } |
73 | ||
74 | /** | |
9d32e6f7 | 75 | * Function to delete case type. |
eaefbeb2 | 76 | * |
cf470720 | 77 | * @param array $params |
244bbdd8 | 78 | * Array including id of CaseType to delete. |
c23f45d3 | 79 | * |
a6c01b45 | 80 | * @return array |
72b3a70c | 81 | * API result array |
eaefbeb2 N |
82 | */ |
83 | function civicrm_api3_case_type_delete($params) { | |
84 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
85 | } |