From: Mikael Nordfeldth Date: Sun, 13 Jul 2014 14:26:08 +0000 (+0200) Subject: Allow default data from Profile_prefs::getData call X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b67a611ca76a9665f87c1670a2d155dd23ef502a;p=quix0rs-gnu-social.git Allow default data from Profile_prefs::getData call --- diff --git a/classes/Profile_prefs.php b/classes/Profile_prefs.php index 37ccf4fb96..32da3b11b8 100644 --- a/classes/Profile_prefs.php +++ b/classes/Profile_prefs.php @@ -112,8 +112,17 @@ class Profile_prefs extends Managed_DataObject return $pref; } - static function getData(Profile $profile, $namespace, $topic) { - $pref = self::getTopic($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; }