3 * StatusNet, the distributed open-source microblogging tool
5 * Output a user directory
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2011 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET'))
35 require_once INSTALLDIR . '/lib/publicgroupnav.php';
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class UserdirectoryAction extends Action
49 * @var $page integer the page we're on
51 protected $page = null;
54 * @var $filter string what to filter the search results by
56 protected $filter = null;
61 * @return string Title of the page
65 // @fixme: This looks kinda gross
67 if ($this->filter == 'all') {
68 if ($this->page != 1) {
69 return(sprintf(_m('All users, page %d'), $this->page));
71 return _m('All users');
74 if ($this->page == 1) {
76 _m('Users with nicknames beginning with %s'),
81 _m('Users with nicknames starting with %s, page %d'),
89 * Instructions for use
91 * @return instructions for use
93 function getInstructions()
95 return _('User directory');
99 * Is this page read-only?
101 * @return boolean true
103 function isReadOnly($args)
109 * Take arguments for running
111 * @param array $args $_REQUEST args
113 * @return boolean success flag
115 * @todo move queries from showContent() to here
117 function prepare($args)
119 parent::prepare($args);
121 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
122 $filter = $this->arg('filter');
123 $this->filter = isset($filter) ? $filter : 'all';
124 $this->sort = $this->arg('sort');
125 $this->order = $this->boolean('asc'); // ascending or decending
127 common_set_returnto($this->selfUrl());
137 * @param array $args $_REQUEST args; handled in prepare()
141 function handle($args)
143 parent::handle($args);
148 * Show the page notice
150 * Shows instructions for the page
154 function showPageNotice()
156 $instr = $this->getInstructions();
157 $output = common_markup_to_html($instr);
159 $this->elementStart('div', 'instructions');
161 $this->elementEnd('div');
167 * This page is part of the public group, so show that.
171 function showLocalNav()
173 $nav = new PublicGroupNav($this);
180 * Shows the list of popular notices
184 function showContent()
186 // XXX Need search bar
188 $this->elementStart('div', array('id' => 'user_directory'));
190 $alphaNav = new AlphaNav($this, true, array('All'));
193 // XXX Maybe use a more specialized version of ProfileList here
195 $profile = $this->getUsers();
198 if (!empty($profile)) {
199 $profileList = new SortableSubscriptionList(
201 common_current_user(),
205 $cnt = $profileList->show();
208 $this->showEmptyListMessage();
214 $cnt > PROFILES_PER_PAGE,
217 array('filter' => $this->filter)
220 $this->elementEnd('div');
225 * Get users filtered by the current filter and page
230 $profile = new Profile();
232 $offset = ($this->page - 1) * PROFILES_PER_PAGE;
233 $limit = PROFILES_PER_PAGE + 1;
234 $sort = $this->getSortKey();
235 $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
237 if ($this->filter != 'all') {
239 ' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
245 ' ORDER BY profile.%s %s, profile.nickname DESC LIMIT %d, %d',
247 ($this->order) ? 'ASC' : 'DESC',
252 $profile->query($sql);
258 * Filter the sort parameter
260 * @return string a column name for sorting
262 function getSortKey()
264 switch ($this->sort) {
277 * Show a nice message when there's no search results
279 function showEmptyListMessage()
281 $message = sprintf(_m('No users starting with %s'), $this->filter);
283 $this->elementStart('div', 'guide');
284 $this->raw(common_markup_to_html($message));
285 $this->elementEnd('div');