From 26bc168c93731c82e95795efa38df60af49b2604 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 12:19:47 -0500 Subject: [PATCH] An action for showing groups a user is in --- actions/usergroups.php | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 actions/usergroups.php diff --git a/actions/usergroups.php b/actions/usergroups.php new file mode 100644 index 0000000000..62ad3b3a2e --- /dev/null +++ b/actions/usergroups.php @@ -0,0 +1,130 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('GROUPS_PER_PAGE', 20); + +/** + * User groups page + * + * Show the groups a user belongs to + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class UsergroupsAction extends Action +{ + var $user = null; + var $page = null; + var $profile = null; + + function title() + { + if ($this->page == 1) { + return sprintf(_("%s groups"), $this->user->nickname); + } else { + return sprintf(_("%s groups, page %d"), + $this->user->nickname, + $this->page); + } + } + + function prepare($args) + { + parent::prepare($args); + + $nickname_arg = $this->arg('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + if ($this->arg('page') && $this->arg('page') != 1) { + $args['page'] = $this->arg['page']; + } + common_redirect(common_local_url('usergroups', $args), 301); + return false; + } + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return false; + } + + $this->profile = $this->user->getProfile(); + + if (!$this->profile) { + $this->serverError(_('User has no profile.')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + return true; + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showLocalNav() + { + // XXX: Add to the subscriptions tabset + } + + function showContent() + { + $offset = ($this->page-1) * GROUPS_PER_PAGE; + $limit = GROUPS_PER_PAGE + 1; + + $groups = $this->user->getGroups($offset, $limit); + + if ($groups) { + $gl = new GroupList($groups, $this->user, $this); + $cnt = $gl->show(); + } + + $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, + $this->page, 'usergroups', + array('nickname' => $this->user->nickname)); + } +}