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

Merge changes Ied96d51d,I4c0e8c49

* changes:
  Add pagination to the submission list in group homepage (Bug 1321941)
  Display shared collections in the groupviews blocktype (Bug 1320006)
parents e10fefd4 fd897c88
<?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 all submissions to 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');
if (!isset($configdata['showsubmitted'])) {
$configdata['showsubmitted'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $groupid);
$allsubmitted = array_merge(array_values($collections), array_values($views));
$allsubmitted = array(
'data' => array_slice($allsubmitted, $offset, $limit),
'count' => count($allsubmitted),
'limit' => $limit,
'offset' => $offset,
);
if (!empty($configdata['showsubmitted'])) {
$baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'allsubmitted_pagination',
'datatable' => 'allsubmissionlist',
'jsonscript' => 'blocktype/groupviews/allsubmissions.json.php',
'resultcounttextsingular' => get_string('vieworcollection', 'view'),
'resultcounttextplural' => get_string('viewsandcollections', 'view'),
);
PluginBlocktypeGroupViews::render_items($allsubmitted, 'blocktype:groupviews:allsubmissions.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $allsubmitted));
......@@ -17,5 +17,11 @@ $string['description'] = 'Display the pages related to the group';
$string['displaygroupviews'] = 'Display group pages';
$string['displaygroupviewsdesc'] = 'Group pages - pages created in the group';
$string['displaysharedviews'] = 'Display shared pages';
$string['displaysharedviewsdesc'] = 'Shared pages - pages shared by group members from their individual portfolios';
$string['displaysharedviewsdesc1'] = 'Show a list of pages shared with this group (excluding pages in collections).';
$string['displaysharedcollections'] = 'Display shared collections';
$string['displaysharedcollectionsdesc'] = 'Show a list of collections shared with this group.';
$string['displaysubmissions'] = 'Display submitted pages and collections';
$string['displaysubmissionsdesc'] = 'Show a list of pages and collections submitted to this group.';
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
$string['itemstoshow'] = 'Entries per page';
$string['itemstoshowdesc'] = 'The number of pages or collections shown for each section. Maximum: 100';
......@@ -82,6 +82,12 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
if (!isset($configdata['showsharedviews'])) {
$configdata['showsharedviews'] = 1;
}
if (!isset($configdata['showsharedcollections'])) {
$configdata['showsharedcollections'] = 1;
}
if (!isset($configdata['showsubmitted'])) {
$configdata['showsubmitted'] = 1;
}
$groupid = $instance->get_view()->get('group');
if (!$groupid) {
return '';
......@@ -95,10 +101,10 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
if (!empty($configdata['showgroupviews']) && isset($data['groupviews'])) {
$dwoo->assign('groupviews', $data['groupviews']->data);
}
$baseurl = $instance->get_view()->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
if (!empty($configdata['showsharedviews']) && isset($data['sharedviews'])) {
$sharedviews = (array)$data['sharedviews'];
$baseurl = $instance->get_view()->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'sharedviews_pagination',
......@@ -110,8 +116,31 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
self::render_items($sharedviews, 'blocktype:groupviews:sharedviews.tpl', $configdata, $pagination);
$dwoo->assign('sharedviews', $sharedviews);
}
if (isset($data['allsubmitted'])) {
$dwoo->assign('allsubmitted', $data['allsubmitted']);
if (!empty($configdata['showsharedcollections']) && isset($data['sharedcollections'])) {
$sharedcollections = (array)$data['sharedcollections'];
$pagination = array(
'baseurl' => $baseurl,
'id' => 'sharedcollections_pagination',
'datatable' => 'sharedcollectionlist',
'jsonscript' => 'blocktype/groupviews/sharedcollections.json.php',
'resultcounttextsingular' => get_string('collection', 'collection'),
'resultcounttextplural' => get_string('collections', 'collection'),
);
self::render_items($sharedcollections, 'blocktype:groupviews:sharedcollections.tpl', $configdata, $pagination);
$dwoo->assign('sharedcollections', $sharedcollections);
}
if (!empty($configdata['showsubmitted']) && isset($data['allsubmitted'])) {
$allsubmitted = $data['allsubmitted'];
$pagination = array(
'baseurl' => $baseurl,
'id' => 'allsubmitted_pagination',
'datatable' => 'allsubmissionlist',
'jsonscript' => 'blocktype/groupviews/allsubmissions.json.php',
'resultcounttextsingular' => get_string('vieworcollection', 'view'),
'resultcounttextplural' => get_string('viewsandcollections', 'view'),
);
self::render_items($allsubmitted, 'blocktype:groupviews:allsubmissions.tpl', $configdata, $pagination);
$dwoo->assign('allsubmitted', $allsubmitted);
}
if (isset($data['mysubmitted'])) {
$dwoo->assign('mysubmitted', $data['mysubmitted']);
......@@ -144,7 +173,7 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'showsharedviews' => array(
'type' => 'radio',
'title' => get_string('displaysharedviews', 'blocktype.groupviews'),
'description' => get_string('displaysharedviewsdesc', 'blocktype.groupviews'),
'description' => get_string('displaysharedviewsdesc1', 'blocktype.groupviews'),
'options' => array(
1 => get_string('yes'),
0 => get_string('no'),
......@@ -152,6 +181,36 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'separator' => '<br>',
'defaultvalue' => isset($configdata['showsharedviews']) ? $configdata['showsharedviews'] : 1,
),
'showsharedcollections' => array(
'type' => 'radio',
'title' => get_string('displaysharedcollections', 'blocktype.groupviews'),
'description' => get_string('displaysharedcollectionsdesc', 'blocktype.groupviews'),
'options' => array(
1 => get_string('yes'),
0 => get_string('no'),
),
'separator' => '<br>',
'defaultvalue' => isset($configdata['showsharedcollections']) ? $configdata['showsharedcollections'] : 1,
),
'showsubmitted' => array(
'type' => 'radio',
'title' => get_string('displaysubmissions', 'blocktype.groupviews'),
'description' => get_string('displaysubmissionsdesc', 'blocktype.groupviews'),
'options' => array(
1 => get_string('yes'),
0 => get_string('no'),
),
'separator' => '<br>',
'defaultvalue' => isset($configdata['showsubmitted']) ? $configdata['showsubmitted'] : 1,
),
'count' => array(
'type' => 'text',
'title' => get_string('itemstoshow', 'blocktype.groupviews'),
'description' => get_string('itemstoshowdesc', 'blocktype.groupviews'),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 5,
'size' => 3,
'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 100),
),
);
}
......@@ -191,11 +250,20 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
}
}
$data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id);
if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
// Display a list of views submitted to the group
list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $group->id);
$data['allsubmitted'] = array_merge(array_values($collections), array_values($views));
$allsubmitted = array_merge(array_values($collections), array_values($views));
$data['allsubmitted'] = array(
'data' => array_slice($allsubmitted, 0, $limit),
'count' => count($allsubmitted),
'limit' => $limit,
'offset' => 0,
);
}
}
if ($group->submittableto) {
......
<?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 collections 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');
if (!isset($configdata['showsharedcollections'])) {
$configdata['showsharedcollections'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
$sharedcollections = (array)View::get_sharedcollections_data($limit, $offset, $groupid);
if (!empty($configdata['showsharedcollections']) && isset($sharedcollections)) {
$baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'sharedcollections_pagination',
'datatable' => 'sharedcollectionlist',
'jsonscript' => 'blocktype/groupviews/sharedcollections.json.php',
'resultcounttextsingular' => get_string('collection', 'collection'),
'resultcounttextplural' => get_string('collections', 'collection'),
);
PluginBlocktypeGroupViews::render_items($sharedcollections, 'blocktype:groupviews:sharedcollections.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $sharedcollections));
......@@ -33,6 +33,9 @@ if (!can_view_view($group_homepage_view)) {
}
$configdata = $bi->get('configdata');
if (!isset($configdata['showsharedviews'])) {
$configdata['showsharedviews'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
......
{foreach from=$items item=item}
<div class="{cycle values='r0,r1'} listrow">
<h4 class="title"><a href="{$item.url}">{$item.name|str_shorten_text:60:true}</a>
<span class="owner">{str tag=by section=view} <a href="{$item.ownerurl}">{$item.ownername}</a></span></h4>
<div class="detail">{str tag=timeofsubmission section=view}: {$item.submittedtime|format_date}</div>
</div>
{/foreach}
......@@ -18,7 +18,7 @@
{if $sharedviews}
<div class="groupviewsection">
<h3 class="title">{str tag="viewssharedtogroupbyothers" section="view"}</h3>
<h3 class="title">{str tag="viewssharedtogroup" section="view"}</h3>
<div id="sharedviewlist" class="fullwidth listing">
{$sharedviews.tablerows|safe}
</div>
......@@ -33,6 +33,28 @@
{literal}}{/literal});
</script>
{/if}
</div>
{/if}
{if $sharedcollections}
<div class="groupviewsection">
<h3 class="title">{str tag="collectionssharedtogroup" section="collection"}</h3>
<div id="sharedcollectionlist" class="fullwidth listing">
{$sharedcollections.tablerows|safe}
</div>
{if $sharedcollections.pagination}
<div id="sharedcollections_page_container" class="hidden center">{$sharedcollections.pagination|safe}</div>
{/if}
{if $sharedcollections.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
{$sharedcollections.pagination_js|safe}
removeElementClass('sharedcollections_page_container', 'hidden');
{literal}}{/literal});
</script>
{/if}
</div>
{/if}
......@@ -63,14 +85,19 @@
{if $allsubmitted}
<div class="groupviewsection">
<h3 class="title">{str tag="submissionstogroup" section="view"}</h3>
<div class="fullwidth listing" id="allsubmitted">
{foreach from=$allsubmitted item=item}
<div class="{cycle values='r0,r1'} listrow">
<h4 class="title"><a href="{$item.url}">{$item.name|str_shorten_text:60:true}</a>
<span class="owner">{str tag=by section=view} <a href="{$item.ownerurl}">{$item.ownername}</a></span></h4>
<div class="detail">{str tag=timeofsubmission section=view}: {$item.submittedtime|format_date}</div>
</div>
{/foreach}
<div id="allsubmissionlist" class="fullwidth listing">
{$allsubmitted.tablerows|safe}
</div>
{if $allsubmitted.pagination}
<div id="allsubmitted_page_container" class="hidden center">{$allsubmitted.pagination|safe}</div>
{/if}
{if $allsubmitted.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
{$allsubmitted.pagination_js|safe}
removeElementClass('allsubmitted_page_container', 'hidden');
{literal}}{/literal});
</script>
{/if}
</div>
{/if}
{foreach from=$items item=collection}
<div class="{cycle values='r0,r1'} listrow">
<h4 class="title"><a href="{$collection.fullurl}">{$collection.name}</a>
{if $collection.sharedby}
<span class="owner"> {str tag=by section=view}
{if $collection.group}
<a href="{group_homepage_url($collection.groupdata)}">{$collection.sharedby}</a>
{elseif $collection.owner}
<a href="{profile_url($collection.user)}">{$collection.sharedby}</a>
{else}
{$collection.sharedby}
{/if}
</span>
{/if}
</h4>
<div class="detail">{$collection.description|str_shorten_html:100:true|strip_tags|safe}</div>
{if $collection.tags}
<div class="tags"><label>{str tag=tags}:</label> {list_tags owner=$collection.owner tags=$collection.tags}</div>
{/if}
</div>
{/foreach}
......@@ -99,3 +99,4 @@ $string['by'] = 'by';
$string['copycollection'] = 'Copy collection';
$string['youhaveonecollection'] = 'You have 1 collection.';
$string['youhavecollections'] = 'You have %s collections.';
$string['collectionssharedtogroup'] = 'Collections shared with this group';
......@@ -62,7 +62,9 @@ $string['accessbetweendates2'] = 'Nobody else can see this page before %s or aft
$string['artefactsinthisview'] = 'Artefacts in this page';
$string['whocanseethisview'] = 'Who can see this page';
$string['view'] = 'page';
$string['vieworcollection'] = 'page or collection';
$string['views'] = 'pages';
$string['viewsandcollections'] = 'pages and collections';
$string['View'] = 'Page';
$string['Views'] = 'Pages';
$string['viewsubmittedtogroup'] = 'This page has been submitted to <a href="%s">%s</a>.';
......
......@@ -4145,7 +4145,7 @@ class View {
/**
* Get views which have been explicitly shared to a group and are
* not owned by the group
* not owned by the group excluding the view in collections
*/
public static function get_sharedviews_data($limit=10, $offset=0, $groupid) {
global $USER;
......@@ -4158,12 +4158,13 @@ class View {
FROM {view} v
INNER JOIN {view_access} a ON (a.view = v.id)
INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL))
WHERE a.group = ? AND m.member = ? AND (v.group IS NULL OR v.group != ?)';
WHERE a.group = ? AND m.member = ? AND (v.group IS NULL OR v.group != ?)
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)';
$ph = array($groupid, $userid, $groupid);
$count = count_records_sql('SELECT COUNT(*) ' . $from, $ph);
$count = count_records_sql('SELECT COUNT(DISTINCT(v.id)) ' . $from, $ph);
$viewdata = get_records_sql_assoc('
SELECT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat,v.institution,v.urlid ' . $from . '
SELECT DISTINCT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat,v.institution,v.urlid ' . $from . '
ORDER BY v.title, v.id',
$ph, $offset, $limit
);
......@@ -4183,6 +4184,53 @@ class View {
);
}
/**
* Get collections which have been explicitly shared to a group and are
* not owned by the group
* @param $limit, $offset for pagination
* @param $groupid
* @return array of collections
*/
public static function get_sharedcollections_data($limit=10, $offset=0, $groupid) {
global $USER;
$userid = $USER->get('id');
require_once(get_config('libroot') . 'group.php');
if (!group_user_access($groupid)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$from = '
FROM {collection} c
INNER JOIN {collection_view} cv ON (cv.collection = c.id)
INNER JOIN {view_access} a ON (a.view = cv.view)
INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL))
WHERE a.group = ? AND m.member = ? AND (c.group IS NULL OR c.group != ?)';
$ph = array($groupid, $userid, $groupid);
$count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from, $ph);
$collectiondata = get_records_sql_assoc('
SELECT DISTINCT c.id,c.name,c.description,c.owner,c.group,c.institution ' . $from . '
ORDER BY c.name, c.id',
$ph, $offset, $limit
);
if ($collectiondata) {
View::get_extra_collection_info($collectiondata, false);
}
else {
$collectiondata = array();
}
return (object) array(
'data' => array_values($collectiondata),
'count' => $count,
'limit' => $limit,
'offset' => $offset,
);
}
public static function get_extra_view_info(&$viewdata, $getartefacts=true, $gettags=true) {
if ($viewdata) {
// Get view owner details for display
......@@ -4292,6 +4340,86 @@ class View {
}
}
/**
* Get more info for the collections: owner, url, tags
*
* @param array a list of collections $collectiondata
* @return array updated collection data
*/
public static function get_extra_collection_info(&$collectiondata) {
if ($collectiondata) {
// Get view owner details for display
$owners = array();
$groups = array();
$institutions = array();
foreach ($collectiondata as $c) {
if (!empty($c->owner) && !isset($owners[$c->owner])) {
$owners[$c->owner] = (int)$c->owner;
}
else if (!empty($c->group) && !isset($groups[$c->group])) {
$groups[$c->group] = (int)$c->group;
}
else if (!empty($c->institution) && !isset($institutions[$c->institution])) {
$institutions[$c->institution] = $c->institution;
}
}
if (!empty($owners)) {
global $USER;
$userid = $USER->get('id');
$fields = array(
'id', 'username', 'firstname', 'lastname', 'preferredname', 'admin', 'staff', 'studentid', 'email',
'profileicon', 'urlid', 'suspendedctime',
);
if (count($owners) == 1 && isset($owners[$userid])) {
$owners = array($userid => new StdClass);
foreach ($fields as $f) {
$owners[$userid]->$f = $USER->get($f);
}
}
else {
$owners = get_records_select_assoc(
'usr', 'id IN (' . join(',', array_fill(0, count($owners), '?')) . ')', $owners, '',
join(',', $fields)
);
}
}
if (!empty($groups)) {
$groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name,urlid');
}
if (!empty($institutions)) {
$institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
$institutions['mahara']->displayname = get_config('sitename');
}
$wwwroot = get_config('wwwroot');
$needsubdomain = get_config('cleanurlusersubdomains');
foreach ($collectiondata as &$c) {
if (!empty($c->owner)) {
$c->sharedby = display_name($owners[$c->owner]);
$c->user = $owners[$c->owner];
}
else if (!empty($c->group)) {
$c->sharedby = $groups[$c->group]->name;
$c->groupdata = $groups[$c->group];
}
else if (!empty($c->institution)) {
$c->sharedby = $institutions[$c->institution]->displayname;
}
$c = (array)$c;
// Now that we have the owner & group records, create a temporary Collection object
// so that we can use get_url method.
require_once(get_config('libroot') . 'collection.php');
$collection = new Collection(0, $c);
$c['url'] = $collection->get_url(false);
$c['fullurl'] = $needsubdomain ? $collection->get_url(true) : ($wwwroot . $c['url']);
}
}
}
public static function set_nav($group, $institution, $share=false, $collection=false) {
if ($group) {
define('MENUITEM', $share ? 'groups/share' : 'groups/views');
......
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