display subscriptions/subscribers as a list

darcs-hash:20081120113839-84dde-169dceadab4d365c81282e8a68a744b7c1aa6a94.gz
This commit is contained in:
Evan Prodromou 2008-11-20 06:38:39 -05:00
parent 383e740920
commit aab4228b53
3 changed files with 61 additions and 50 deletions

View File

@ -36,9 +36,8 @@ class SubscribersAction extends GalleryAction {
} }
} }
function define_subs(&$subs, &$profile) { function fields() {
$subs->subscribed = $profile->id; return array('subscriber', 'subscribed');
$subs->whereAdd('subscriber != ' . $profile->id);
} }
function div_class() { function div_class() {

View File

@ -36,9 +36,8 @@ class SubscriptionsAction extends GalleryAction {
} }
} }
function define_subs(&$subs, &$profile) { function fields() {
$subs->subscriber = $profile->id; return array('subscribed', 'subscriber');
$subs->whereAdd('subscribed != ' . $profile->id);
} }
function div_class() { function div_class() {
@ -48,4 +47,4 @@ class SubscriptionsAction extends GalleryAction {
function get_other(&$subs) { function get_other(&$subs) {
return $subs->subscribed; return $subs->subscribed;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* Laconica - a distributed open-source microblogging tool * Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc. * Copyright (C) 2008, Controlez-Vous, Inc.
@ -31,8 +32,8 @@ class GalleryAction extends Action {
function handle($args) { function handle($args) {
parent::handle($args); parent::handle($args);
$nickname = common_canonical_nickname($this->arg('nickname')); $nickname = common_canonical_nickname($this->arg('nickname'));
$user = User::staticGet('nickname', $nickname); $user = User::staticGet('nickname', $nickname);
if (!$user) { if (!$user) {
@ -48,13 +49,21 @@ class GalleryAction extends Action {
} }
$page = $this->arg('page'); $page = $this->arg('page');
if (!$page) { if (!$page) {
$page = 1; $page = 1;
} }
$display = $this->arg('display');
if (!$display) {
$display = 'list';
}
common_show_header($profile->nickname . ": " . $this->gallery_type(), common_show_header($profile->nickname . ": " . $this->gallery_type(),
NULL, $profile, NULL, $profile,
array($this, 'show_top')); array($this, 'show_top'));
$this->show_gallery($profile, $page); $this->show_gallery($profile, $page, $display);
common_show_footer(); common_show_footer();
} }
@ -67,43 +76,57 @@ class GalleryAction extends Action {
$this->get_instructions($profile)); $this->get_instructions($profile));
} }
function show_gallery($profile, $page) { function show_gallery($profile, $page, $display='list') {
$subs = new Subscription(); $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;
}
$this->define_subs($subs, $profile); # XXX: memcached results
$subs->orderBy('created DESC'); $cnt = $other->query('SELECT profile.* ' .
'FROM profile JOIN subscription ' .
# We ask for an extra one to know if we need to do another page 'ON profile.id = subscription.' . $lst . ' ' .
'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
$subs->limit((($page-1)*AVATARS_PER_PAGE), AVATARS_PER_PAGE + 1); 'AND ' . $lst . ' != ' . $usr . ' ' .
'ORDER BY subscription.created DESC ' .
$subs_count = $subs->find(); $lim);
if ($subs_count == 0) { if ($cnt == 0) {
common_element('p', _('Nobody to show!')); common_element('p', _('Nobody to show!'));
return; 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++) { for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
$result = $subs->fetch(); $other->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;
}
common_element_start('li'); common_element_start('li');
@ -129,16 +152,10 @@ class GalleryAction extends Action {
common_element_end('li'); common_element_end('li');
} }
common_element_end('ul'); common_element_end('ul');
common_pagination($page > 1,
$subs_count > AVATARS_PER_PAGE,
$page,
$this->trimmed('action'),
array('nickname' => $profile->nickname));
} }
function gallery_type() { function gallery_type() {
return NULL; return NULL;
} }
@ -147,11 +164,7 @@ class GalleryAction extends Action {
return NULL; return NULL;
} }
function define_subs(&$subs, &$profile) { function fields() {
return;
}
function get_other(&$subs) {
return NULL; return NULL;
} }