3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM Case.
15 * @package CiviCRM_APIv3
19 * Create or update case type.
21 * @param array $params
24 * @throws API_Exception
28 function civicrm_api3_case_type_create($params) {
29 civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__
));
30 // Computed properties.
31 unset($params['is_forkable']);
32 unset($params['is_forked']);
34 if (!array_key_exists('is_active', $params) && empty($params['id'])) {
35 $params['is_active'] = TRUE;
37 // This is an existing case-type.
38 if (!empty($params['id']) && isset($params['definition'])
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'])
44 unset($params['definition']);
46 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'CaseType');
47 return _civicrm_api3_case_type_get_formatResult($result);
51 * Retrieve case types.
53 * @param array $params
56 * case types keyed by id
58 function civicrm_api3_case_type_get($params) {
59 if (!empty($params['options']) && !empty($params['options']['is_count'])) {
60 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
62 $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
63 // format case type, to fetch xml definition
64 $options = _civicrm_api3_get_options_from_params($params);
65 return _civicrm_api3_case_type_get_formatResult($caseTypes, $options);
71 * @param array $result
72 * @param array $options
75 * @throws \CRM_Core_Exception
77 function _civicrm_api3_case_type_get_formatResult(&$result, $options = []) {
78 foreach ($result['values'] as $key => &$caseType) {
79 if (!empty($caseType['definition'])) {
80 list($xml) = CRM_Utils_XML
::parseString($caseType['definition']);
81 $caseType['definition'] = $xml ? CRM_Case_BAO_CaseType
::convertXmlToDefinition($xml) : [];
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);
87 $caseType['definition'] = $xml ? CRM_Case_BAO_CaseType
::convertXmlToDefinition($xml) : [];
90 $caseType['is_forkable'] = CRM_Case_BAO_CaseType
::isForkable($caseType['id']);
91 $caseType['is_forked'] = CRM_Case_BAO_CaseType
::isForked($caseType['id']);
97 * Function to delete case type.
99 * @param array $params
100 * Array including id of CaseType to delete.
105 function civicrm_api3_case_type_delete($params) {
106 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);