Merge pull request #6356 from monishdeb/CRM-16931
[civicrm-core.git] / api / v3 / Setting.php
index 19fe574344b21d8d93a1a90599d8836bdc57ef94..7a4a920f9e31edeaf58ddb897492650d617aa6cc 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  */
 
 /**
- * File for CiviCRM APIv3 settings
+ * This api exposes CiviCRM configuration settings.
  *
- * @package CiviCRM_APIv3_Core
- * @subpackage API_Settings
- * @copyright CiviCRM LLC (c) 2004-2014
- * @version $Id: Settings.php
+ * @package CiviCRM_APIv3
  */
 
 /**
@@ -54,7 +51,7 @@ function civicrm_api3_setting_getfields($params) {
         'description' => 'Settings Group. This is required if the setting is not stored in config',
         'type' => CRM_Utils_Type::T_STRING),
     );
-    return civicrm_api3_create_success($result, $params, 'setting', 'getfields');
+    return civicrm_api3_create_success($result, $params, 'Setting', 'getfields');
   }
   if (!empty($params['name'])) {
     //am of two minds about special handling for 'name' as opposed to other filters - but is does make most common
@@ -74,30 +71,44 @@ function civicrm_api3_setting_getfields($params) {
       $specFunction($result);
     }
   }
-  return civicrm_api3_create_success($result, $params, 'setting', 'getfields');
+  return civicrm_api3_create_success($result, $params, 'Setting', 'getfields');
 }
 
 /**
- * Alter metadata for getfields functions
+ * Alter metadata for getfields functions.
+ *
  * @param array $params
  */
 function _civicrm_api3_setting_getfields_spec(&$params) {
-  $params['filters'] = array('title' => 'Fields you wish to filter by e.g. array("group_name" => "CiviCRM Preferences")');
-  $params['component_id'] = array('title' => 'id of relevant component');
-  $params['profile'] = array('title' => 'profile is passed through to hooks & added to cachestring');
+  $params['filters'] = array(
+    'title' => 'Filters',
+    'description' => 'Fields you wish to filter by e.g. array("group_name" => "CiviCRM Preferences")',
+  );
+  $params['component_id'] = array(
+    'title' => 'Component ID',
+    'description' => 'ID of relevant component',
+  );
+  $params['profile'] = array(
+    'title' => 'Profile',
+    'description' => 'Profile is passed through to hooks & added to cachestring',
+  );
 }
 
 /**
- * Return default values for settings. We will domain key this as it could vary by domain (ie. urls)
+ * Return default values for settings.
+ *
+ * We will domain key this as it could vary by domain (ie. urls)
  * as we will be creating the option for a function rather than an value to be in the defaults
- * Note that is not in place as yet
+ * Note that is not in place as yet.
+ *
  * @param array $params
+ *
  * @return array
  * @throws \CiviCRM_API3_Exception
  * @throws \Exception
  */
 function civicrm_api3_setting_getdefaults(&$params) {
-  $settings = civicrm_api3('setting', 'getfields', $params);
+  $settings = civicrm_api3('Setting', 'getfields', $params);
   $domains = _civicrm_api3_setting_getDomainArray($params);
   $defaults = array();
   foreach ($domains as $domainID) {
@@ -116,10 +127,10 @@ function civicrm_api3_setting_getdefaults(&$params) {
       print_r($noDefaults);
     }
   }
-  return civicrm_api3_create_success($defaults, $params, 'setting', 'getfields');
+  return civicrm_api3_create_success($defaults, $params, 'Setting', 'getfields');
 }
 /**
- * Metadata for setting create function.
+ * Metadata for Setting create function.
  *
  * @param array $params
  *   Parameters as passed to the API.
@@ -142,8 +153,8 @@ function _civicrm_api3_setting_getdefaults_spec(&$params) {
  * @throws \Exception
  */
 function civicrm_api3_setting_revert(&$params) {
-  $defaults = civicrm_api('setting', 'getdefaults', $params);
-  $fields = civicrm_api('setting', 'getfields', $params);
+  $defaults = civicrm_api('Setting', 'getdefaults', $params);
+  $fields = civicrm_api('Setting', 'getfields', $params);
   $fields = $fields['values'];
   $domains = _civicrm_api3_setting_getDomainArray($params);
   $result = array();
@@ -153,37 +164,46 @@ function civicrm_api3_setting_revert(&$params) {
       $valuesToRevert['version'] = $params['version'];
       $valuesToRevert['domain_id'] = $domainID;
       // note that I haven't looked at how the result would appear with multiple domains in play
-      $result = array_merge($result, civicrm_api('setting', 'create', $valuesToRevert));
+      $result = array_merge($result, civicrm_api('Setting', 'create', $valuesToRevert));
     }
   }
 
