From: Evan Prodromou Date: Thu, 20 Nov 2008 11:38:39 +0000 (-0500) Subject: display subscriptions/subscribers as a list X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aab4228b53c41f9f34200ba69a8f89303fd648f0;p=quix0rs-gnu-social.git display subscriptions/subscribers as a list darcs-hash:20081120113839-84dde-169dceadab4d365c81282e8a68a744b7c1aa6a94.gz --- diff --git a/actions/subscribers.php b/actions/subscribers.php index 2cc82d4571..2e37e03156 100644 --- a/actions/subscribers.php +++ b/actions/subscribers.php @@ -36,9 +36,8 @@ class SubscribersAction extends GalleryAction { } } - function define_subs(&$subs, &$profile) { - $subs->subscribed = $profile->id; - $subs->whereAdd('subscriber != ' . $profile->id); + function fields() { + return array('subscriber', 'subscribed'); } function div_class() { diff --git a/actions/subscriptions.php b/actions/subscriptions.php index 5566acb41d..aebfa22e83 100644 --- a/actions/subscriptions.php +++ b/actions/subscriptions.php @@ -36,9 +36,8 @@ class SubscriptionsAction extends GalleryAction { } } - function define_subs(&$subs, &$profile) { - $subs->subscriber = $profile->id; - $subs->whereAdd('subscribed != ' . $profile->id); + function fields() { + return array('subscribed', 'subscriber'); } function div_class() { @@ -48,4 +47,4 @@ class SubscriptionsAction extends GalleryAction { function get_other(&$subs) { return $subs->subscribed; } -} \ No newline at end of file +} diff --git a/lib/gallery.php b/lib/gallery.php index a478db25d5..4f4de51d81 100644 --- a/lib/gallery.php +++ b/lib/gallery.php @@ -1,4 +1,5 @@ arg('nickname')); - $user = User::staticGet('nickname', $nickname); if (!$user) { @@ -48,13 +49,21 @@ class GalleryAction extends Action { } $page = $this->arg('page'); + if (!$page) { $page = 1; } + + $display = $this->arg('display'); + + if (!$display) { + $display = 'list'; + } + common_show_header($profile->nickname . ": " . $this->gallery_type(), NULL, $profile, array($this, 'show_top')); - $this->show_gallery($profile, $page); + $this->show_gallery($profile, $page, $display); common_show_footer(); } @@ -67,43 +76,57 @@ class GalleryAction extends Action { $this->get_instructions($profile)); } - function show_gallery($profile, $page) { - - $subs = new Subscription(); - - $this->define_subs($subs, $profile); - - $subs->orderBy('created DESC'); - - # We ask for an extra one to know if we need to do another page - - $subs->limit((($page-1)*AVATARS_PER_PAGE), AVATARS_PER_PAGE + 1); - - $subs_count = $subs->find(); + function show_gallery($profile, $page, $display='list') { + + $other = new Profile(); + + list($lst, $usr) = $this->fields(); + + $offset = ($page-1)*AVATARS_PER_PAGE; + $limit = AVATARS_PER_PAGE + 1; + + if (common_config('db','type') == 'pgsql') { + $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $lim = ' LIMIT ' . $offset . ', ' . $limit; + } - if ($subs_count == 0) { + # XXX: memcached results + + $cnt = $other->query('SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.' . $lst . ' ' . + 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . + 'AND ' . $lst . ' != ' . $usr . ' ' . + 'ORDER BY subscription.created DESC ' . + $lim); + + if ($cnt == 0) { common_element('p', _('Nobody to show!')); return; } - common_element_start('ul', $this->div_class()); + if ($display == 'list') { + $profile_list = new ProfileList($other); + $profile_list->show_list(); + } else { + $this->icon_list($profile, $cnt); + } + + common_pagination($page > 1, + $subs_count > AVATARS_PER_PAGE, + $page, + $this->trimmed('action'), + array('nickname' => $profile->nickname)); + } + function icon_list($other, $subs_count) { + + common_element_start('ul', $this->div_class()); + for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) { - $result = $subs->fetch(); - - if (!$result) { - common_debug('Ran out of subscribers too early.', __FILE__); - break; - } - - $other_id = $this->get_other($subs); - $other = Profile::staticGet($other_id); - - if (!$other) { - common_log(LOG_WARNING, 'No matching profile for ' . $other_id); - continue; - } + $other->fetch(); common_element_start('li'); @@ -129,16 +152,10 @@ class GalleryAction extends Action { common_element_end('li'); } - + common_element_end('ul'); - - common_pagination($page > 1, - $subs_count > AVATARS_PER_PAGE, - $page, - $this->trimmed('action'), - array('nickname' => $profile->nickname)); } - + function gallery_type() { return NULL; } @@ -147,11 +164,7 @@ class GalleryAction extends Action { return NULL; } - function define_subs(&$subs, &$profile) { - return; - } - - function get_other(&$subs) { + function fields() { return NULL; }