Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-28-20-20-34
[civicrm-core.git] / api / v3 / examples / Setting / GetDefaults.php
index 6e20ae6712e32e4b787ffe8e9613f8f7b98c2d54..5084c159cee6aacd1edf3a98d75819fdc3ffa40a 100644 (file)
@@ -1,31 +1,39 @@
 <?php
-
-/*
- gets defaults setting a variable for a given domain - if no domain is set current is assumed
+/**
+ * Test Generated example of using setting getdefaults API
+ * gets defaults setting a variable for a given domain - if no domain is set current is assumed *
  */
 function setting_getdefaults_example(){
-$params = array( 
-  'version' => 3,
+$params = array(
   'name' => 'address_format',
 );
 
-  $result = civicrm_api( 'setting','getdefaults',$params );
+try{
+  $result = civicrm_api3('setting', 'getdefaults', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+  // handle error here
+  $errorMessage = $e->getMessage();
+  $errorCode = $e->getErrorCode();
+  $errorData = $e->getExtraParams();
+  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
 
-  return $result;
+return $result;
 }
 
-/*
+/**
  * Function returns array of result expected from previous function
  */
 function setting_getdefaults_expectedresult(){
 
-  $expectedResult = array( 
+  $expectedResult = array(
   'is_error' => 0,
   'version' => 3,
   'count' => 1,
   'id' => 1,
-  'values' => array( 
-      '1' => array( 
+  'values' => array(
+      '1' => array(
           'address_format' => '{contact.address_name}
 {contact.street_address}
 {contact.supplemental_address_1}
@@ -36,7 +44,7 @@ function setting_getdefaults_expectedresult(){
     ),
 );
 
-  return $expectedResult  ;
+  return $expectedResult;
 }