Refactor subs_* functions for remote use

The subs_* functions in subs.php have made a lot of assumptions
about users versus profiles. I've refactored the functions to
be methods of the Subscription class instead, and to use Profile
objects throughout.

Some of the checks for blocks or existing subscriptions depended
on users or profiles, so I've moved those methods around a bit.

I've left stubs for the subs_* functions until we get time to replace
them.
This commit is contained in:
Evan Prodromou
2010-02-19 08:16:45 -05:00
parent 48edade751
commit 52e8aa798a
4 changed files with 170 additions and 127 deletions

View File

@@ -80,11 +80,7 @@ class User extends Memcached_DataObject
function isSubscribed($other)
{
assert(!is_null($other));
// XXX: cache results of this query
$sub = Subscription::pkeyGet(array('subscriber' => $this->id,
'subscribed' => $other->id));
return (is_null($sub)) ? false : true;
return Subscription::exists($this->getProfile(), $other);
}
// 'update' won't write key columns, so we have to do it ourselves.
@@ -167,17 +163,8 @@ class User extends Memcached_DataObject
function hasBlocked($other)
{
$block = Profile_block::get($this->id, $other->id);
if (is_null($block)) {
$result = false;
} else {
$result = true;
$block->free();
}
return $result;
$profile = $this->getProfile();
return $profile->hasBlocked($other);
}
/**