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 return(sprintf(_m('Group Directory, page %d'), $this->page));
96 return _m('Group directory');
97 } else if ($this->page == 1) {
99 _m('Group directory - %s'),
100 strtoupper($this->filter)
104 _m('Group directory - %s, page %d'),
105 strtoupper($this->filter),
112 * Instructions for use
114 * @return instructions for use
116 function getInstructions()
118 // TRANS: %%site.name%% is the name of the StatusNet site.
120 'Search for groups on %%site.name%% by their name, '
121 . 'location, or interests. Separate the terms by spaces; '
122 . ' they must be 3 characters or more.'
127 * Is this page read-only?
129 * @return boolean true
131 function isReadOnly($args)
137 * Take arguments for running
139 * @param array $args $_REQUEST args
141 * @return boolean success flag
143 function prepare($args)
145 parent::prepare($args);
147 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
148 $this->filter = $this->arg('filter', 'all');
149 $this->reverse = $this->boolean('reverse');
150 $this->q = $this->trimmed('q');
151 $this->sort = $this->arg('sort', 'nickname');
153 common_set_returnto($this->selfUrl());
163 * @param array $args $_REQUEST args; handled in prepare()
167 function handle($args)
169 parent::handle($args);
174 * Show the page notice
176 * Shows instructions for the page
180 function showPageNotice()
182 $instr = $this->getInstructions();
183 $output = common_markup_to_html($instr);
185 $this->elementStart('div', 'instructions');
187 $this->elementEnd('div');
194 * Shows the list of popular notices
198 function showContent()
202 $this->elementStart('div', array('id' => 'group_directory'));
204 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
208 $group = $this->getGroups();
211 if (!empty($group)) {
212 $groupList = new SortableGroupList(
214 common_current_user(),
218 $cnt = $groupList->show();
222 $this->showEmptyListMessage();
227 if (isset($this->q)) {
228 $args['q'] = $this->q;
230 $args['filter'] = $this->filter;
235 $cnt > GROUPS_PER_PAGE,
241 $this->elementEnd('div');
245 function showForm($error=null)
251 'id' => 'form_search',
252 'class' => 'form_settings',
253 'action' => common_local_url('groupdirectory')
257 $this->elementStart('fieldset');
259 $this->element('legend', null, _m('Search groups'));
260 $this->elementStart('ul', 'form_data');
261 $this->elementStart('li');
263 $this->input('q', _m('Keyword(s)'), $this->q);
265 $this->submit('search', _m('BUTTON','Search'));
266 $this->elementEnd('li');
267 $this->elementEnd('ul');
268 $this->elementEnd('fieldset');
269 $this->elementEnd('form');
273 * Get groups filtered by the current filter, sort key,
274 * sort order, and page
278 $group = new User_group();
280 $offset = ($this->page-1) * GROUPS_PER_PAGE;
281 $limit = GROUPS_PER_PAGE + 1;
283 if (isset($this->q)) {
285 $order = 'user_group.created ASC';
287 if ($this->sort == 'nickname') {
288 if ($this->reverse) {
289 $order = 'user_group.nickname DESC';
291 $order = 'user_group.nickname ASC';
294 if ($this->reverse) {
295 $order = 'user_group.created DESC';
299 $sql = <<< GROUP_QUERY_END
302 JOIN local_group ON user_group.id = local_group.group_id
308 $group->query(sprintf($sql, $order, $limit, $offset));
312 // User is browsing via AlphaNav
313 $sort = $this->getSortKey();
315 $sql = <<< GROUP_QUERY_END
318 JOIN local_group ON user_group.id = local_group.group_id
321 switch($this->filter)
328 ' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
332 ' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'',
338 ' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d',
340 $this->reverse ? 'DESC' : 'ASC',
352 * Filter the sort parameter
354 * @return string a column name for sorting
356 function getSortKey()
358 switch ($this->sort) {
371 * Show a nice message when there's no search results
373 function showEmptyListMessage()
375 if (!empty($this->filter) && ($this->filter != 'all')) {
380 _m('No groups starting with %s'),
385 $this->element('p', 'error', _m('No results.'));
386 $message = _m(<<<E_O_T
387 * Make sure all words are spelled correctly.
388 * Try different keywords.
389 * Try more general keywords.
390 * Try fewer keywords.
393 $this->elementStart('div', 'help instructions');
394 $this->raw(common_markup_to_html($message));
395 $this->elementEnd('div');
399 // XXX This needs some adjustment
402 function showSections()
404 $gbp = new GroupsByPostsSection($this);
406 $gbm = new GroupsByMembersSection($this);