Commit 5c81266b authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Merge "Bug 1523747: Allow watchlist to be paginated"

parents 7422f7f8 940f6cd9
......@@ -34,38 +34,93 @@ class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
$smarty = smarty_core();
$views = self::fetch_items($instance, 0, $editing);
// if there are no watched views, notify the user
if (empty($views['data'])) {
$smarty->assign('watchlistempty', true);
}
else {
$smarty->assign('watchlist', $views);
}
return $smarty->fetch('blocktype:watchlist:watchlist.tpl');
}
/**
* This function fetches one pagination "page" of items to be displayed by the watchlist block.
* (This is used both for the initial block display, and in the JSON pagination script.)
*
* @param BlockInstance $instance The watchlist to display
* @param int $offset
* @param boolean $editing Whether we're in editing more or not.
*/
//public static function fetch_items($view, $userid, $offset = 0, $limit = 10, $editing = false) {
public static function fetch_items(BlockInstance $instance, $offset = 0, $editing = false) {
global $USER;
$configdata = $instance->get('configdata');
$limit = isset($configdata['count']) ? (int) $configdata['count'] : 10;
$userid = $USER->get('id');
$smarty = smarty_core();
$count = count_records_sql('SELECT COUNT(*) FROM {view} v JOIN {usr_watchlist_view} wv ON wv.view = v.id WHERE wv.usr = ?' , array($userid));
$sql = '
SELECT v.id, v.title, v.owner, v.group, v.institution, v.ownerformat, v.urlid, v.ctime, v.mtime
FROM {view} v
JOIN {usr_watchlist_view} wv ON wv.view = v.id
WHERE wv.usr = ?
ORDER BY v.title
LIMIT ?';
$results = get_records_sql_assoc($sql, array($userid, $limit));
// if there are no watched views, notify the user
if (!$results) {
$smarty->assign('watchlistempty', true);
return $smarty->fetch('blocktype:watchlist:watchlist.tpl');
}
View::get_extra_view_info($results, false, false);
foreach ($results as &$r) {
$r = (object) $r;
ORDER BY v.title';
$results = get_records_sql_assoc($sql, array($userid), $offset, $limit);
if (!empty($results)) {
View::get_extra_view_info($results, false, false);
foreach ($results as &$r) {
$r = (object) $r;
}
}
$views = array('data' => $results,
'offset' => $offset,
'limit' => $limit,
'editing' => $editing,
'count' => $count);
$view = $instance->get_view();
$baseurl = $view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'id=' . $instance->get('id'). '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'watchlist_pagination',
'datatable' => 'watchlistblock',
'jsonscript' => 'blocktype/watchlist/watchlist.json.php',
'resultcounttextsingular' => get_string('result'),
'resultcounttextplural' => get_string('results'),
);
$smarty = smarty_core();
$smarty->assign('options', array());
$smarty->assign('views', $views['data']);
$smarty->assign('loggedin', $USER->is_logged_in());
$smarty->assign('views', array_values($results));
return $smarty->fetch('blocktype:watchlist:watchlist.tpl');
$views['tablerows'] = $smarty->fetch('blocktype:watchlist:watchlistpaginator.tpl');
if ($views['limit'] && $pagination) {
$pagination = build_pagination(array(
'id' => $pagination['id'],
'class' => 'center',
'datatable' => $pagination['datatable'],
'url' => $pagination['baseurl'],
'jsonscript' => $pagination['jsonscript'],
'count' => $views['count'],
'editing' => $views['editing'],
'limit' => $views['limit'],
'offset' => $views['offset'],
'numbersincludefirstlast' => false,
'resultcounttextsingular' => $pagination['resultcounttextsingular'] ? $pagination['resultcounttextsingular'] : get_string('result'),
'resultcounttextplural' => $pagination['resultcounttextplural'] ? $pagination['resultcounttextplural'] :get_string('results'),
));
$views['pagination'] = $pagination['html'];
$views['pagination_js'] = $pagination['javascript'];
}
return $views;
}
public static function has_instance_config() {
......@@ -99,7 +154,7 @@ class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
}
public static function should_ajaxify() {
return true;
return false;
}
/**
......
<?php
/**
*
* @package mahara
* @subpackage blocktype/groupviews
* @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.
*
*/
/**
* returns shared views in a given group id
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('blocktype', 'watchlist');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');
$blockid = param_integer('id');
$offset = param_integer('offset', 0);
$editing = param_integer('editing', false);
$instance = new BlockInstance($blockid);
if (!can_view_view($instance->get_view())) {
json_reply(true, get_string('accessdenied', 'error'));
}
$views = PluginBlocktypeWatchlist::fetch_items($instance, $offset, $editing);
json_reply(false, array('data' => $views));
......@@ -4157,8 +4157,8 @@ function build_pagination($params) {
}
// Build limitoptions dropbox if results are more than 10 (minimum dropbox pagination)
if ($params['setlimit'] && $params['count'] > 10) {
// Build limitoptions dropbox if results are more than 10 (minimum dropbox pagination) and that we are not in the block editor screen
if ($params['setlimit'] && $params['count'] > 10 && (!isset($params['editing']) || $params['editing'] === false)) {
$strlimitoptions = array();
$limit = $params['limit'];
for ($i = 0; $i < count($limitoptions); $i++) {
......
{if $watchlistempty}
<div class="panel-body">
<p class="lead text-small">{str tag=nopages section=blocktype.watchlist}</p>
</div>
<div class="panel-body">
<p class="lead text-small">{str tag=nopages section=blocktype.watchlist}</p>
</div>
{else}
<ul id="watchlistblock" class="viewlist list-group">
{foreach $views as item=view}
<li class="list-group-item">
<a href="{$view->fullurl}" class=" outer-link watchlist-showview">
<span class="sr-only">{$view->title}</span>
</a>
<h4 class="title list-group-item-heading">
{$view->title}
</h4>
{if $view->sharedby}
<div class="groupuserdate text-small">
{if $view->group && $loggedin}
<a class="inner-link" href="{$view->groupdata->homeurl}">{$view->sharedby}</a>
{elseif $view->owner && $loggedin}
{if $view->anonymous}
{if $view->staff_or_admin}
{assign var='realauthor' value=$view->sharedby}
{assign var='realauthorlink' value=profile_url($view->user)}
{/if}
{assign var='author' value=get_string('anonymoususer')}
{include file=author.tpl}
{else}
<a class="inner-link" href="{profile_url($view->user)}">{$view->sharedby}</a>
{/if}
{else}
{$view->sharedby}
{/if}
<span class="postedon text-midtone">
- {if $view->mtime == $view->ctime}{str tag=Created}{else}{str tag=Updated}{/if}
{$view->mtime|strtotime|format_date:'strftimedate'}</span>
</div>
{/if}
</li>
{/foreach}
</ul>
<ul id="watchlistblock" class="viewlist list-group">
{$watchlist.tablerows|safe}
</ul>
{if $watchlist.pagination}
<div id="watchlist_page_container" class="hidden">{$watchlist.pagination|safe}</div>
{/if}
{if $watchlist.pagination_js}
<script type="application/javascript">
jQuery(function() {literal}{{/literal}
{$watchlist.pagination_js|safe}
removeElementClass('watchlist_page_container', 'hidden');
{literal}}{/literal});
</script>
{/if}
{/if}
{foreach $views as item=view}
<li class="list-group-item">
<a href="{$view->fullurl}" class=" outer-link watchlist-showview">
<span class="sr-only">{$view->title}</span>
</a>
<h4 class="title list-group-item-heading">
{$view->title}
</h4>
{if $view->sharedby}
<div class="groupuserdate text-small">
{if $view->group && $loggedin}
<a class="inner-link" href="{$view->groupdata->homeurl}">{$view->sharedby}</a>
{elseif $view->owner && $loggedin}
{if $view->anonymous}
{if $view->staff_or_admin}
{assign var='realauthor' value=$view->sharedby}
{assign var='realauthorlink' value=profile_url($view->user)}
{/if}
{assign var='author' value=get_string('anonymoususer')}
{include file=author.tpl}
{else}
<a class="inner-link" href="{profile_url($view->user)}">{$view->sharedby}</a>
{/if}
{else}
{$view->sharedby}
{/if}
<span class="postedon text-midtone">
- {if $view->mtime == $view->ctime}{str tag=Created}{else}{str tag=Updated}{/if}
{$view->mtime|strtotime|format_date:'strftimedate'}</span>
</div>
{/if}
</li>
{/foreach}
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