]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Subscription stream functions
[quix0rs-gnu-social.git] / classes / Profile.php
index 8dbdcbd97385395f78bdaac90c41a21226f8b998..239c368ca19fb0451369921ca0445594f440f91c 100644 (file)
@@ -380,54 +380,32 @@ class Profile extends Memcached_DataObject
 
     function getSubscriptions($offset=0, $limit=null)
     {
-        $qry =
-          'SELECT profile.* ' .
-          'FROM profile JOIN subscription ' .
-          'ON profile.id = subscription.subscribed ' .
-          'WHERE subscription.subscriber = %d ' .
-          'AND subscription.subscribed != subscription.subscriber ' .
-          'ORDER BY subscription.created DESC ';
-
-        if ($offset>0 && !is_null($limit)){
-            if (common_config('db','type') == 'pgsql') {
-                $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-            } else {
-                $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-            }
-        }
+        $subs = Subscription::bySubscriber($this->id,
+                                           $offset,
+                                           $limit);
 
-        $profile = new Profile();
+        $profiles = array();
 
-        $profile->query(sprintf($qry, $this->id));
+        while ($subs->fetch()) {
+            $profiles[] = Profile::staticGet($subs->subscribed);
+        }
 
-        return $profile;
+        return new ArrayWrapper($profiles);
     }
 
     function getSubscribers($offset=0, $limit=null)
     {
-        $qry =
-          'SELECT profile.* ' .
-          'FROM profile JOIN subscription ' .
-          'ON profile.id = subscription.subscriber ' .
-          'WHERE subscription.subscribed = %d ' .
-          'AND subscription.subscribed != subscription.subscriber ' .
-          'ORDER BY subscription.created DESC ';
-
-        if ($offset>0 && !is_null($limit)){
-            if ($offset) {
-                if (common_config('db','type') == 'pgsql') {
-                    $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-                } else {
-                    $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-                }
-            }
-        }
+        $subs = Subscription::bySubscribed($this->id,
+                                           $offset,
+                                           $limit);
 
-        $profile = new Profile();
+        $profiles = array();
 
-        $cnt = $profile->query(sprintf($qry, $this->id));
+        while ($subs->fetch()) {
+            $profiles[] = Profile::staticGet($subs->subscriber);
+        }
 
-        return $profile;
+        return new ArrayWrapper($profiles);
     }
 
     function getConnectedApps($offset = 0, $limit = null)