From: Tim Otten Date: Tue, 3 Jun 2014 04:04:47 +0000 (-0700) Subject: CRM-14476 - CRM_Case_BAO_CaseType - In array-based definition, represent true boolean... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2f58fb093903e467e6ba0e427ceec0be10b6c4b3;p=civicrm-core.git CRM-14476 - CRM_Case_BAO_CaseType - In array-based definition, represent true boolean values of "sequence" and "timeline" as "1". --- diff --git a/CRM/Case/BAO/CaseType.php b/CRM/Case/BAO/CaseType.php index 6fea8d02f4..2fef389b8b 100644 --- a/CRM/Case/BAO/CaseType.php +++ b/CRM/Case/BAO/CaseType.php @@ -108,21 +108,28 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType { foreach ($definition['activitySets'] as $k => $val) { $xmlFile .= "\n"; foreach ($val as $index => $setVal) { - if ($index == 'activityTypes') { - if (!empty($setVal)) { - $xmlFile .= "\n"; - foreach ($setVal as $values) { - $xmlFile .= "\n"; - foreach ($values as $key => $value) { - $xmlFile .= "<{$key}>{$value}\n"; + switch ($index) { + case 'activityTypes': + if (!empty($setVal)) { + $xmlFile .= "\n"; + foreach ($setVal as $values) { + $xmlFile .= "\n"; + foreach ($values as $key => $value) { + $xmlFile .= "<{$key}>{$value}\n"; + } + $xmlFile .= "\n"; } - $xmlFile .= "\n"; + $xmlFile .= "\n"; } - $xmlFile .= "\n"; - } - } - else { - $xmlFile .= "<{$index}>{$setVal}\n"; + break; + case 'sequence': // passthrough + case 'timeline': + if ($setVal) { + $xmlFile .= "<{$index}>true\n"; + } + break; + default: + $xmlFile .= "<{$index}>{$setVal}\n"; } } @@ -173,10 +180,16 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType { $definition['activitySets'] = array(); foreach ($xml->ActivitySets->ActivitySet as $activitySetXML) { // parse basic properties - $activitySet = json_decode(json_encode($activitySetXML), TRUE); - unset($activitySet['ActivityTypes']); // not parsed reliably (eg single-tag vs multi-tag) + $activitySet = array(); + $activitySet['name'] = (string) $activitySetXML->name; + $activitySet['label'] = (string) $activitySetXML->label; + if ('true' == (string) $activitySetXML->timeline) { + $activitySet['timeline'] = 1; + } + if ('true' == (string) $activitySetXML->sequence) { + $activitySet['sequence'] = 1; + } - // parse activity-types if (isset($activitySetXML->ActivityTypes)) { $activitySet['activityTypes'] = array(); foreach ($activitySetXML->ActivityTypes->ActivityType as $activityTypeXML) { diff --git a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php index d26c9ddd32..aceffd4690 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php @@ -47,7 +47,7 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { array( 'name' => 'set1', 'label' => 'Label 1', - 'timeline' => 'true', + 'timeline' => 1, 'activityTypes' => array( array('name' => 'Open Case', 'status' => 'Completed'), ), @@ -99,7 +99,7 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { array( 'name' => 'set1', 'label' => 'Label 1', - 'timeline' => 'true', + 'timeline' => 1, 'activityTypes' => array( array('name' => 'Open Case', 'status' => 'Completed'), array( @@ -113,7 +113,7 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { array( 'name' => 'set2', 'label' => 'Label 2', - 'sequence' => 'true', + 'sequence' => 1, 'activityTypes' => array( array('name' => 'First act'), array('name' => 'Second act'),