public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
- /* Static get */
- function staticGet($k,$v=NULL) {
- return Memcached_DataObject::staticGet('Profile',$k,$v);
- }
-
public static function schemaDef()
{
$def = array(
return $def;
}
-
- function multiGet($keyCol, $keyVals, $skipNulls=true)
- {
- return parent::multiGet('Profile', $keyCol, $keyVals, $skipNulls);
- }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
protected $_user = -1; // Uninitialized value distinct from null
- function getUser()
+ public function getUser()
{
- if (is_int($this->_user) && $this->_user == -1) {
- $this->_user = User::staticGet('id', $this->id);
+ if ($this->_user === -1) {
+ $this->_user = User::getKV('id', $this->id);
+ }
+ if (!($this->_user instanceof User)) {
+ throw new NoSuchUserException(array('id'=>$this->id));
}
return $this->_user;
}
+ public function isLocal()
+ {
+ try {
+ $this->getUser();
+ } catch (NoSuchUserException $e) {
+ return false;
+ }
+ return true;
+ }
+
protected $_avatars;
function getAvatar($width, $height=null)
function getOriginalAvatar()
{
- $avatar = DB_DataObject::factory('avatar');
- $avatar->profile_id = $this->id;
- $avatar->original = true;
- if ($avatar->find(true)) {
+ $pkey = array('profile_id' => $this->id,
+ 'original' => true);
+ $avatar = Avatar::pkeyGet($pkey);
+ if (!empty($avatar)) {
return $avatar;
} else {
return null;
$lists = array();
foreach ($ids as $id) {
- $list = Profile_list::staticGet('id', $id);
+ $list = Profile_list::getKV('id', $id);
if (!empty($list) &&
($showPrivate || !$list->private)) {
$lists = new Profile_list();
$subs = new Profile_tag_subscription();
- $lists->joinAdd('id', 'profile_tag_subscription:profile_tag_id');
+ $lists->joinAdd(array('id', 'profile_tag_subscription:profile_tag_id'));
#@fixme: postgres (round(date_part('epoch', my_date)))
$lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"');
if (Event::handle('StartJoinGroup', array($group, $this))) {
$join = Group_member::join($group->id, $this->id);
self::blow('profile:groups:%d', $this->id);
+ self::blow('group:member_ids:%d', $group->id);
+ self::blow('group:member_count:%d', $group->id);
Event::handle('EndJoinGroup', array($group, $this));
}
}
if (Event::handle('StartLeaveGroup', array($group, $this))) {
Group_member::leave($group->id, $this->id);
self::blow('profile:groups:%d', $this->id);
+ self::blow('group:member_ids:%d', $group->id);
+ self::blow('group:member_count:%d', $group->id);
Event::handle('EndLeaveGroup', array($group, $this));
}
}
$profiles = array();
while ($subs->fetch()) {
- $profile = Profile::staticGet($subs->subscribed);
+ $profile = Profile::getKV($subs->subscribed);
if ($profile) {
$profiles[] = $profile;
}
$profiles = array();
while ($subs->fetch()) {
- $profile = Profile::staticGet($subs->subscriber);
+ $profile = Profile::getKV($subs->subscriber);
if ($profile) {
$profiles[] = $profile;
}
$profile = new Profile();
$tagged = array();
- $cnt = $profile->query(sprintf($qry, $this->id, $this->id, $tag));
+ $cnt = $profile->query(sprintf($qry, $this->id, $this->id, $profile->escape($tag)));
while ($profile->fetch()) {
$tagged[] = clone($profile);
$sub->find();
while ($sub->fetch()) {
- $other = Profile::staticGet('id', $sub->subscribed);
+ $other = Profile::getKV('id', $sub->subscribed);
if (empty($other)) {
continue;
}
$subd->find();
while ($subd->fetch()) {
- $other = Profile::staticGet('id', $subd->subscriber);
+ $other = Profile::getKV('id', $subd->subscriber);
if (empty($other)) {
continue;
}
function silence()
{
$this->grantRole(Profile_role::SILENCED);
- $this->blowRecentNoticeScope();
+ if (common_config('notice', 'hidespam')) {
+ $this->flushVisibility();
+ }
}
function unsilence()
{
$this->revokeRole(Profile_role::SILENCED);
- $this->blowRecentNoticeScope();
+ if (common_config('notice', 'hidespam')) {
+ $this->flushVisibility();
+ }
}
- function blowRecentNoticeScope() {
- $notice = $this->getNotices(0, CachingNoticeStream::CACHE_WINDOW);
- while ($notice->fetch()) {
- self::blow(sprintf('notice:in-scope-for:%d:null', $notice->id));
- }
+ function flushVisibility()
+ {
+ // Get all notices
+ $stream = new ProfileNoticeStream($this, $this);
+ $ids = $stream->getNoticeIds(0, CachingNoticeStream::CACHE_WINDOW);
+ foreach ($ids as $id) {
+ self::blow('notice:in-scope-for:%d:null', $id);
+ }
}
/**
case Right::SILENCEUSER:
case Right::DELETEUSER:
case Right::DELETEGROUP:
+ case Right::TRAINSPAM:
+ case Right::REVIEWSPAM:
$result = $this->hasRole(Profile_role::MODERATOR);
break;
case Right::CONFIGURESITE:
{
// XXX: not really a pkey, but should work
- $notice = Memcached_DataObject::pkeyGet('Notice',
- array('profile_id' => $this->id,
- 'repeat_of' => $notice_id));
+ $notice = Notice::pkeyGet(array('profile_id' => $this->id,
+ 'repeat_of' => $notice_id));
return !empty($notice);
}
if (Event::handle('StartGetProfileUri', array($this, &$uri))) {
// check for a local user first
- $user = User::staticGet('id', $this->id);
+ $user = User::getKV('id', $this->id);
if (!empty($user)) {
$uri = $user->uri;
function hasBlocked($other)
{
- $block = Profile_block::get($this->id, $other->id);
-
- if (empty($block)) {
- $result = false;
- } else {
- $result = true;
- }
-
- return $result;
+ $block = Profile_block::exists($this, $other);
+ return !empty($block);
}
function getAtomFeed()
$feed = null;
if (Event::handle('StartProfileGetAtomFeed', array($this, &$feed))) {
- $user = User::staticGet('id', $this->id);
+ $user = User::getKV('id', $this->id);
if (!empty($user)) {
$feed = common_local_url('ApiTimelineUser', array('id' => $user->id,
'format' => 'atom'));
if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
// Get a local user or remote (OMB 0.1) profile
- $user = User::staticGet('uri', $uri);
+ $user = User::getKV('uri', $uri);
if (!empty($user)) {
$profile = $user->getProfile();
}
{
return $this;
}
-
- static function pivotGet($key, $values, $otherCols=array()) {
- return Memcached_DataObject::pivotGet('Profile', $key, $values, $otherCols);
- }
}