CRM-14974 , worked on coding standard
[civicrm-core.git] / CRM / Core / BAO / Setting.php
index e9392503c1d600d847cbc2280f46c7d179d26bfb..c8cfb25d2960284b88408e814f5235e18cdeee80 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -44,9 +44,9 @@
 class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
 
   /**
-   * Various predefined settings that have been migrated to the setting table
+   * Various predefined settings that have been migrated to the setting table.
    */
-  CONST
+  const
     ADDRESS_STANDARDIZATION_PREFERENCES_NAME = 'Address Standardization Preferences',
     CAMPAIGN_PREFERENCES_NAME = 'Campaign Preferences',
     DEVELOPER_PREFERENCES_NAME = 'Developer Preferences',
@@ -66,25 +66,28 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   /**
    * Checks whether an item is present in the in-memory cache table
    *
-   * @param string $group (required) The group name of the item
-   * @param string $name (required) The name of the setting
-   * @param int $componentID The optional component ID (so components can share the same name space)
-   * @param int $contactID If set, this is a contactID specific setting, else its a global setting
+   * @param string $group
+   *   (required) The group name of the item.
+   * @param string $name
+   *   (required) The name of the setting.
+   * @param int $componentID
+   *   The optional component ID (so components can share the same name space).
+   * @param int $contactID
+   *   If set, this is a contactID specific setting, else its a global setting.
    * @param bool|int $load if true, load from local cache (typically memcache)
    *
    * @param int $domainID
    * @param bool $force
    *
-   * @return boolean true if item is already in cache
-   * @static
-   * @access public
+   * @return bool
+   *   true if item is already in cache
    */
