From 4e95e303a0c9146be88c7988fbbf2a88914b5bae Mon Sep 17 00:00:00 2001 From: kurund Date: Tue, 27 May 2014 18:31:23 +0530 Subject: [PATCH] fix case type get api to return definition, CRM-14725 ---------------------------------------- * CRM-14725: Edit Case Type - Use AJAX load/save https://issues.civicrm.org/jira/browse/CRM-14725 --- CRM/Case/BAO/CaseType.php | 34 ++++++++++++++++++++++++++++++++++ api/v3/CaseType.php | 15 ++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CRM/Case/BAO/CaseType.php b/CRM/Case/BAO/CaseType.php index 1f876df88b..60fb6fb8d7 100644 --- a/CRM/Case/BAO/CaseType.php +++ b/CRM/Case/BAO/CaseType.php @@ -163,4 +163,38 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType { $caseType->id = $caseTypeId; return $caseType->delete(); } + + /** + * Function to get the case definition + * + * @param $caseType + * @return mixed + * + * FIX ME: need to clean up this function + */ + static function getCaseTypeDefinition(&$caseType) { + // check if case type definition is saved in DB + if (!empty($caseType['values'][0]['definition'])) { + // FIX ME: process db values + } + else { + $xml = CRM_Case_XMLRepository::singleton()->retrieve($caseType['values'][0]['name']); + + // set activity types + $activityTypes = json_decode(json_encode($xml->ActivityTypes), true); + $caseType['values'][0]['definition']['activityTypes'] = $activityTypes['ActivityType']; + + // set activity sets + $activitySets = json_decode(json_encode($xml->ActivitySets), true); + $caseType['values'][0]['definition']['activitySets'] = $activitySets['ActivitySet']; + $caseType['values'][0]['definition']['activitySets']['activityTypes'] = $activitySets['ActivitySet']['ActivityTypes']['ActivityType']; + unset($caseType['values'][0]['definition']['activitySets']['ActivityTypes']); + + // set case roles + $caseRoles = json_decode(json_encode($xml->CaseRoles), true); + $caseType['values'][0]['definition']['caseRoles'] = $caseRoles['RelationshipType']; + } + + return $caseType; + } } diff --git a/api/v3/CaseType.php b/api/v3/CaseType.php index 0c95a85935..859b7510bb 100644 --- a/api/v3/CaseType.php +++ b/api/v3/CaseType.php @@ -69,7 +69,20 @@ function civicrm_api3_case_type_create($params) { */ function civicrm_api3_case_type_get($params) { civicrm_api3_verify_mandatory($params); - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + + // format case type, to fetch xml definition + return _civicrm_api3_case_type_get_formatResult($params, $caseTypes); +} + +/** + * Function to format definition + * + * @param $caseTypes + * @return mixed + */ +function _civicrm_api3_case_type_get_formatResult(&$caseTypes) { + return CRM_Case_BAO_CaseType::getCaseTypeDefinition($caseTypes); } /** -- 2.25.1