Commit b5a865e1 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Adding paginator to 'My pages' block (Bug #634689)"

parents 06fb32d0 406c4c8a
......@@ -33,6 +33,40 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
return array('profile', 'dashboard');
}
/**
* This function renders a list of items views as html
*
* @param array items
* @param string template
* @param array options
* @param array pagination
*/
public function render_items(&$items, $template, $options, $pagination) {
$smarty = smarty_core();
$smarty->assign('options', $options);
$smarty->assign('items', $items['data']);
$items['tablerows'] = $smarty->fetch($template);
if ($items['limit'] && $pagination) {
$pagination = build_pagination(array(
'id' => $pagination['id'],
'class' => 'center',
'datatable' => $pagination['datatable'],
'url' => $pagination['baseurl'],
'jsonscript' => $pagination['jsonscript'],
'count' => $items['count'],
'limit' => $items['limit'],
'offset' => $items['offset'],
'numbersincludefirstlast' => false,
'resultcounttextsingular' => $pagination['resultcounttextsingular'] ? $pagination['resultcounttextsingular'] : get_string('result'),
'resultcounttextplural' => $pagination['resultcounttextplural'] ? $pagination['resultcounttextplural'] :get_string('results'),
));
$items['pagination'] = $pagination['html'];
$items['pagination_js'] = $pagination['javascript'];
}
}
public static function render_instance(BlockInstance $instance, $editing=false) {
$userid = $instance->get_view()->get('owner');
if (!$userid) {
......@@ -42,9 +76,21 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
$smarty = smarty_core();
// Get viewable views
$views = View::view_search(null, null, (object) array('owner' => $userid), null, null, 0, true, null, array('portfolio'));
$views = $views->count ? $views->data : array();
$smarty->assign('VIEWS',$views);
$views = View::view_search(null, null, (object) array('owner' => $userid), null, 10, 0, true, null, array('portfolio'));
$views = (array)$views;
$viewid = $instance->get_view()->get('id');
$baseurl = $instance->get_view()->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'view=' . $viewid . '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'myviews_pagination',
'datatable' => 'myviewlist',
'jsonscript' => 'blocktype/myviews/myviews.json.php',
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
);
self::render_items($views, 'blocktype:myviews:myviewspaginator.tpl', array(), $pagination);
$smarty->assign('myviews', $views);
return $smarty->fetch('blocktype:myviews:myviews.tpl');
}
......
<?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', 'myviews');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');
$offset = param_integer('offset', 0);
$viewid = param_integer('view');
$editing = param_boolean('editing', false);
$dashboard = new View($viewid);
if (!can_view_view($dashboard)) {
json_reply(true, get_string('accessdenied', 'error'));
}
$views = View::view_search(null, null, (object) array('owner' => $dashboard->get('owner')), null, 10, $offset, true, null, array('portfolio'));
$views = (array)$views;
$baseurl = $dashboard->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'view=' . $viewid . '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'myviews_pagination',
'datatable' => 'myviewlist',
'jsonscript' => 'blocktype/myviews/myviews.json.php',
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
);
PluginBlocktypeMyViews::render_items($views, 'blocktype:myviews:myviewspaginator.tpl', array(), $pagination);
json_reply(false, array('data' => $views));
{if $VIEWS}
<div id="userviewstable" class="viewlist fullwidth listing">
{foreach from=$VIEWS item=item name=view}
<div class="{cycle values='r0,r1'} listrow">
<h3 class="title"><a href="{$item.fullurl}">{$item.title}</a></h3>
{if $item.description}
<div class="detail">{$item.description|str_shorten_html:100:true|strip_tags|safe}</div>
{/if}
{if $item.tags}
<div class="tags"><strong>{str tag=tags}:</strong> {list_tags owner=$item.owner tags=$item.tags}</div>
{/if}
</div>
{/foreach}
{if $myviews}
<div class="myviewsection">
<div id="myviewlist" class="fullwidth listing">
{$myviews.tablerows|safe}
</div>
{if $myviews.pagination}
<div id="myviews_page_container" class="hidden center">{$myviews.pagination|safe}</div>
{/if}
{if $myviews.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
{$myviews.pagination_js|safe}
removeElementClass('myviews_page_container', 'hidden');
{literal}}{/literal});
</script>
{/if}
</div>
{else}
{str tag='noviewstosee' section='group'}
{/if}
{foreach from=$items item=view}
<div class="{cycle values='r0,r1'} listrow">
<h4 class="title"><a href="{$view.fullurl}">{$view.title}</a></h4>
{if $view.description}
<div class="detail">{$view.description|str_shorten_html:100:true|strip_tags|safe}</div>
{/if}
{if $item.tags}
<div class="tags"><strong>{str tag=tags}:</strong> {list_tags owner=$view.owner tags=$view.tags}</div>
{/if}
</div>
{/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