X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FProfile.php;h=3b3e43025ba7189b0c1f3ce558bdd0cd0bc8d483;hb=2892f70d18065e1478c729f2de96218c9500e2df;hp=7f45031f6655a9ea8f0e9198ac83c68470c75b7c;hpb=a844c423a9a8408eb79a01763b632c2e1390ad9e;p=quix0rs-gnu-social.git diff --git a/classes/Profile.php b/classes/Profile.php index 7f45031f66..3b3e43025b 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -103,41 +103,61 @@ class Profile extends Managed_DataObject return $this->_user; } - protected $_avatars; - + protected $_avatars; + function getAvatar($width, $height=null) { if (is_null($height)) { $height = $width; } - if (!isset($this->_avatars)) { - $this->_avatars = array(); - } + $avatar = $this->_getAvatar($width); + + if (empty($avatar)) { - if (array_key_exists($width, $this->_avatars)) { - return $this->_avatars[$width]; - } - - $avatar = null; + if (Event::handle('StartProfileGetAvatar', array($this, $width, &$avatar))) { + $avatar = Avatar::pkeyGet( + array( + 'profile_id' => $this->id, + 'width' => $width, + 'height' => $height + ) + ); + Event::handle('EndProfileGetAvatar', array($this, $width, &$avatar)); + } - if (Event::handle('StartProfileGetAvatar', array($this, $width, &$avatar))) { - $avatar = Avatar::pkeyGet(array('profile_id' => $this->id, - 'width' => $width, - 'height' => $height)); - Event::handle('EndProfileGetAvatar', array($this, $width, &$avatar)); + $this->_fillAvatar($width, $avatar); } - $this->_avatars[$width] = $avatar; - return $avatar; } - function _fillAvatar($width, $avatar) - { - $this->_avatars[$width] = $avatar; - } - + // XXX: @Fix me gargargar + function _getAvatar($width) + { + if (empty($this->_avatars)) { + $this->_avatars = array(); + } + + // GAR! I cannot figure out where _avatars gets pre-filled with the avatar from + // the previously used profile! Please shoot me now! --Zach + if (array_key_exists($width, $this->_avatars)) { + // Don't return cached avatar unless it's really for this profile + if ($this->_avatars[$width]->profile_id == $this->id) { + return $this->_avatars[$width]; + } + } + + return null; + } + + function _fillAvatar($width, $avatar) + { + //common_debug("Storing avatar of width: {$avatar->width} and profile_id {$avatar->profile_id} in profile {$this->id}."); + $this->_avatars[$width] = $avatar; + + } + function getOriginalAvatar() { $avatar = DB_DataObject::factory('avatar'); @@ -330,6 +350,10 @@ class Profile extends Managed_DataObject self::cacheSet($keypart, implode(',', $ids)); } + if (!is_null($offset) && !is_null($limit)) { + $ids = array_slice($ids, $offset, $limit); + } + return User_group::multiGet('id', $ids); } @@ -436,42 +460,55 @@ class Profile extends Managed_DataObject return new ArrayWrapper($lists); } + /** + * Get tags that other people put on this profile, in reverse-chron order + * + * @param (Profile|User) $auth_user Authorized user (used for privacy) + * @param int $offset Offset from latest + * @param int $limit Max number to get + * @param datetime $since_id max date + * @param datetime $max_id min date + * + * @return Profile_list resulting lists + */ + function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0) { - $lists = new Profile_list(); + $list = new Profile_list(); - $tags = new Profile_tag(); - $tags->tagged = $this->id; + $qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' . + 'from profile_tag join profile_list '. + 'on (profile_tag.tagger = profile_list.tagger ' . + ' and profile_tag.tag = profile_list.tag) ' . + 'where profile_tag.tagged = %d ', + $this->id); - $lists->joinAdd($tags); - - #@fixme: postgres (round(date_part('epoch', my_date))) - $lists->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"'); if ($auth_user instanceof User || $auth_user instanceof Profile) { - $lists->whereAdd('( ( profile_list.private = false ) ' . - 'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' . - 'profile_list.private = true ) )'); + $qry .= sprintf('AND ( ( profile_list.private = false ) ' . + 'OR ( profile_list.tagger = %d AND ' . + 'profile_list.private = true ) )', + $auth_user->id); } else { - $lists->private = false; + $qry .= 'AND profile_list.private = 0 '; } - if ($since_id>0) { - $lists->whereAdd('cursor > '.$since_id); + if ($since_id > 0) { + $qry .= sprintf('AND (cursor > %d) ', $since_id); } - if ($max_id>0) { - $lists->whereAdd('cursor <= '.$max_id); + if ($max_id > 0) { + $qry .= sprintf('AND (cursor < %d) ', $max_id); } - if($offset>=0 && !is_null($limit)) { - $lists->limit($offset, $limit); - } + $qry .= 'ORDER BY profile_tag.modified DESC '; - $lists->orderBy('profile_tag.modified DESC'); - $lists->find(); + if ($offset >= 0 && !is_null($limit)) { + $qry .= sprintf('LIMIT %d OFFSET %d ', $limit, $offset); + } - return $lists; + $list->query($qry); + return $list; } function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0) @@ -1441,4 +1478,8 @@ class Profile extends Managed_DataObject { return $this; } + + static function pivotGet($key, $values, $otherCols=array()) { + return Memcached_DataObject::pivotGet('Profile', $key, $values, $otherCols); + } }