]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Non-dynamic profile fetching in User and User_group
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 5 Jun 2014 22:19:54 +0000 (00:19 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 5 Jun 2014 22:19:54 +0000 (00:19 +0200)
classes/User.php
classes/User_group.php

index 3e2873c75fe36cc8a07d69d36da1f9efc2c29560..c23b0a0b0ae98f800e76fc5f2da25a9840ca0800 100644 (file)
@@ -113,7 +113,7 @@ class User extends Managed_DataObject
         );
     }
 
-    protected $_profile = null;
+    protected $_profile = array();
 
     /**
      * @return Profile
@@ -122,14 +122,18 @@ class User extends Managed_DataObject
      */
     public function getProfile()
     {
-        if (!($this->_profile instanceof Profile)) {
-            $this->_profile = Profile::getKV('id', $this->id);
-            if (!($this->_profile instanceof Profile)) {
-                throw new UserNoProfileException($this);
-            }
+        if (!isset($this->_profile[$this->id])) {
+            $this->_setProfile(Profile::getKV('id', $this->id));
         }
+        return $this->_profile[$this->id];
+    }
 
-        return $this->_profile;
+    public function _setProfile(Profile $profile=null)
+    {
+        if (!$profile instanceof Profile) {
+            throw new UserNoProfileException($this);
+        }
+        $this->_profile[$this->id] = $profile;
     }
 
     public function getUri()
index 762b4466016f8f16c7ee530f79759ee2e9296fad..a9dfacd49811a3541a257cd276d986795d6c2d7b 100644 (file)
@@ -74,23 +74,27 @@ class User_group extends Managed_DataObject
         );
     }
 
-    protected $_profile = null;
+    protected $_profile = array();
 
     /**
      * @return Profile
      *
-     * @throws UserNoProfileException if user has no profile
+     * @throws GroupNoProfileException if user has no profile
      */
     public function getProfile()
     {
-        if (!($this->_profile instanceof Profile)) {
-            $this->_profile = Profile::getKV('id', $this->profile_id);
-            if (!($this->_profile instanceof Profile)) {
-                throw new GroupNoProfileException($this);
-            }
+        if (!isset($this->_profile[$this->profile_id])) {
+            $this->_setProfile(Profile::getKV('id', $this->profile_id));
         }
+        return $this->_profile[$this->profile_id];
+    }
 
-        return $this->_profile;
+    public function _setProfile(Profile $profile=null)
+    {
+        if (!$profile instanceof Profile) {
+            throw new GroupNoProfileException($this);
+        }
+        $this->_profile[$this->profile_id] = $profile;
     }
 
     public static function defaultLogo($size)