Merge pull request #4962 from totten/master-angular-ts
[civicrm-core.git] / CRM / Core / BAO / Setting.php
index 7ab3f5778fc666fb345504b5ec225621dd48c87b..f42e66c6f98d669ea54e30e687285f4204205970 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -79,15 +79,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $domainID
    * @param bool $force
    *
-   * @return boolean true if item is already in cache
-   * @static
+   * @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
   ) {
@@ -113,10 +113,11 @@ 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
-  */
+   * Allow key o be cleared
+   * @param string $cacheKey
+   */
   public static function flushCache($cacheKey) {
     unset(self::$_cache[$cacheKey]);
     $globalCache = CRM_Utils_Cache::singleton();
@@ -132,7 +133,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return string
    */
-  static function setCache(
+  public static function setCache(
     $values,
     $group,
     $componentID = NULL,
@@ -162,11 +163,11 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return CRM_Core_DAO_Domain|CRM_Core_DAO_Setting
    */
-  static function dao(
+  public static function dao(
     $group,
-    $name        = NULL,
+    $name = NULL,
     $componentID = NULL,
-    $contactID   = NULL,
+    $contactID = NULL,
     $domainID = NULL
   ) {
     if (self::isUpgradeFromPreFourOneAlpha1()) {
@@ -178,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;
@@ -215,16 +216,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @param int $domainID
    *
-   * @return mixed The data if present in the setting table, else null
-   * @static
+   * @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
   ) {
 
     if (NULL !== ($override = self::getOverride($group, $name, NULL))) {
@@ -268,7 +269,6 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @domains array an array of domains to get settings for. Default is the current domain
    * @return void
-   * @static
    */
   public static function getItems(&$params, $domains = NULL, $settingsToReturn) {
     $originalDomain = CRM_Core_Config::domainID();
@@ -292,19 +292,19 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       foreach ($fieldsToGet as $name => $value) {
         if (!empty($fields['values'][$name]['prefetch'])) {
           if (isset($params['filters']) && isset($params['filters']['prefetch'])
-            && $params['filters']['prefetch'] == 0) {
+            && $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);
+          $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),
@@ -344,16 +344,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $domainID
    *
    * @return void
-   * @static
    */
-  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);
@@ -380,15 +379,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();
@@ -460,7 +459,6 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @throws api_Exception
    * @domains array an array of domains to get settings for. Default is the current domain
    * @return array
-   * @static
    */
   public static function setItems(&$params, $domains = NULL) {
     $originalDomain = CRM_Core_Config::domainID();
@@ -529,7 +527,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @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)
    */
   public static function validateSettingsInput($params, &$fields, $createMode = TRUE) {
     $group = CRM_Utils_Array::value('group', $params);
@@ -560,7 +559,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       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");
@@ -583,14 +582,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    */
   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;
+      $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']}");
       }
     }
@@ -635,17 +634,18 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @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,
@@ -666,7 +666,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
         $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;
     }
@@ -718,7 +718,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       $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;
   }
 
@@ -831,15 +831,15 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return array
    */
-  static function valueOptions(
+  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);
 
@@ -890,12 +890,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $userID
    * @param string $keyField
    */
-  static function setValueOption(
+  public static function setValueOption(
     $group,
     $name,
     $value,
-    $system   = TRUE,
-    $userID   = NULL,
+    $system = TRUE,
+    $userID = NULL,
     $keyField = 'name'
   ) {
     if (empty($value)) {
@@ -913,8 +913,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;
@@ -1042,7 +1042,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'),
     );
@@ -1109,7 +1110,7 @@ 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
    */
   public static function isUpgradeFromPreFourOneAlpha1() {
     if (CRM_Core_Config::isUpgradeMode()) {
@@ -1120,4 +1121,5 @@ AND domain_id = %3
     }
     return FALSE;
   }
+
 }