]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Allow default data from Profile_prefs::getData call
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 13 Jul 2014 14:26:08 +0000 (16:26 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 13 Jul 2014 14:26:08 +0000 (16:26 +0200)
classes/Profile_prefs.php

index 37ccf4fb9677263aceca5e31f6071282eb4f6680..32da3b11b854da062c3de473b73db7da54b32531 100644 (file)
@@ -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;
     }