Commit 473b4f2c authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Add pagination for the shared page list (Bug 1320006)"

parents 1db24af2 8b63b642
......@@ -39,6 +39,40 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
return true;
}
/**
* This function renders a list of items (views/collections) 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) {
$configdata = $instance->get('configdata');
if (!isset($configdata['showgroupviews'])) {
......@@ -62,7 +96,19 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
$dwoo->assign('groupviews', $data['groupviews']->data);
}
if (!empty($configdata['showsharedviews']) && isset($data['sharedviews'])) {
$dwoo->assign('sharedviews', $data['sharedviews']->data);
$sharedviews = (array)$data['sharedviews'];
$baseurl = $instance->get_view()->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'sharedviews_pagination',
'datatable' => 'sharedviewlist',
'jsonscript' => 'blocktype/groupviews/sharedviews.json.php',
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
);
self::render_items($sharedviews, 'blocktype:groupviews:sharedviews.tpl', $configdata, $pagination);
$dwoo->assign('sharedviews', $sharedviews);
}
if (isset($data['allsubmitted'])) {
$dwoo->assign('allsubmitted', $data['allsubmitted']);
......@@ -134,7 +180,11 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
// For group members, display a list of views that others have
// shared to the group
$data['sharedviews'] = View::get_sharedviews_data(null, 0, $group->id);
$bi = group_get_homepage_view_groupview_block($group->id);
$configdata = $bi->get('configdata');
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
$data['sharedviews'] = View::get_sharedviews_data($limit, 0, $group->id);
foreach ($data['sharedviews']->data as &$view) {
if (!$editing && isset($view['template']) && $view['template']) {
$view['form'] = pieform(create_view_form($group, null, $view->id));
......
<?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', 'groupviews');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
$offset = param_integer('offset', 0);
$groupid = param_integer('group');
$group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid);
if (!can_view_view($group_homepage_view)) {
json_reply(true, get_string('accessdenied', 'error'));
}
$configdata = $bi->get('configdata');
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
$sharedviews = (array)View::get_sharedviews_data($limit, $offset, $groupid);
foreach ($sharedviews['data'] as &$view) {
if (isset($view['template']) && $view['template']) {
$view['form'] = pieform(create_view_form($group_homepage_view, null, $view->id));
}
}
if (!empty($configdata['showsharedviews']) && isset($sharedviews)) {
$baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'sharedviews_pagination',
'datatable' => 'sharedviewlist',
'jsonscript' => 'blocktype/groupviews/sharedviews.json.php',
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
);
PluginBlocktypeGroupViews::render_items($sharedviews, 'blocktype:groupviews:sharedviews.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $sharedviews));
......@@ -19,33 +19,20 @@
{if $sharedviews}
<div class="groupviewsection">
<h3 class="title">{str tag="viewssharedtogroupbyothers" section="view"}</h3>
<div class="fullwidth listing">
{foreach from=$sharedviews item=view}
<div class="{cycle values='r0,r1'} listrow">
{if $view.template}
<div class="s fr">{$view.form|safe}</div>
{/if}
<h4 class="title"><a href="{$view.fullurl}">{$view.title}</a>
{if $view.sharedby}
<span class="owner"> {str tag=by section=view}
{if $view.group}
<a href="{group_homepage_url($view.groupdata)}">{$view.sharedby}</a>
{elseif $view.owner}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{else}
{$view.sharedby}
{/if}
</span>
{/if}
</h4>
<div class="detail">{$view.description|str_shorten_html:100:true|strip_tags|safe}</div>
{if $view.tags}
<div class="tags"><label>{str tag=tags}:</label> {list_tags owner=$view.owner tags=$view.tags}</div>
{/if}
</div>
{/foreach}
<div id="sharedviewlist" class="fullwidth listing">
{$sharedviews.tablerows|safe}
</div>
</div>
{if $sharedviews.pagination}
<div id="sharedviews_page_container" class="hidden center">{$sharedviews.pagination|safe}</div>
{/if}
{if $sharedviews.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
{$sharedviews.pagination_js|safe}
removeElementClass('sharedviews_page_container', 'hidden');
{literal}}{/literal});
</script>
{/if}
{/if}
......
{foreach from=$items item=view}
<div class="{cycle values='r0,r1'} listrow">
{if $view.template}
<div class="s fr">{$view.form|safe}</div>
{/if}
<h4 class="title"><a href="{$view.fullurl}">{$view.title}</a>
{if $view.sharedby}
<span class="owner"> {str tag=by section=view}
{if $view.group}
<a href="{group_homepage_url($view.groupdata)}">{$view.sharedby}</a>
{elseif $view.owner}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{else}
{$view.sharedby}
{/if}
</span>
{/if}
</h4>
<div class="detail">{$view.description|str_shorten_html:100:true|strip_tags|safe}</div>
{if $view.tags}
<div class="tags"><label>{str tag=tags}:</label> {list_tags owner=$view.owner tags=$view.tags}</div>
{/if}
</div>
{/foreach}
......@@ -2141,6 +2141,25 @@ function group_get_homepage_view($groupid) {
return new View($v->id, (array)$v);
}
/**
* Return the groupview block object of this group's homepage view
*
* @param int $groupid the id of the group to fetch the view for
* @return object block instance
* @throws SQLException if there are more than one groupview block instance
*/
function group_get_homepage_view_groupview_block($groupid) {
$bi = get_record_sql('
SELECT bi.id
FROM {view} v
INNER JOIN {block_instance} bi ON v.id = bi.view
WHERE bi.blocktype = ?
AND v.group = ? AND v.type = ?',
array('groupviews', $groupid, 'grouphomepage')
);
return new BlockInstance($bi->id);
}
/**
* install the group homepage view
* This creates a template at system level
......
......@@ -4176,8 +4176,10 @@ class View {
}
return (object) array(
'data' => array_values($viewdata),
'count' => $count,
'data' => array_values($viewdata),
'count' => $count,
'limit' => $limit,
'offset' => $offset,
);
}
......
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