-  return civicrm_api3_create_success($result, $params, 'setting', 'revert');
+  return civicrm_api3_create_success($result, $params, 'Setting', 'revert');
 }
 
 /**
- * Alter metadata for getfields functions
+ * Alter metadata for getfields functions.
+ *
  * @param array $params
  */
 function _civicrm_api3_setting_revert_spec(&$params) {
-  $params['name'] = array('title' => 'Setting Name belongs to');
-  $params['component_id'] = array('title' => 'id of relevant component');
+  $params['name'] = array(
+    'title' => 'Name',
+    'description' => 'Setting Name belongs to',
+  );
+  $params['component_id'] = array(
+    'title' => 'Component ID',
+    'description' => 'ID of relevant component',
+  );
   $params['domain_id'] = array(
     'api.default' => 'current_domain',
-    'description' => 'Defaults may differ by domain - if you do not pass in a domain id this will default to the current domain
-      an array or "all" are acceptable values for multiple domains',
+    'description' => 'Defaults may differ by domain - if you do not pass in a domain id this will default to the current domain'
+    . ' an array or "all" are acceptable values for multiple domains',
     'title' => 'Setting Domain',
   );
 }
 
 /**
- * Revert settings to defaults
+ * Revert settings to defaults.
+ *
  * @param array $params
+ *
  * @return array
  * @throws \CiviCRM_API3_Exception
  * @throws \Exception
  */
 function civicrm_api3_setting_fill(&$params) {
-  $defaults = civicrm_api3('setting', 'getdefaults', $params);
+  $defaults = civicrm_api3('Setting', 'getdefaults', $params);
   $domains = _civicrm_api3_setting_getDomainArray($params);
   $result = array();
   foreach ($domains as $domainID) {
@@ -191,13 +211,13 @@ function civicrm_api3_setting_fill(&$params) {
       'version' => $params['version'],
       'domain_id' => $domainID,
     );
-    $existing = civicrm_api3('setting', 'get', $apiArray);
+    $existing = civicrm_api3('Setting', 'get', $apiArray);
     $valuesToFill = array_diff_key($defaults['values'][$domainID], $existing['values'][$domainID]);
     if (!empty($valuesToFill)) {
-      $result = array_merge($result, civicrm_api('setting', 'create', $valuesToFill + $apiArray));
+      $result = array_merge($result, civicrm_api('Setting', 'create', $valuesToFill + $apiArray));
     }
   }
-  return civicrm_api3_create_success($result, $params, 'setting', 'fill');
+  return civicrm_api3_create_success($result, $params, 'Setting', 'fill');
 }
 
 /**
@@ -206,13 +226,19 @@ function civicrm_api3_setting_fill(&$params) {
  * @param array $params
  */
 function _civicrm_api3_setting_fill_spec(&$params) {
-  $params['name'] = array('title' => 'Setting Name belongs to');
-  $params['component_id'] = array('title' => 'id of relevant component');
+  $params['name'] = array(
+    'title' => 'Name',
+    'description' => 'Setting Name belongs to',
+  );
+  $params['component_id'] = array(
+    'title' => 'Component ID',
+    'description' => 'ID of relevant component',
+  );
   $params['domain_id'] = array(
     'api.default' => 'current_domain',
     'title' => 'Setting Domain',
-    'description' => 'Defaults may differ by domain - if you do not pass in a domain id this will default to the current domain
-      an array or "all" are acceptable values for multiple domains',
+    'description' => 'Defaults may differ by domain - if you do not pass in a domain id this will default to the '
+    . 'current domain, an array or "all" are acceptable values for multiple domains',
   );
 }
 
@@ -228,11 +254,11 @@ function _civicrm_api3_setting_fill_spec(&$params) {
 function civicrm_api3_setting_create($params) {
   $domains = _civicrm_api3_setting_getDomainArray($params);
   $result = CRM_Core_BAO_Setting::setItems($params, $domains);
-  return civicrm_api3_create_success($result, $params, 'setting', 'create');
+  return civicrm_api3_create_success($result, $params, 'Setting', 'create');
 }
 
 /**
- * Metadata for setting create function
+ * Metadata for setting create function.
  *
  * @param array $params
  *   Parameters as passed to the API.
@@ -262,10 +288,10 @@ function _civicrm_api3_setting_create_spec(&$params) {
 function civicrm_api3_setting_get($params) {
   $domains = _civicrm_api3_setting_getDomainArray($params);
   $result = $result = CRM_Core_BAO_Setting::getItems($params, $domains, CRM_Utils_Array::value('return', $params, array()));
-  return civicrm_api3_create_success($result, $params, 'setting', 'get');
+  return civicrm_api3_create_success($result, $params, 'Setting', 'get');
 }
 /**
- * Metadata for setting create function
+ * Metadata for setting create function.
  *
  * @param array $params
  *   Parameters as passed to the API.
@@ -282,16 +308,17 @@ function _civicrm_api3_setting_get_spec(&$params) {
   );
 }
 /**
- * Returns value for specific parameter. Function requires more fields than 'get' but is intended for
+ * Returns value for specific parameter.
+ *
+ * Function requires more fields than 'get' but is intended for
  * runtime usage & should be quicker
  *
  * @param array $params
- *   (reference) Array of one or more valid.
+ *   Array of one or more valid.
  *                       property_name=>value pairs.
  *
  * @return array
- *   Array of matching settings
- *   {@getfields setting_get}
+ *   API result array.
  */
 function civicrm_api3_setting_getvalue($params) {
   $config = CRM_Core_Config::singleton();
@@ -309,7 +336,7 @@ function civicrm_api3_setting_getvalue($params) {
 }
 
 /**
- * Metadata for setting create function
+ * Metadata for setting create function.
  *
  * @param array $params
  *   Parameters as passed to the API.
@@ -340,13 +367,17 @@ function _civicrm_api3_setting_getvalue_spec(&$params) {
 }
 
 /**
- * Converts domain input into an array. If an array is passed in this is used, if 'all' is passed
+ * Converts domain input into an array.
+ *
+ * If an array is passed in this is used, if 'all' is passed
  * in this is converted to 'all arrays'
  *
  * Really domain_id should always be set but doing an empty check because at the moment
  * using crm-editable will pass an id & default won't be applied
- * we did talk about id being a pseudonym for domain_id in this api so applying it here
+ * we did talk about id being a pseudonym for domain_id in this api so applying it here.
+ *
  * @param array $params
+ *
  * @return array
  * @throws \Exception
  */