Merge pull request #4865 from eileenmcnaughton/my-first-factory
[civicrm-core.git] / CRM / Core / BAO / Setting.php
index a8722e737dabb602e6c7f439bca1a3ee9e01e307..7ab3f5778fc666fb345504b5ec225621dd48c87b 100644 (file)
@@ -66,10 +66,14 @@ 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
@@ -113,7 +117,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   * Allow key o be cleared
   * @param string $cacheKey
   */
-  public static function flushCache($cacheKey){
+  public static function flushCache($cacheKey) {
     unset(self::$_cache[$cacheKey]);
     $globalCache = CRM_Utils_Cache::singleton();
     $globalCache->delete($cacheKey);
@@ -128,7 +132,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return string
    */
-  static function setCache($values,
+  static function setCache(
+    $values,
     $group,
     $componentID = NULL,
     $contactID = NULL,
@@ -157,7 +162,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return CRM_Core_DAO_Domain|CRM_Core_DAO_Setting
    */
-  static function dao($group,
+  static function dao(
+    $group,
     $name        = NULL,
     $componentID = NULL,
     $contactID   = NULL,
@@ -196,11 +202,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   /**
    * 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
    *
@@ -250,7 +261,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   /**
    * Store multiple items in the setting table
    *
-   * @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
    * @param $settingsToReturn
    *
@@ -271,22 +283,22 @@ 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)){
+          if (isset($config->$configKey)) {
             $setting = $config->$configKey;
           }
         }
@@ -317,12 +329,17 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * _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
    *
@@ -353,7 +370,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * _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
@@ -435,7 +453,8 @@ 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
@@ -457,13 +476,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,
@@ -475,22 +494,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();
       }
     }
@@ -503,8 +522,10 @@ 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
@@ -534,7 +555,7 @@ 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;
@@ -561,7 +582,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @fieldSpec array Metadata for given field (drawn from the xml)
    */
   public static function validateSetting(&$value, $fieldSpec) {
-    if($fieldSpec['type'] == 'String' && is_array($value)){
+    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'])) {
@@ -608,7 +629,8 @@ 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
@@ -641,7 +663,7 @@ 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);
@@ -669,7 +691,8 @@ 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
+   * @param array $metaDataFolders
+   *   List of folder paths.
    * @return array
    */
   public static function loadSettingsMetaDataFolders($metaDataFolders) {
@@ -703,14 +726,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.
    */
   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;
     }
@@ -763,20 +788,21 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
     // 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));
       }
@@ -805,7 +831,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return array
    */
-  static function valueOptions($group,
+  static function valueOptions(
+    $group,
     $name,
     $system              = TRUE,
     $userID              = NULL,
@@ -863,7 +890,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $userID
    * @param string $keyField
    */
-  static function setValueOption($group,
+  static function setValueOption(
+    $group,
     $name,
     $value,
     $system   = TRUE,