Commit 117ab531 authored by Robert Lyon's avatar Robert Lyon

Bug 1515484: Fix some more places where pagination is wrong

Includes:
1) Group -> my groups
2) Group -> find groups
3) Admin -> Users -> Suspended ...
4) Admin -> Group
5) Content -> Journal -> entries list

This is also to standardize pagination

behatnotneeded

Change-Id: Iad9edc668b3f5f8e8c71408c842cbf28a69fa2f4
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent b86741d1
......@@ -21,7 +21,7 @@ require_once('searchlib.php');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = 10;
$limit = param_integer('limit', 10);
$data = build_grouplist_html($query, $limit, $offset, $count);
$data['count'] = $count;
......
......@@ -22,7 +22,14 @@ require_once('searchlib.php');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = 10;
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$data = build_grouplist_html($query, $limit, $offset);
......
......@@ -19,6 +19,7 @@ require_once('pieforms/pieform.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$type = param_alpha('type', 'suspended');
$setlimit = param_boolean('setlimit', false);
// Filter for institutional admins:
$instsql = $USER->get('admin') ? '' : '
......@@ -76,9 +77,28 @@ else {
}
}
$smarty = smarty_core();
$smarty->assign('data', $data);
$html = $smarty->fetch('admin/users/suspendresults.tpl');
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'admin/users/suspended.php?type=' . $type,
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => $setlimit,
'datatable' => 'suspendedlist',
'jsonscript' => 'admin/users/suspended.json.php',
));
json_reply(false, array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data
'data' => array(
'tablerows' => $html,
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
'count' => $count,
'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')),
'offset' => $offset,
'setlimit' => $setlimit,
)
));
......@@ -19,9 +19,10 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'suspendedusers');
require_once('pieforms/pieform.php');
$type = param_alpha('type', 'suspended') == 'expired' ? 'expired' : 'suspended';
$type = param_alpha('type', 'suspended');
$enc_type = json_encode($type);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$typeform = pieform(
array(
'name' => 'usertype',
......@@ -45,41 +46,117 @@ $typeform = pieform(
)
);
$smarty = smarty(array('tablerenderer'));
// Filter for institutional admins:
$instsql = $USER->get('admin') ? '' : '
AND ui.institution IN (' . join(',', array_map('db_quote', array_keys($USER->get('institutions')))) . ')';
$count = get_field_sql('
SELECT COUNT(*)
FROM (
SELECT u.id
FROM {usr} u
LEFT OUTER JOIN {usr_institution} ui ON (ui.usr = u.id)
WHERE ' . ($type == 'expired' ? 'u.expiry < current_timestamp' : 'suspendedcusr IS NOT NULL') . '
AND deleted = 0 ' . $instsql . '
GROUP BY u.id
) AS a');
$data = get_records_sql_assoc('
SELECT
u.id, u.firstname, u.lastname, u.studentid, u.suspendedctime, u.suspendedreason AS reason,
ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname, ' . db_format_tsfield('u.expiry', 'expiry') . '
FROM {usr} u
LEFT JOIN {usr} ua on (ua.id = u.suspendedcusr)
LEFT OUTER JOIN {usr_institution} ui ON (ui.usr = u.id)
WHERE ' . ($type == 'expired' ? 'u.expiry < current_timestamp' : 'u.suspendedcusr IS NOT NULL') . '
AND u.deleted = 0 ' . $instsql . '
GROUP BY
u.id, u.firstname, u.lastname, u.studentid, u.suspendedctime, u.suspendedreason,
ua.firstname, ua.lastname, u.expiry
ORDER BY ' . ($type == 'expired' ? 'u.expiry' : 'u.suspendedctime') . ', u.id
LIMIT ?
OFFSET ?', array($limit, $offset));
if (!$data) {
$data = array();
}
else {
$institutions = get_records_sql_array('
SELECT ui.usr, ui.studentid, i.displayname
FROM {usr_institution} ui INNER JOIN {institution} i ON ui.institution = i.name
WHERE ui.usr IN (' . join(',', array_keys($data)) . ')', array());
if ($institutions) {
foreach ($institutions as &$i) {
$data[$i->usr]->institutions[] = $i->displayname;
$data[$i->usr]->institutionids[] = $i->studentid;
}
}
$data = array_values($data);
foreach ($data as &$record) {
$record->name = full_name($record);
$record->firstname = $record->cusrfirstname;
$record->lastname = $record->cusrlastname;
$record->cusrname = full_name($record);
$record->expiry = $record->expiry ? format_date($record->expiry, 'strftimew3cdate') : '-';
unset($record->firstname, $record->lastname);
}
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'admin/users/suspended.php?type=' . $type,
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => true,
'datatable' => 'suspendedlist',
'jsonscript' => 'admin/users/suspended.json.php',
));
$smarty = smarty(array('paginator'));
setpageicon($smarty, 'icon-user-times');
$smarty->assign('typeform', $typeform);
$smarty->assign('data', $data);
$smarty->assign('INLINEJAVASCRIPT', <<<EOF
var suspendedlist = new TableRenderer(
'suspendedlist',
'suspended.json.php',
[
'name',
function (r) {
return TD(null, r.institutions ? map(partial(DIV, null), r.institutions) : null);
},
function (r) {
return TD(null, r.institutions ? map(partial(DIV, {'class':'dont-collapse'}), r.institutionids) : r.studentid);
},
'cusrname',
'reason',
'expiry',
function (rowdata) { return TD(null, INPUT({'type': 'checkbox', 'name': 'usr_' + rowdata.id})); }
]
);
suspendedlist.type = {$enc_type};
suspendedlist.statevars.push('type');
suspendedlist.updateOnLoad();
addLoadEvent(function() {
connect('usertype_type', 'onchange', function() {
if (suspendedlist.type != $('usertype_type').value) {
suspendedlist.offset = 0;
suspendedlist.type = $('usertype_type').value;
suspendedlist.doupdate();
}
addLoadEvent(function () {
p = {$pagination['javascript']}
connect('usertype_type', 'onchange', function (event) {
var params = {
'limit': $limit,
'offset': 0,
'sesskey': config['sesskey'],
'setlimit': true,
'type': $('usertype_type').value,
};
p.sendQuery(params);
event.stop();
// Show the buttons relating to the 'type' selected
show_buttons(params.type);
});
function show_buttons(type) {
if (type == 'suspended') {
jQuery('#buttons_unsuspend').show();
jQuery('#buttons_unexpire').hide();
}
else if (type == 'expired') {
jQuery('#buttons_unsuspend').hide();
jQuery('#buttons_unexpire').show();
}
}
show_buttons('$type');
});
jQuery(window).on('pageupdated', {}, function(e, data) {
// For when we are switching between suspended and expired
var tmp = jQuery('<div>').append(data.data.pagination);
var paginationid = tmp.find('.pagination-wrapper').attr('id');
if (paginationid !== jQuery('.pagination-wrapper').attr('id')) {
jQuery('.pagination-wrapper').replaceWith(data.data.pagination);
p = eval(data.data.pagination_js);
}
});
EOF
......@@ -124,6 +201,9 @@ $form = new Pieform(array(
)
)
));
$html = $smarty->fetch('admin/users/suspendresults.tpl');
$smarty->assign('suspendhtml', $html);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('buttonformopen', $form->get_form_tag());
$smarty->assign('buttonform', $form->build(false));
$smarty->assign('PAGEHEADING', TITLE);
......
......@@ -29,7 +29,6 @@ if ($blogpost = param_integer('blogpost', null)) {
$post = ArtefactTypeBlogPost::get_post_data($blogpost);
$id = $post->blogid;
$limit = 1;
$setlimit = 1;
$offset = $post->offset;
}
......@@ -133,11 +132,7 @@ if (!empty($blog)) {
}
if (!isset($limit)) {
$limit = param_integer('limit', 5);
}
if (!isset($setlimit)) {
$setlimit = 0;
$limit = param_integer('limit', 10);
}
if (!isset($offset)) {
......@@ -151,7 +146,7 @@ $pagination = array(
'id' => 'blogpost_pagination',
'jsonscript' => 'artefact/blog/view/index.json.php',
'datatable' => 'postlist',
'setlimit' => $setlimit,
'setlimit' => true,
);
ArtefactTypeBlogPost::render_posts($posts, $template, array(), $pagination);
......
......@@ -83,6 +83,7 @@ $pagination = build_pagination(array(
'offset' => $data->offset,
'datatable' => 'mycollections',
'jsonscript' => 'collection/index.json.php',
'setlimit' => $setlimit,
'firsttext' => '',
'previoustext' => '',
'nexttext' => '',
......
......@@ -113,6 +113,7 @@ $pagination = build_pagination(array(
'offset' => $data->offset,
'datatable' => 'mycollections',
'jsonscript' => 'collection/index.json.php',
'setlimit' => true,
'firsttext' => '',
'previoustext' => '',
'nexttext' => '',
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('group.php');
require_once('searchlib.php');
$filter = param_alpha('filter', 'canjoin');
$offset = param_integer('offset', 0);
$groupsperpage = param_integer('limit', 10);
$groupcategory = param_signed_integer('groupcategory', 0);
$setlimit = param_boolean('setlimit', false);
$query = param_variable('query', '');
// check that the filter is valid, if not default to 'all'
if (in_array($filter, array('member', 'notmember', 'canjoin'))) {
$type = $filter;
}
else { // all or some other text
$filter = 'all';
$type = 'all';
}
$groups = search_group($query, $groupsperpage, $offset, $type, $groupcategory);
// gets more data about the groups found by search_group
// including type if the user is associated with the group in some way
if ($groups['data']) {
$groupids = array();
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests,
g1.editwindowstart, g1.editwindowend
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, COUNT(gm.member) AS membercount,
g.editwindowstart, g.editwindowend
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
SELECT g.id, 'admin' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype, gm.role AS role
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION
SELECT g.id, 'request' AS membershiptype, NULL as role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.urlid, t.role, t.membershiptype, g.editwindowstart, g.editwindowend
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.urlid, g1.role, g1.membershiptype, g1.membercount, g1.editwindowstart, g1.editwindowend
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
}
group_prepare_usergroups_for_display($groups['data'], 'find');
$params = array();
$params['filter'] = $filter;
if ($groupcategory != 0) {
$params['groupcategory'] = $groupcategory;
}
if ($query) {
$params['query'] = $query;
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'group/find.php' . ($params ? ('?' . http_build_query($params)) : ''),
'count' => $groups['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'datatable' => 'findgroups',
'jsonscript' => 'group/find.json.php',
'setlimit' => true,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
$smarty = smarty_core();
$smarty->assign('groups', $groups['data']);
$html = $smarty->fetch('group/mygroupresults.tpl');
json_reply(false, array(
'message' => null,
'data' => array(
'tablerows' => $html,
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
'count' => $groups['count'],
'results' => $groups['count'] . ' ' . ($groups['count'] == 1 ? get_string('result') : get_string('results')),
'offset' => $offset,
'setlimit' => $setlimit,
)
));
\ No newline at end of file
......@@ -178,6 +178,9 @@ $pagination = build_pagination(array(
'count' => $groups['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'datatable' => 'findgroups',
'jsonscript' => 'group/find.json.php',
'setlimit' => true,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
......@@ -188,9 +191,12 @@ function search_submit(Pieform $form, $values) {
redirect('/group/find.php?filter=' . $values['filter'] . ((isset($values['query']) && ($values['query'] != '')) ? '&query=' . urlencode($values['query']) : '') . (!empty($values['groupcategory']) ? '&groupcategory=' . intval($values['groupcategory']) : ''));
}
$smarty = smarty();
$smarty = smarty(array('paginator'));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('form', $searchform);
$smarty->assign('groups', $groups['data']);
$html = $smarty->fetch('group/mygroupresults.tpl');
$smarty->assign('groupresults', $html);
$smarty->assign('form', $searchform);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('pagination_js', $pagination['javascript']);
$smarty->display('group/find.tpl');
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('group.php');
$filter = param_alpha('filter', 'all');
$offset = param_integer('offset', 'all');
$setlimit = param_boolean('setlimit', false);
$groupcategory = param_signed_integer('groupcategory', 0);
$groupsperpage = param_integer('limit', 10);
$offset = (int)($offset / $groupsperpage) * $groupsperpage;
$results = group_get_associated_groups($USER->get('id'), $filter, $groupsperpage, $offset, $groupcategory);
$params = array();
if ($filter != 'all') {
$params['filter'] = $filter;
}
if ($groupcategory != 0) {
$params['groupcategory'] = $groupcategory;
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'group/mygroups.php' . (!empty($params) ? ('?' . http_build_query($params)) : ''),
'count' => $results['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'setlimit' => true,
'datatable' => 'mygroups',
'jsonscript' => 'group/mygroups.json.php',
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
group_prepare_usergroups_for_display($results['groups'], 'mygroups');
$smarty = smarty_core();
$smarty->assign('groups', $results['groups']);
$smarty->assign('filter', $filter);
$html = $smarty->fetch('group/mygroupresults.tpl');
json_reply(false, array(
'message' => null,
'data' => array(
'tablerows' => $html,
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
'count' => $results['count'],
'results' => $results['count'] . ' ' . ($results['count'] == 1 ? get_string('result') : get_string('results')),
'offset' => $offset,
'setlimit' => $setlimit,
)
));
......@@ -85,6 +85,9 @@ $pagination = build_pagination(array(
'count' => $results['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'setlimit' => true,
'datatable' => 'mygroups',
'jsonscript' => 'group/mygroups.json.php',
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
......@@ -93,12 +96,13 @@ $pagination = build_pagination(array(
group_prepare_usergroups_for_display($results['groups'], 'mygroups');
$smarty = smarty();
$smarty = smarty(array('paginator'));
$smarty->assign('groups', $results['groups']);
$smarty->assign('cancreate', group_can_create_groups());
$smarty->assign('form', $form);
$smarty->assign('filter', $filter);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('pagination_js', $pagination['javascript']);
$smarty->assign('searchingforgroups', array('<a href="' . get_config('wwwroot') . 'group/find.php">', '</a>'));
$smarty->assign('headingclass', 'page-header');
$smarty->assign('PAGEHEADING', TITLE);
......
......@@ -1620,6 +1620,7 @@ function build_grouplist_html($query, $limit, $offset, &$count=null) {
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => true,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
......
......@@ -17,8 +17,11 @@
</tr>
</thead>
<tbody>
{$suspendhtml|safe}
</tbody>
</table>
</form>
</div>
{$pagination|safe}
{include file="footer.tpl"}
{foreach from=$data item=item}
<tr class="{cycle values='r0,r1'}">
<td>{$item->name}</td>
<td>{if $item->institutions}
{foreach from=$item->institutions item=institution}
<div>{$institution}</div>
{/foreach}
{/if}
</td>
<td>{if $item->institutions}
{foreach from=$item->institutionids item=institutionid}
<div>{$institutionid}</div>
{/foreach}
{else}
<div>{$item->studentid}</div>
{/if}
</td>
<td>{$item->cusrname}</td>
<td>{$item->reason}</td>
<td>{$item->expiry}</td>
<td><input type="checkbox" name="usr_{$item->id}"></td>
</tr>
{/foreach}
\ No newline at end of file
......@@ -4,12 +4,15 @@
<div class="panel panel-default view-container">
<h2 class="panel-heading">{str tag=Results}</h2>
<div id="findgroups" class="list-group">
{foreach from=$groups item=group}
{include file="group/group.tpl" group=$group returnto='mygroups'}
{/foreach}
{$groupresults|safe}
</div>
</div>
{$pagination|safe}
{if $pagination_js}
<script type="application/javascript">
{$pagination_js|safe}
</script>
{/if}
{else}
<p class="no-results">
{str tag="nogroupsfound" section="group"}
......
{foreach from=$groups item=group}
{include file="group/group.tpl" group=$group returnto='mygroups'}
{/foreach}
\ No newline at end of file
......@@ -18,6 +18,11 @@
</div>
</div>
{$pagination|safe}
{if $pagination_js}
<script type="application/javascript">
{$pagination_js|safe}
</script>
{/if}
{else}
<p class="no-results">
{str tag="trysearchingforgroups" section="group" args=$searchingforgroups}
......
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