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__)); |
9d32e6f7 EM |
30 | // Computed properties. |
31 | unset($params['is_forkable']); | |
32 | unset($params['is_forked']); | |
eaefbeb2 | 33 | |
52ae14f0 | 34 | if (!array_key_exists('is_active', $params) && empty($params['id'])) { |
eaefbeb2 N |
35 | $params['is_active'] = TRUE; |
36 | } | |
9d32e6f7 | 37 | // This is an existing case-type. |
492121d2 | 38 | if (!empty($params['id']) && isset($params['definition']) |
7c31ae57 SL |
39 | // which is not yet forked |
40 | && !CRM_Case_BAO_CaseType::isForked($params['id']) | |
41 | // for which new forks are prohibited | |
42 | && !CRM_Case_BAO_CaseType::isForkable($params['id']) | |
32f1c917 TO |
43 | ) { |
44 | unset($params['definition']); | |
45 | } | |
46 | $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'CaseType'); | |
47 | return _civicrm_api3_case_type_get_formatResult($result); | |
eaefbeb2 N |
48 | } |
49 | ||
50 | /** | |
9d32e6f7 | 51 | * Retrieve case types. |
eaefbeb2 | 52 | * |
c490a46a | 53 | * @param array $params |
77b97be7 | 54 | * |
a6c01b45 | 55 | * @return array |
72b3a70c | 56 | * case types keyed by id |
eaefbeb2 N |
57 | */ |
58 | function civicrm_api3_case_type_get($params) { | |
4771089b EM |
59 | if (!empty($params['options']) && !empty($params['options']['is_count'])) { |
60 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
61 | } | |
4e95e303 | 62 | $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
4e95e303 | 63 | // format case type, to fetch xml definition |
492121d2 CW |
64 | $options = _civicrm_api3_get_options_from_params($params); |
65 | return _civicrm_api3_case_type_get_formatResult($caseTypes, $options); | |
4e95e303 | 66 | } |
67 | ||
68 | /** | |
9d32e6f7 | 69 | * Format definition. |
4e95e303 | 70 | * |
645ee340 | 71 | * @param array $result |
492121d2 | 72 | * @param array $options |
9d32e6f7 | 73 | * |
c23f45d3 | 74 | * @return array |
645ee340 | 75 | * @throws \CRM_Core_Exception |
4e95e303 | 76 | */ |
cf8f0fff | 77 | function _civicrm_api3_case_type_get_formatResult(&$result, $options = []) { |
492121d2 CW |
78 | foreach ($result['values'] as $key => &$caseType) { |
79 | if (!empty($caseType['definition'])) { | |
80 | list($xml) = CRM_Utils_XML::parseString($caseType['definition']); | |
cf8f0fff | 81 | $caseType['definition'] = $xml ? CRM_Case_BAO_CaseType::convertXmlToDefinition($xml) : []; |
0db6c3e1 TO |
82 | } |
83 | else { | |
492121d2 CW |
84 | if (empty($options['return']) || !empty($options['return']['definition'])) { |
85 | $caseTypeName = (isset($caseType['name'])) ? $caseType['name'] : CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $caseType['id'], 'name', 'id', TRUE); | |
86 | $xml = CRM_Case_XMLRepository::singleton()->retrieve($caseTypeName); | |
cf8f0fff | 87 | $caseType['definition'] = $xml ? CRM_Case_BAO_CaseType::convertXmlToDefinition($xml) : []; |
492121d2 | 88 | } |
c2f2bbe6 | 89 | } |
492121d2 CW |
90 | $caseType['is_forkable'] = CRM_Case_BAO_CaseType::isForkable($caseType['id']); |
91 | $caseType['is_forked'] = CRM_Case_BAO_CaseType::isForked($caseType['id']); | |
93d47462 TO |
92 | } |
93 | return $result; | |
eaefbeb2 N |
94 | } |
95 | ||
96 | /** | |
9d32e6f7 | 97 | * Function to delete case type. |
eaefbeb2 | 98 | * |
cf470720 | 99 | * @param array $params |
244bbdd8 | 100 | * Array including id of CaseType to delete. |
c23f45d3 | 101 | * |
a6c01b45 | 102 | * @return array |
72b3a70c | 103 | * API result array |
eaefbeb2 N |
104 | */ |
105 | function civicrm_api3_case_type_delete($params) { | |
106 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
107 | } |