Allow default data from Profile_prefs::getData call

This commit is contained in:
Mikael Nordfeldth 2014-07-13 16:26:08 +02:00
parent 933bf0b026
commit b67a611ca7

View File

@ -112,8 +112,17 @@ class Profile_prefs extends Managed_DataObject
return $pref;
}
static function getData(Profile $profile, $namespace, $topic) {
static function getData(Profile $profile, $namespace, $topic, $def=null) {
try {
$pref = self::getTopic($profile, $namespace, $topic);
} catch (NoResultException $e) {
if ($def === null) {
// If no default value was set, continue the exception.
throw $e;
}
// If there was a default value, return that.
return $def;
}
return $pref->data;
}