/** * 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 int $domainID * * @return mixed * The data if present in the setting table, else null */ public static function getItem($group, $name = NULL, $componentID = NULL, $defaultValue = NULL, $contactID = NULL, $domainID = NULL) { $overrideGroup = array(); if (NULL !== ($override = self::getOverride($group, $name, NULL))) { if (isset($name)) { return $override; } else { $overrideGroup = $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 = CRM_Utils_Array::multiArrayDiff($overrideGroup, self::$_cache[$cacheKey]); if (!empty($valueDifference)) { $cacheKey = ''; } } if (!$cacheKey) { $dao = self::dao($group, NULL, $componentID, $contactID, $domainID); $dao->find(); $values = array(); while ($dao->fetch()) { if (NULL !== ($override = self::getOverride($group, $dao->name, NULL))) { $values[$dao->name] = $override; } elseif ($dao->value) { $values[$dao->name] = unserialize($dao->value); } else { $values[$dao->name] = NULL; } } $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, $overrideGroup); } $cacheKey = self::setCache($values, $group, $componentID, $contactID, $domainID); } return $name ? CRM_Utils_Array::value($name, self::$_cache[$cacheKey], $defaultValue) : self::$_cache[$cacheKey]; }