From: Mikael Nordfeldth Date: Tue, 15 Oct 2013 00:00:27 +0000 (+0200) Subject: getTaggedSub-stuff moved to Profile class X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fdbb528e7ad7d887c445807a6fd96f43970f608f;p=quix0rs-gnu-social.git getTaggedSub-stuff moved to Profile class --- diff --git a/classes/Profile.php b/classes/Profile.php index 2f734aafd7..5058fbce68 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -568,29 +568,50 @@ class Profile extends Managed_DataObject return $profiles; } - function getTaggedSubscribers($tag) + function getTaggedSubscribers($tag, $offset=0, $limit=null) { $qry = 'SELECT profile.* ' . - 'FROM profile JOIN (subscription, profile_tag, profile_list) ' . + 'FROM profile JOIN subscription ' . 'ON profile.id = subscription.subscriber ' . - 'AND profile.id = profile_tag.tagged ' . - 'AND profile_tag.tagger = profile_list.tagger AND profile_tag.tag = profile_list.tag ' . + '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 ' . - 'AND profile_tag.tagger = %d AND profile_tag.tag = "%s" ' . - 'AND profile_list.private = false ' . - 'ORDER BY subscription.created DESC'; + 'ORDER BY subscription.created DESC '; + + if ($offset) { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } $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()) { - $tagged[] = clone($profile); - } - return $tagged; + return $profile; + } + + 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; } /** diff --git a/classes/User.php b/classes/User.php index ca3281107e..59cb4e1890 100644 --- a/classes/User.php +++ b/classes/User.php @@ -717,48 +717,12 @@ class User extends Managed_DataObject function getTaggedSubscribers($tag, $offset=0, $limit=null) { - $qry = - '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; + return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit); } 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; + return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit); } function hasRight($right)