Commit c4f2c8c6 authored by Robert Lyon's avatar Robert Lyon

Bug 1515484: Fix the group page list pagination to use json

This is 4 of 6 patches to standardize pagination

behatnotneeded

Change-Id: If89d7a800e4d76c6ec6e7dc44c3b69c73dee9952
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 80858bc8
......@@ -19,11 +19,76 @@ require_once('pieforms/pieform.php');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 0);
$setlimit = param_boolean('setlimit', false);
$groupid = param_integer('group', null);
list($searchform, $data, $pagination) = View::views_by_owner();
if (!empty($groupid)) {
define('PUBLIC', 1);
define('GROUP', param_integer('group'));
require_once(get_config('docroot') . 'lib/group.php');
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
json_reply('local', get_string('accessdenied', 'error'));
}
$role = group_user_access($group->id);
$can_edit = $role && group_role_can_edit_views($group, $role);
// If the user can edit group views, show a page similar to the my views
// page, otherwise just show a list of the views owned by this group that
// are visible to the user.
if (!$can_edit) {
$setlimit = true;
$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;
}
$offset = param_integer('offset', 0);
$data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset);
// Add a copy view form for all templates in the list
foreach ($data->data as &$v) {
if ($v['template']) {
$v['copyform'] = pieform(create_view_form(null, null, $v['id']));
}
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'view/groupviews.php?group=' . $group->id,
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'setlimit' => $setlimit,
'datatable' => 'myviews',
'jsonscript' => 'json/viewlist.php',
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
));
}
else {
list($searchform, $data, $pagination) = View::views_by_owner($group->id);
$createviewform = pieform(create_view_form($group->id));
}
}
else {
list($searchform, $data, $pagination) = View::views_by_owner();
}
$smarty = smarty_core();
$smarty->assign('views', $data->data);
if ($groupid && !$can_edit) {
$html = $smarty->fetch('view/indexgroupresults.tpl');
$smarty->assign('viewresults', $html);
$smarty->display('view/groupviews.tpl');
}
else if ($groupid) {
$smarty->assign('editlocked', $role == 'admin');
}
$smarty->assign('querystring', get_querystring());
$html = $smarty->fetch('view/indexresults.tpl');
......
......@@ -5,32 +5,7 @@
<div class="panel panel-default">
<h2 class="panel-heading hidefocus" tabindex="-1">Results</h2>
<div class="list-group">
{foreach from=$views item=view}
<div class="list-group-item">
<a href="{$view.fullurl}" class="outer-link">
<span class="sr-only">{$view.title}</span>
</a>
<div class="row">
<div class="col-md-9">
<h3 class="title list-group-item-heading">{$view.title}</h3>
{if $view.description}
<div class="detail">
{$view.description|clean_html|safe}
</div>
{/if}
</div>
{if $view.copyform}
<div class="col-md-3">
<div class="inner-link btn-action-list">
<div class="btn-top-right btn-group btn-group-top only-button">
{$view.copyform|safe}
</div>
</div>
</div>
{/if}
</div>
</div>
{/foreach}
{$viewresults|safe}
</div>
</div>
</div>
......
{foreach from=$views item=view}
<div class="list-group-item">
<a href="{$view.fullurl}" class="outer-link">
<span class="sr-only">{$view.title}</span>
</a>
<div class="row">
<div class="col-md-9">
<h3 class="title list-group-item-heading">{$view.title}</h3>
{if $view.description}
<div class="detail">
{$view.description|clean_html|safe}
</div>
{/if}
</div>
{if $view.copyform}
<div class="col-md-3">
<div class="inner-link btn-action-list">
<div class="btn-top-right btn-group btn-group-top only-button">
{$view.copyform|safe}
</div>
</div>
</div>
{/if}
</div>
</div>
{/foreach}
......@@ -66,6 +66,8 @@ if (!$can_edit) {
'limit' => $limit,
'offset' => $offset,
'setlimit' => $setlimit,
'datatable' => 'myviews',
'jsonscript' => 'json/viewlist.php',
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
));
......@@ -107,12 +109,16 @@ $smarty->assign('pagination', $pagination['html']);
$smarty->assign('subsectionheading', get_string('Views', 'view'));
if (!$can_edit) {
$html = $smarty->fetch('view/indexgroupresults.tpl');
$smarty->assign('viewresults', $html);
$smarty->display('view/groupviews.tpl');
}
else {
$smarty->assign('query', param_variable('query', null));
$smarty->assign('querystring', get_querystring());
$smarty->assign('editlocked', $role == 'admin');
$html = $smarty->fetch('view/indexresults.tpl');
$smarty->assign('viewresults', $html);
$smarty->assign('searchform', $searchform);
$smarty->assign('createviewform', $createviewform);
$smarty->display('view/index.tpl');
......
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