3 * StatusNet, the distributed open-source microblogging tool
5 * Output a group 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 GroupdirectoryAction extends Action
56 * What to filter the search results by
70 * How to order search results, ascending or descending
86 * @return string Title of the page
90 // @fixme: This looks kinda gross
92 if ($this->filter == 'all') {
93 if ($this->page != 1) {
94 // TRANS: Title for group directory page. %d is a page number.
95 return(sprintf(_m('Group Directory, page %d'), $this->page));
97 // TRANS: Title for group directory page.
98 return _m('Group directory');
99 } else if ($this->page == 1) {
101 // TRANS: Title for group directory page when it is filtered.
102 // TRANS: %s is the filter string.
103 _m('Group directory - %s'),
104 strtoupper($this->filter)
108 // TRANS: Title for group directory page when it is filtered.
109 // TRANS: %1$s is the filter string, %2$d is a page number.
110 _m('Group directory - %1$s, page %2$d'),
111 strtoupper($this->filter),
118 * Instructions for use
120 * @return instructions for use
122 function getInstructions()
124 // TRANS: Page instructions.
125 return _m("After you join a group you can send messages to all other members\n".
126 "using the syntax \"!groupname\".\n\n".
127 "Browse groups, or search for groups by their name, location or topic.\n".
128 "Separate the terms by spaces; they must be three characters or more.") . "\n";
132 * Is this page read-only?
134 * @return boolean true
136 function isReadOnly($args)
142 * Take arguments for running
144 * @param array $args $_REQUEST args
146 * @return boolean success flag
148 function prepare($args)
150 parent::prepare($args);
152 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
153 $this->filter = $this->arg('filter', 'all');
154 $this->reverse = $this->boolean('reverse');
155 $this->q = $this->trimmed('q');
156 $this->sort = $this->arg('sort', 'nickname');
158 common_set_returnto($this->selfUrl());
168 * @param array $args $_REQUEST args; handled in prepare()
172 function handle($args)
174 parent::handle($args);
179 * Show the page notice
181 * Shows instructions for the page
185 function showPageNotice()
187 $instr = $this->getInstructions();
188 $output = common_markup_to_html($instr);
190 $this->elementStart('div', 'instructions');
192 $this->elementEnd('div');
203 function showContent()
205 if (common_logged_in()) {
215 'href' => common_local_url('newgroup'),
217 // TRANS: Link to create a new group on the group list page.
218 _m('Create a new group')
220 $this->elementEnd('p');
225 $this->elementStart('div', array('id' => 'profile_directory'));
227 // @todo FIXME: Does "All" need i18n here?
228 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
232 $group = $this->getGroups();
235 if (!empty($group)) {
236 $groupList = new SortableGroupList(
238 common_current_user(),
242 $cnt = $groupList->show();
246 $this->showEmptyListMessage();
251 if (isset($this->q)) {
252 $args['q'] = $this->q;
254 $args['filter'] = $this->filter;
259 $cnt > PROFILES_PER_PAGE,
265 $this->elementEnd('div');
268 function showForm($error=null)
274 'id' => 'form_search',
275 'class' => 'form_settings',
276 'action' => common_local_url('groupdirectory')
280 $this->elementStart('fieldset');
282 // TRANS: Fieldset legend.
283 $this->element('legend', null, _m('Search groups'));
284 $this->elementStart('ul', 'form_data');
285 $this->elementStart('li');
287 // TRANS: Field label for input of one or more keywords.
288 $this->input('q', _m('Keyword(s)'), $this->q);
290 // TRANS: Button text for searching group directory.
291 $this->submit('search', _m('BUTTON','Search'));
292 $this->elementEnd('li');
293 $this->elementEnd('ul');
294 $this->elementEnd('fieldset');
295 $this->elementEnd('form');
299 * Get groups filtered by the current filter, sort key,
300 * sort order, and page
304 $group = new User_group();
306 $offset = ($this->page-1) * PROFILES_PER_PAGE;
307 $limit = PROFILES_PER_PAGE + 1;
309 if (isset($this->q)) {
311 $order = 'user_group.created ASC';
313 if ($this->sort == 'nickname') {
314 if ($this->reverse) {
315 $order = 'user_group.nickname DESC';
317 $order = 'user_group.nickname ASC';
320 if ($this->reverse) {
321 $order = 'user_group.created DESC';
325 $sql = <<< GROUP_QUERY_END
328 JOIN local_group ON user_group.id = local_group.group_id
334 $group->query(sprintf($sql, $order, $limit, $offset));
338 // User is browsing via AlphaNav
339 $sort = $this->getSortKey();
341 $sql = <<< GROUP_QUERY_END
344 JOIN local_group ON user_group.id = local_group.group_id
347 switch($this->filter)
354 ' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
358 ' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'',
364 ' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d',
366 $this->reverse ? 'DESC' : 'ASC',
378 * Filter the sort parameter
380 * @return string a column name for sorting
382 function getSortKey()
384 switch ($this->sort) {
397 * Show a nice message when there's no search results
399 function showEmptyListMessage()
401 if (!empty($this->filter) && ($this->filter != 'all')) {
406 // TRANS: Empty list message for searching group directory.
407 // TRANS: %s is the search string.
408 _m('No groups starting with %s.'),
413 // TRANS: Empty list message for searching group directory.
414 $this->element('p', 'error', _m('No results.'));
415 // TRANS: Help text for searching group directory.
416 $message = _m("* Make sure all words are spelled correctly.\n".
417 "* Try different keywords.\n".
418 "* Try more general keywords.\n".
419 "* Try fewer keywords.");
420 $this->elementStart('div', 'help instructions');
421 $this->raw(common_markup_to_html($message));
422 $this->elementEnd('div');
426 function showSections()
428 $gbp = new GroupsByPostsSection($this);
430 $gbm = new GroupsByMembersSection($this);