-  static function inCache(
+  public static function inCache(
     $group,
     $name,
     $componentID = NULL,
-    $contactID   = NULL,
-    $load        = FALSE,
+    $contactID = NULL,
+    $load = FALSE,
     $domainID = NULL,
     $force = FALSE
   ) {
@@ -110,11 +113,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
 
     return isset(self::$_cache[$cacheKey]) ? $cacheKey : NULL;
   }
+
   /**
-  * Allow key o be cleared
-  * @param string $cacheKey
-  */
-  static function flushCache($cacheKey){
+   * Allow key o be cleared.
+   * @param string $cacheKey
+   */
+  public static function flushCache($cacheKey) {
     unset(self::$_cache[$cacheKey]);
     $globalCache = CRM_Utils_Cache::singleton();
     $globalCache->delete($cacheKey);
@@ -129,7 +133,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return string
    */
-  static function setCache($values,
+  public static function setCache(
+    $values,
     $group,
     $componentID = NULL,
     $contactID = NULL,
@@ -158,10 +163,11 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return CRM_Core_DAO_Domain|CRM_Core_DAO_Setting
    */
-  static function dao($group,
-    $name        = NULL,
+  public static function dao(
+    $group,
+    $name = NULL,
     $componentID = NULL,
-    $contactID   = NULL,
+    $contactID = NULL,
     $domainID = NULL
   ) {
     if (self::isUpgradeFromPreFourOneAlpha1()) {
@@ -173,11 +179,11 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
     }
     $dao = new CRM_Core_DAO_Setting();
 
-    $dao->group_name   = $group;
-    $dao->name         = $name;
+    $dao->group_name = $group;
+    $dao->name = $name;
     $dao->component_id = $componentID;
     if (empty($domainID)) {
-      $dao->domain_id    = CRM_Core_Config::domainID();
+      $dao->domain_id = CRM_Core_Config::domainID();
     }
     else {
       $dao->domain_id = $domainID;
@@ -195,37 +201,56 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Retrieve the value of a setting from the DB table
+   * Retrieve the value of a setting from the DB table.
    *
-   * @param string $group (required) The group name of the item
-   * @param string $name (required) The name under which this item is stored
-   * @param int $componentID The optional component ID (so componenets can share the same name space)
-   * @param string $defaultValue The default value to return for this setting if not present in DB
-   * @param int $contactID If set, this is a contactID specific setting, else its a global setting
+   * @param string $group
+   *   (required) The group name of the item.
+   * @param string $name
+   *   (required) The name under which this item is stored.
+   * @param int $componentID
+   *   The optional component ID (so componenets can share the same name space).
+   * @param string $defaultValue
+   *   The default value to return for this setting if not present in DB.
+   * @param int $contactID
+   *   If set, this is a contactID specific setting, else its a global setting.
    *
    * @param int $domainID
    *
-   * @return mixed The data if present in the setting table, else null
-   * @static
-   * @access public
+   * @return mixed
+   *   The data if present in the setting table, else null
    */
-  static function getItem(
+  public static function getItem(
     $group,
-    $name         = NULL,
-    $componentID  = NULL,
+    $name = NULL,
+    $componentID = NULL,
     $defaultValue = NULL,
-    $contactID    = NULL,
-    $domainID     = NULL
+    $contactID = NULL,
+    $domainID = NULL
   ) {
 
+    $override_group = array();
     if (NULL !== ($override = self::getOverride($group, $name, NULL))) {
-      return $override;
+      if (isset($name)) {
+        return $override;
+      }
+      else {
+        $override_group = $override;
+      }
     }
 
     if (empty($domainID)) {
       $domainID = CRM_Core_Config::domainID();
     }
     $cacheKey = self::inCache($group, $name, $componentID, $contactID, TRUE, $domainID);
+
+    if ($group && !isset($name) && $cacheKey) {
+      // check value against the cache, and unset key if values are different
+      $valueDifference = array_diff($override_group, self::$_cache[$cacheKey]);
+      if (!empty($valueDifference)) {
+        $cacheKey = '';
+      }
+    }
+
     if (!$cacheKey) {
       $dao = self::dao($group, NULL, $componentID, $contactID, $domainID);
       $dao->find();
@@ -244,24 +269,32 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       }
       $dao->free();
 
+      if (!isset($name)) {
+        // merge db and override group values
+        // When no $name is present, the getItem() function should return an array
+        // consisting of the sum of all override settings + all settings present in
+        // the database for the given $group (with the overrides taking precedence,
+        // and applying even if the setting is not defined in the database).
+        //
+        $values = array_merge($values, $override_group);
+      }
+
       $cacheKey = self::setCache($values, $group, $componentID, $contactID, $domainID);
     }
     return $name ? CRM_Utils_Array::value($name, self::$_cache[$cacheKey], $defaultValue) : self::$_cache[$cacheKey];
   }
 
   /**
-   * Store multiple items in the setting table
+   * Store multiple items in the setting table.
    *
-   * @param array $params (required) An api formatted array of keys and values
-   * @param null $domains
+   * @param array $params
+   *   (required) An api formatted array of keys and values.
+   * @param array $domains Array of domains to get settings for. Default is the current domain
    * @param $settingsToReturn
    *
-   * @domains array an array of domains to get settings for. Default is the current domain
-   * @return void
-   * @static
-   * @access public
+   * @return array
    */
-  static function getItems(&$params, $domains = NULL, $settingsToReturn) {
+  public static function getItems(&$params, $domains = NULL, $settingsToReturn) {
     $originalDomain = CRM_Core_Config::domainID();
     if (empty($domains)) {
       $domains[] = $originalDomain;
@@ -274,28 +307,28 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
     $fields = $result = array();
     $fieldsToGet = self::validateSettingsInput(array_flip($settingsToReturn), $fields, FALSE);
     foreach ($domains as $domainID) {
-      if($domainID != CRM_Core_Config::domainID()){
+      if ($domainID != CRM_Core_Config::domainID()) {
         $reloadConfig = TRUE;
         CRM_Core_BAO_Domain::setDomain($domainID);
       }
       $config = CRM_Core_Config::singleton($reloadConfig, $reloadConfig);
       $result[$domainID] = array();
       foreach ($fieldsToGet as $name => $value) {
-        if(!empty($fields['values'][$name]['prefetch'])){
-          if(isset($params['filters']) && isset($params['filters']['prefetch'])
-            && $params['filters']['prefetch'] == 0){
+        if (!empty($fields['values'][$name]['prefetch'])) {
+          if (isset($params['filters']) && isset($params['filters']['prefetch'])
+            && $params['filters']['prefetch'] == 0
+          ) {
             // we are filtering out the prefetches from the return array
             // so we will skip
             continue;
           }
-          $configKey = CRM_Utils_Array::value('config_key', $fields['values'][$name],  $name);
-          if(isset($config->$configKey)){
+          $configKey = CRM_Utils_Array::value('config_key', $fields['values'][$name], $name);
+          if (isset($config->$configKey)) {
             $setting = $config->$configKey;
           }
         }
         else {
-          $setting =
-            CRM_Core_BAO_Setting::getItem(
+          $setting = CRM_Core_BAO_Setting::getItem(
             $fields['values'][$name]['group_name'],
             $name,
             CRM_Utils_Array::value('component_id', $params),
@@ -316,31 +349,34 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Store an item in the setting table
+   * Store an item in the setting table.
    *
    * _setItem() is the common logic shared by setItem() and setItems().
    *
-   * @param object $value (required) The value that will be serialized and stored
-   * @param string $group (required) The group name of the item
-   * @param string $name (required) The name of the setting
-   * @param int $componentID The optional component ID (so componenets can share the same name space)
+   * @param object $value
+   *   (required) The value that will be serialized and stored.
+   * @param string $group
+   *   (required) The group name of the item.
+   * @param string $name
+   *   (required) The name of the setting.
+   * @param int $componentID
+   *   The optional component ID (so componenets can share the same name space).
    * @param int $contactID
-   * @param int $createdID An optional ID to assign the creator to. If not set, retrieved from session
+   * @param int $createdID
+   *   An optional ID to assign the creator to. If not set, retrieved from session.
    *
    * @param int $domainID
    *
    * @return void
-   * @static
-   * @access public
    */
-  static function setItem(
+  public static function setItem(
     $value,
     $group,
     $name,
     $componentID = NULL,
-    $contactID   = NULL,
-    $createdID   = NULL,
-    $domainID    = NULL
+    $contactID = NULL,
+    $createdID = NULL,
+    $domainID = NULL
   ) {
     $fields = array();
     $fieldsToSet = self::validateSettingsInput(array($name => $value), $fields);
@@ -353,11 +389,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Store an item in a setting table
+   * Store an item in a setting table.
    *
    * _setItem() is the common logic shared by setItem() and setItems().
    *
-   * @param array $metadata metadata describing this field
+   * @param array $metadata
+   *   Metadata describing this field.
    * @param $value
    * @param $group
    * @param string $name
@@ -366,15 +403,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $createdID
    * @param int $domainID
    */
-  static function _setItem(
+  public static function _setItem(
     $metadata,
     $value,
     $group,
     $name,
     $componentID = NULL,
-    $contactID   = NULL,
-    $createdID   = NULL,
-    $domainID    = NULL
+    $contactID = NULL,
+    $createdID = NULL,
+    $domainID = NULL
   ) {
     if (empty($domainID)) {
       $domainID = CRM_Core_Config::domainID();
@@ -439,16 +476,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * _setItem() is the common logic shared by setItem() and setItems().
    *
-   * @param array $params (required) An api formatted array of keys and values
+   * @param array $params
+   *   (required) An api formatted array of keys and values.
    * @param null $domains
    *
    * @throws api_Exception
    * @domains array an array of domains to get settings for. Default is the current domain
    * @return array
-   * @static
-   * @access public
    */
-  static function setItems(&$params, $domains = NULL) {
+  public static function setItems(&$params, $domains = NULL) {
     $originalDomain = CRM_Core_Config::domainID();
     if (empty($domains)) {
       $domains[] = $originalDomain;
@@ -462,13 +498,13 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
     }
 
     foreach ($domains as $domainID) {
-      if($domainID != CRM_Core_Config::domainID()){
+      if ($domainID != CRM_Core_Config::domainID()) {
         $reloadConfig = TRUE;
         CRM_Core_BAO_Domain::setDomain($domainID);
       }
       $result[$domainID] = array();
       foreach ($fieldsToSet as $name => $value) {
-        if(empty($fields['values'][$name]['config_only'])){
+        if (empty($fields['values'][$name]['config_only'])) {
           CRM_Core_BAO_Setting::_setItem(
             $fields['values'][$name],
             $value,
@@ -480,22 +516,22 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
             $domainID
           );
         }
-        if(!empty($fields['values'][$name]['prefetch'])){
-          if(!empty($fields['values'][$name]['config_key'])){
+        if (!empty($fields['values'][$name]['prefetch'])) {
+          if (!empty($fields['values'][$name]['config_key'])) {
             $name = $fields['values'][$name]['config_key'];
           }
           $config_keys[$name] = $value;
         }
         $result[$domainID][$name] = $value;
       }
-      if($reloadConfig){
+      if ($reloadConfig) {
         CRM_Core_Config::singleton($reloadConfig, $reloadConfig);
       }
 
-      if(!empty($config_keys)){
+      if (!empty($config_keys)) {
         CRM_Core_BAO_ConfigSetting::create($config_keys);
       }
-      if($reloadConfig){
+      if ($reloadConfig) {
         CRM_Core_BAO_Domain::resetDomain();
       }
     }
@@ -508,14 +544,17 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * This function filters on the fields like 'version' & 'debug' that are not settings
    *
-   * @param array $params Parameters as passed into API
-   * @param array $fields empty array to be populated with fields metadata
+   * @param array $params
+   *   Parameters as passed into API.
+   * @param array $fields
+   *   Empty array to be populated with fields metadata.
    * @param bool $createMode
    *
    * @throws api_Exception
-   * @return array $fieldstoset name => value array of the fields to be set (with extraneous removed)
+   * @return array
+   *   name => value array of the fields to be set (with extraneous removed)
    */
-  static function validateSettingsInput($params, &$fields, $createMode = TRUE) {
+  public static function validateSettingsInput($params, &$fields, $createMode = TRUE) {
     $group = CRM_Utils_Array::value('group', $params);
 
     $ignoredParams = array(
@@ -539,12 +578,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
     );
     $settingParams = array_diff_key($params, array_fill_keys($ignoredParams, TRUE));
     $getFieldsParams = array('version' => 3);
-    if (count($settingParams) ==1) {
+    if (count($settingParams) == 1) {
       // ie we are only setting one field - we'll pass it into getfields for efficiency
       list($name) = array_keys($settingParams);
       $getFieldsParams['name'] = $name;
     }
-    $fields = civicrm_api3('setting','getfields', $getFieldsParams);
+    $fields = civicrm_api3('setting', 'getfields', $getFieldsParams);
     $invalidParams = (array_diff_key($settingParams, $fields['values']));
     if (!empty($invalidParams)) {
       throw new api_Exception(implode(',', array_keys($invalidParams)) . " not valid settings");
@@ -565,16 +604,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @value mixed value of the setting to be set
    * @fieldSpec array Metadata for given field (drawn from the xml)
    */
-  static function validateSetting(&$value, $fieldSpec) {
-    if($fieldSpec['type'] == 'String' && is_array($value)){
-      $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,$value) . CRM_Core_DAO::VALUE_SEPARATOR;
+  public static function validateSetting(&$value, $fieldSpec) {
+    if ($fieldSpec['type'] == 'String' && is_array($value)) {
+      $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $value) . CRM_Core_DAO::VALUE_SEPARATOR;
     }
     if (empty($fieldSpec['validate_callback'])) {
       return TRUE;
     }
     else {
-      list($class,$fn) = explode('::',$fieldSpec['validate_callback']);
-      if (!$class::$fn($value,$fieldSpec)) {
+      list($class, $fn) = explode('::', $fieldSpec['validate_callback']);
+      if (!$class::$fn($value, $fieldSpec)) {
         throw new api_Exception("validation failed for {$fieldSpec['name']} = $value  based on callback {$fieldSpec['validate_callback']}");
       }
     }
@@ -586,7 +625,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @value mixed value of the setting to be set
    * @fieldSpec array Metadata for given field (drawn from the xml)
    */
-  static function validateBoolSetting(&$value, $fieldSpec) {
+  public static function validateBoolSetting(&$value, $fieldSpec) {
     if (!CRM_Utils_Rule::boolean($value)) {
       throw new api_Exception("Boolean value required for {$fieldSpec['name']}");
     }
@@ -613,22 +652,24 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * The following params will filter the result. If none are passed all settings will be returns
    *
-   * @param int $componentID id of relevant component
+   * @param int $componentID
+   *   Id of relevant component.
    * @param array $filters
    * @param int $domainID
    * @param null $profile
    *
-   * @return array $result - the following information as appropriate for each setting
-   * - name
-   * - type
-   * - default
-   * - add (CiviCRM version added)
-   * - is_domain
-   * - is_contact
-   * - description
-   * - help_text
+   * @return array
+   *   the following information as appropriate for each setting
+   *   - name
+   *   - type
+   *   - default
+   *   - add (CiviCRM version added)
+   *   - is_domain
+   *   - is_contact
+   *   - description
+   *   - help_text
    */
-  static function getSettingSpecification(
+  public static function getSettingSpecification(
     $componentID = NULL,
     $filters = array(),
     $domainID = NULL,
@@ -646,10 +687,10 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID);
       if (empty($settingsMetadata)) {
         global $civicrm_root;
-        $metaDataFolders = array($civicrm_root. '/settings');
+        $metaDataFolders = array($civicrm_root . '/settings');
         CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
         $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
-        CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Spec', 'All', $componentID);
+        CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Spec', 'All', $componentID);
       }
       $cached = 0;
     }
@@ -673,8 +714,9 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Load the settings files defined in a series of folders
-   * @param array $metaDataFolders list of folder paths
+   * Load the settings files defined in a series of folders.
+   * @param array $metaDataFolders
+   *   List of folder paths.
    * @return array
    */
   public static function loadSettingsMetaDataFolders($metaDataFolders) {
@@ -691,16 +733,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Load up settings metadata from files
+   * Load up settings metadata from files.
    */
-  static function loadSettingsMetadata($metaDataFolder) {
+  public static function loadSettingsMetadata($metaDataFolder) {
     $settingMetaData = array();
     $settingsFiles = CRM_Utils_File::findFiles($metaDataFolder, '*.setting.php');
     foreach ($settingsFiles as $file) {
       $settings = include $file;
       $settingMetaData = array_merge($settingMetaData, $settings);
     }
-    CRM_Core_BAO_Cache::setItem($settingMetaData,'CiviCRM setting Spec', 'All');
+    CRM_Core_BAO_Cache::setItem($settingMetaData, 'CiviCRM setting Spec', 'All');
     return $settingMetaData;
   }
 
@@ -708,14 +750,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * Filter the settings metadata according to filters passed in. This is a convenience filter
    * and allows selective reverting / filling of settings
    *
-   * @param array $filters Filters to match against data
-   * @param array $settingSpec metadata to filter
+   * @param array $filters
+   *   Filters to match against data.
+   * @param array $settingSpec
+   *   Metadata to filter.
    */
-  static function _filterSettingsSpecification($filters, &$settingSpec) {
+  public static function _filterSettingsSpecification($filters, &$settingSpec) {
     if (empty($filters)) {
       return;
     }
-    else if (array_keys($filters) == array('name')) {
+    elseif (array_keys($filters) == array('name')) {
       $settingSpec = array($filters['name'] => CRM_Utils_Array::value($filters['name'], $settingSpec, ''));
       return;
     }
@@ -730,13 +774,13 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Look for any missing settings and convert them from config or load default as appropriate
+   * Look for any missing settings and convert them from config or load default as appropriate.
    * This should be run from GenCode & also from upgrades to add any new defaults.
    *
    * Multisites have often been overlooked in upgrade scripts so can be expected to be missing
    * a number of settings
    */
-  static function updateSettingsFromMetaData() {
+  public static function updateSettingsFromMetaData() {
     $apiParams = array(
       'version' => 3,
       'domain_id' => 'all',
@@ -763,25 +807,26 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * Note that where the key name is being changed the 'legacy_key' will give us the old name
    */
-  static function convertConfigToSetting($name, $domainID = NULL) {
+  public static function convertConfigToSetting($name, $domainID = NULL) {
     // we have to force this here in case more than one domain is in play.
     // whenever there is a possibility of more than one domain we must force it
     $config = CRM_Core_Config::singleton();
     if (empty($domainID)) {
-      $domainID= CRM_Core_Config::domainID();
+      $domainID = CRM_Core_Config::domainID();
     }
     $domain = new CRM_Core_DAO_Domain();
     $domain->id = $domainID;
     $domain->find(TRUE);
     if ($domain->config_backend) {
       $values = unserialize($domain->config_backend);
-    } else {
+    }
+    else {
       $values = array();
     }
     $spec = self::getSettingSpecification(NULL, array('name' => $name), $domainID);
     $configKey = CRM_Utils_Array::value('config_key', $spec[$name], CRM_Utils_Array::value('legacy_key', $spec[$name], $name));
     //if the key is set to config_only we don't need to do anything
-    if(empty($spec[$name]['config_only'])){
+    if (empty($spec[$name]['config_only'])) {
       if (!empty($values[$configKey])) {
         civicrm_api('setting', 'create', array('version' => 3, $name => $values[$configKey], 'domain_id' => $domainID));
       }
@@ -810,14 +855,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return array
    */
-  static function valueOptions($group,
+  public static function valueOptions(
+    $group,
     $name,
-    $system              = TRUE,
-    $userID              = NULL,
-    $localize            = FALSE,
-    $returnField         = 'name',
+    $system = TRUE,
+    $userID = NULL,
+    $localize = FALSE,
+    $returnField = 'name',
     $returnNameANDLabels = FALSE,
-    $condition           = NULL
+    $condition = NULL
   ) {
     $optionValue = self::getItem($group, $name);
 
@@ -868,11 +914,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $userID
    * @param string $keyField
    */
-  static function setValueOption($group,
+  public static function setValueOption(
+    $group,
     $name,
     $value,
-    $system   = TRUE,
-    $userID   = NULL,
+    $system = TRUE,
+    $userID = NULL,
     $keyField = 'name'
   ) {
     if (empty($value)) {
@@ -890,8 +937,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
 
       if (!empty($cbValues)) {
         $optionValue = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-          array_keys($cbValues)
-        ) . CRM_Core_DAO::VALUE_SEPARATOR;
+            array_keys($cbValues)
+          ) . CRM_Core_DAO::VALUE_SEPARATOR;
       }
       else {
         $optionValue = NULL;
@@ -908,7 +955,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param array $params
    * @param int $domainID
    */
-  static function fixAndStoreDirAndURL(&$params, $domainID = NULL) {
+  public static function fixAndStoreDirAndURL(&$params, $domainID = NULL) {
     if (self::isUpgradeFromPreFourOneAlpha1()) {
       return;
     }
@@ -983,7 +1030,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param array $params
    * @param $group
    */
-  static function storeDirectoryOrURLPreferences(&$params, $group) {
+  public static function storeDirectoryOrURLPreferences(&$params, $group) {
     foreach ($params as $name => $value) {
       // always try to store relative directory or url from CMS root
       $value = ($group == self::DIRECTORY_PREFERENCES_NAME) ? CRM_Utils_File::relativeDirectory($value) : CRM_Utils_System::relativeURL($value);
@@ -996,7 +1043,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param array $params
    * @param bool $setInConfig
    */
-  static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) {
+  public static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) {
     if (CRM_Core_Config::isUpgradeMode()) {
       $isJoomla = (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') ? TRUE : FALSE;
       // hack to set the resource base url so that js/ css etc is loaded correctly
@@ -1019,7 +1066,8 @@ WHERE  ( group_name = %1
 OR       group_name = %2 )
 AND domain_id = %3
 ";
-    $sqlParams = array(1 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'),
+    $sqlParams = array(
+      1 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'),
       2 => array(self::URL_PREFERENCES_NAME, 'String'),
       3 => array(CRM_Core_Config::domainID(), 'Integer'),
     );
@@ -1078,6 +1126,9 @@ AND domain_id = %3
     if ($group && $name && isset($civicrm_setting[$group][$name])) {
       return $civicrm_setting[$group][$name];
     }
+    elseif ($group && !isset($name) && isset($civicrm_setting[$group])) {
+      return $civicrm_setting[$group];
+    }
     else {
       return $default;
     }
@@ -1086,9 +1137,9 @@ AND domain_id = %3
   /**
    * Civicrm_setting didn't exist before 4.1.alpha1 and this function helps taking decisions during upgrade
    *
-   * @return boolean
+   * @return bool
    */
-  static function isUpgradeFromPreFourOneAlpha1() {
+  public static function isUpgradeFromPreFourOneAlpha1() {
     if (CRM_Core_Config::isUpgradeMode()) {
       $currentVer = CRM_Core_BAO_Domain::version();
       if (version_compare($currentVer, '4.1.alpha1') < 0) {
@@ -1097,4 +1148,5 @@ AND domain_id = %3
     }
     return FALSE;
   }
+
 }