getTaggedSub-stuff moved to Profile class

This commit is contained in:
Mikael Nordfeldth 2013-10-15 02:00:27 +02:00
parent ffdbd8d729
commit fdbb528e7a
2 changed files with 36 additions and 51 deletions

View File

@ -568,29 +568,50 @@ class Profile extends Managed_DataObject
return $profiles; return $profiles;
} }
function getTaggedSubscribers($tag) function getTaggedSubscribers($tag, $offset=0, $limit=null)
{ {
$qry = $qry =
'SELECT profile.* ' . 'SELECT profile.* ' .
'FROM profile JOIN (subscription, profile_tag, profile_list) ' . 'FROM profile JOIN subscription ' .
'ON profile.id = subscription.subscriber ' . 'ON profile.id = subscription.subscriber ' .
'AND profile.id = profile_tag.tagged ' . 'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' .
'AND profile_tag.tagger = profile_list.tagger AND profile_tag.tag = profile_list.tag ' . 'AND profile_tag.tagger = subscription.subscribed) ' .
'WHERE subscription.subscribed = %d ' . 'WHERE subscription.subscribed = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' . 'AND subscription.subscribed != subscription.subscriber ' .
'AND profile_tag.tagger = %d AND profile_tag.tag = "%s" ' . 'ORDER BY subscription.created DESC ';
'AND profile_list.private = false ' .
'ORDER BY subscription.created DESC'; if ($offset) {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
}
$profile = new Profile(); $profile = new Profile();
$tagged = array();
$cnt = $profile->query(sprintf($qry, $this->id, $this->id, $profile->escape($tag))); $cnt = $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
while ($profile->fetch()) { return $profile;
$tagged[] = clone($profile); }
}
return $tagged; function getTaggedSubscriptions($tag, $offset=0, $limit=null)
{
$qry =
'SELECT profile.* ' .
'FROM profile JOIN subscription ' .
'ON profile.id = subscription.subscribed ' .
'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' .
'AND profile_tag.tagger = subscription.subscriber) ' .
'WHERE subscription.subscriber = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' .
'ORDER BY subscription.created DESC ';
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
$profile = new Profile();
$profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
return $profile;
} }
/** /**

View File

@ -717,48 +717,12 @@ class User extends Managed_DataObject
function getTaggedSubscribers($tag, $offset=0, $limit=null) function getTaggedSubscribers($tag, $offset=0, $limit=null)
{ {
$qry = return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
'SELECT profile.* ' .
'FROM profile JOIN subscription ' .
'ON profile.id = subscription.subscriber ' .
'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' .
'AND profile_tag.tagger = subscription.subscribed) ' .
'WHERE subscription.subscribed = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' .
'ORDER BY subscription.created DESC ';
if ($offset) {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
}
$profile = new Profile();
$cnt = $profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
return $profile;
} }
function getTaggedSubscriptions($tag, $offset=0, $limit=null) function getTaggedSubscriptions($tag, $offset=0, $limit=null)
{ {
$qry = return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
'SELECT profile.* ' .
'FROM profile JOIN subscription ' .
'ON profile.id = subscription.subscribed ' .
'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' .
'AND profile_tag.tagger = subscription.subscriber) ' .
'WHERE subscription.subscriber = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' .
'ORDER BY subscription.created DESC ';
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
$profile = new Profile();
$profile->query(sprintf($qry, $this->id, $profile->escape($tag)));
return $profile;
} }
function hasRight($right) function hasRight($right)