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
53 protected $page = null;
56 * what to filter the search results by
60 protected $filter = null;
65 * @return string Title of the page
69 // @fixme: This looks kinda gross
71 if ($this->filter == 'all') {
72 if ($this->page != 1) {
73 return(sprintf(_m('All users, page %d'), $this->page));
75 return _m('All users');
78 if ($this->page == 1) {
80 _m('Users with nicknames beginning with %s'),
85 _m('Users with nicknames starting with %s, page %d'),
93 * Instructions for use
95 * @return instructions for use
97 function getInstructions()
99 return _('User directory');
103 * Is this page read-only?
105 * @return boolean true
107 function isReadOnly($args)
113 * Take arguments for running
115 * @param array $args $_REQUEST args
117 * @return boolean success flag
119 function prepare($args)
121 parent::prepare($args);
123 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
124 $filter = $this->arg('filter');
125 $this->filter = isset($filter) ? $filter : 'all';
126 $this->sort = $this->arg('sort');
127 $this->order = $this->boolean('asc'); // ascending or decending
129 common_set_returnto($this->selfUrl());
139 * @param array $args $_REQUEST args; handled in prepare()
143 function handle($args)
145 parent::handle($args);
150 * Show the page notice
152 * Shows instructions for the page
156 function showPageNotice()
158 $instr = $this->getInstructions();
159 $output = common_markup_to_html($instr);
161 $this->elementStart('div', 'instructions');
163 $this->elementEnd('div');
169 * This page is part of the public group, so show that.
173 function showLocalNav()
175 $nav = new PublicGroupNav($this);
182 * Shows the list of popular notices
186 function showContent()
188 // XXX Need search bar
190 $this->elementStart('div', array('id' => 'user_directory'));
192 $alphaNav = new AlphaNav($this, true, array('All'));
195 // XXX Maybe use a more specialized version of ProfileList here
197 $profile = $this->getUsers();
200 if (!empty($profile)) {
201 $profileList = new SortableSubscriptionList(
203 common_current_user(),
207 $cnt = $profileList->show();
210 $this->showEmptyListMessage();
216 $cnt > PROFILES_PER_PAGE,
219 array('filter' => $this->filter)
222 $this->elementEnd('div');
227 * Get users filtered by the current filter, sort key,
228 * sort order, and page
233 $profile = new Profile();
235 $offset = ($this->page - 1) * PROFILES_PER_PAGE;
236 $limit = PROFILES_PER_PAGE + 1;
237 $sort = $this->getSortKey();
238 $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
240 if ($this->filter != 'all') {
242 ' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
248 ' ORDER BY profile.%s %s, profile.nickname DESC LIMIT %d, %d',
250 ($this->order) ? 'ASC' : 'DESC',
255 $profile->query($sql);
261 * Filter the sort parameter
263 * @return string a column name for sorting
265 function getSortKey()
267 switch ($this->sort) {
280 * Show a nice message when there's no search results
282 function showEmptyListMessage()
284 $message = sprintf(_m('No users starting with **%s**'), $this->filter);
286 $this->elementStart('div', 'guide');
287 $this->raw(common_markup_to_html($message));
288 $this->elementEnd('div');