Commit 558e6f27 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use ajax pagination, paginator.js on find friends page


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 4942c941
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require('searchlib.php');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
$data['query'] = $query;
build_userlist_html($data, 'find');
log_debug($data);
json_reply(false, array('data' => $data));
?>
......@@ -1119,6 +1119,31 @@ function get_users_data($userlist, $getviews=true) {
return $ordereddata;
}
function build_userlist_html(&$data, $page) {
if ($data['data']) {
$userlist = join(',', array_map(create_function('$u','return $u[\'id\'];'), $data['data']));
$userdata = get_users_data($userlist, $page == 'myfriends');
}
$smarty = smarty_core();
$smarty->assign('data', isset($userdata) ? $userdata : null);
$smarty->assign('page', $page);
$smarty->assign('query', $data['query']);
$data['tablerows'] = $smarty->fetch('user/userresults.tpl');
$pagination = build_pagination(array(
'id' => 'friendslist_pagination',
'url' => get_config('wwwroot') . 'user/' . $page . '.php?query=' . $data['query'],
'jsonscript' => 'json/friendsearch.php',
'datatable' => 'friendslist',
'count' => $data['count'],
'limit' => $data['limit'],
'offset' => $data['offset'],
'resultcounttextsingular' => get_string('user', 'group'),
'resultcounttextplural' => get_string('users', 'group'),
));
$data['pagination'] = $pagination['html'];
$data['pagination_js'] = $pagination['javascript'];
}
function get_institution_string_for_user($userid) {
static $institutions = null;
if (is_null($institutions)) {
......
{include file="header.tpl"}
<div id="friendslistcontainer">
{$form}
{if $users}
<table id="friendslist" class="fullwidth listing">
<tbody>
{foreach from=$users item=user}
<tr class="r{cycle values=1,0}">
{include file="user/user.tpl" user=$user page='find'}
</tr>
{/foreach}
{$results.tablerows}
</tbody>
</table>
</div>
{$pagination}
{elseif $message}
<div class="message">{$message}</div>
{/if}
{$results.pagination}
</div>
{include file="footer.tpl"}
{if $data}
{foreach from=$data item=user}
<tr class="r{cycle values=1,0}">
{include file="user/user.tpl" user=$user page=$page}
</tr>
{/foreach}
{elseif $query}
<tr><td><div class="message">{str tag=nosearchresultsfound section=group}</div></td></tr>
{/if}
\ No newline at end of file
......@@ -38,11 +38,10 @@ $offset = param_integer('offset', 0);
$limit = 10;
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
$data['query'] = $query;
build_userlist_html($data, 'find');
if ($data['data']) {
$userlist = join(',', array_map(create_function('$u','return $u[\'id\'];'), $data['data']));
$data['data'] = get_users_data($userlist, false);
}
$js = 'addLoadEvent(function () {' . $data['pagination_js'] . '});';
$searchform = pieform(array(
'name' => 'search',
......@@ -59,28 +58,11 @@ $searchform = pieform(array(
)
));
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'user/find.php?query=' . $query,
'count' => $data['count'],
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('user', 'group'),
'resultcounttextplural' => get_string('users', 'group'),
));
if ($query && !$data['count']) {
// Search run, no results
$message = get_string('nosearchresultsfound', 'group');
}
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(friends_control_sideblock('find'))));
$smarty = smarty(array('paginator'), array(), array(), array('sideblocks' => array(friends_control_sideblock('find'))));
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('users', $data['data']);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('results', $data);
$smarty->assign('form', $searchform);
$smarty->assign('pagination', $pagination['html']);
if (isset($message)) {
$smarty->assign('message', $message);
}
$smarty->display('user/find.tpl');
function search_submit(Pieform $form, $values) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment