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

Merge "Let "group pages" show pages by group members only"

parents 5a10b391 469ef3c8
......@@ -25,3 +25,6 @@ $string['displaysubmissionsdesc'] = 'Show a list of pages and collections submit
$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';
$string['showbyanybody'] = 'By anybody';
$string['showbygroupmembers'] = 'By members of this group';
$string['shownone'] = 'None';
......@@ -187,8 +187,9 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'title' => get_string('displaysharedviews', 'blocktype.groupviews'),
'description' => get_string('displaysharedviewsdesc1', 'blocktype.groupviews'),
'options' => array(
1 => get_string('yes'),
0 => get_string('no'),
0 => get_string('shownone', 'blocktype.groupviews'),
1 => get_string('showbygroupmembers', 'blocktype.groupviews'),
2 => get_string('showbyanybody', 'blocktype.groupviews'),
),
'separator' => '<br>',
'defaultvalue' => isset($configdata['showsharedviews']) ? $configdata['showsharedviews'] : 1,
......@@ -198,8 +199,9 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'title' => get_string('displaysharedcollections', 'blocktype.groupviews'),
'description' => get_string('displaysharedcollectionsdesc', 'blocktype.groupviews'),
'options' => array(
1 => get_string('yes'),
0 => get_string('no'),
0 => get_string('shownone', 'blocktype.groupviews'),
1 => get_string('showbygroupmembers', 'blocktype.groupviews'),
2 => get_string('showbyanybody', 'blocktype.groupviews'),
),
'separator' => '<br>',
'defaultvalue' => isset($configdata['showsharedcollections']) ? $configdata['showsharedcollections'] : 1,
......@@ -256,14 +258,44 @@ 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($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));
if (empty($configdata['showsharedviews'])) {
$data['sharedviews'] = (object) array(
'data' => array(),
'count' => 0,
'limit' => $limit,
'offset' => 0
);
}
else {
$data['sharedviews'] = View::get_sharedviews_data(
$limit,
0,
$group->id,
($configdata['showsharedviews'] == 2 ? false : true)
);
foreach ($data['sharedviews']->data as &$view) {
if (!$editing && isset($view['template']) && $view['template']) {
$view['form'] = pieform(create_view_form($group, null, $view->id));
}
}
}
$data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id);
if (empty($configdata['showsharedcollections'])) {
$data['sharedcollections'] = (object) array(
'data' => array(),
'count' => 0,
'limit' => $limit,
'offset' => 0
);
}
else {
$data['sharedcollections'] = View::get_sharedcollections_data(
$limit,
0,
$group->id,
($configdata['showsharedcollections'] == 2 ? false : true)
);
}
if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
// Display a list of views submitted to the group
......
......@@ -40,7 +40,12 @@ if (!isset($configdata['showsharedcollections'])) {
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
$sharedcollections = (array)View::get_sharedcollections_data($limit, $offset, $groupid);
$sharedcollections = (array) View::get_sharedcollections_data(
$limit,
$offset,
$groupid,
($configdata['showsharedcollections'] == 2 ? true : false)
);
if (!empty($configdata['showsharedcollections']) && isset($sharedcollections)) {
$baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
......
......@@ -40,7 +40,12 @@ if (!isset($configdata['showsharedviews'])) {
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;
$sharedviews = (array)View::get_sharedviews_data($limit, $offset, $groupid);
$sharedviews = (array) View::get_sharedviews_data(
$limit,
$offset,
$groupid,
($configdata['showsharedviews'] == 2 ? false : true)
);
foreach ($sharedviews['data'] as &$view) {
if (isset($view['template']) && $view['template']) {
$view['form'] = pieform(create_view_form($group_homepage_view, null, $view->id));
......
......@@ -13,5 +13,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010061800;
$config->release = '0.9.0';
$config->version = 2015011500;
$config->release = '1.0.0';
......@@ -2286,7 +2286,11 @@ function install_system_grouphomepage_view() {
'title' => '',
'row' => 1,
'column' => 1,
'config' => array('showgroupviews' => 1, 'showsharedviews' => 1),
'config' => array(
'showgroupviews' => 1,
'showsharedviews' => 1,
'showsharedcollections' => 1,
),
),
array(
'blocktype' => 'groupmembers',
......
......@@ -4338,8 +4338,14 @@ class View {
/**
* Get views which have been explicitly shared to a group and are
* not owned by the group excluding the view in collections
*
* @param int $limit
* @param int $offset
* @param int $groupid
* @param boolean $membersonly Only return pages owned by members of the gorup
* @throws AccessDeniedException
*/
public static function get_sharedviews_data($limit=10, $offset=0, $groupid) {
public static function get_sharedviews_data($limit=10, $offset=0, $groupid, $membersonly = false) {
global $USER;
$userid = $USER->get('id');
require_once(get_config('libroot') . 'group.php');
......@@ -4350,15 +4356,24 @@ 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 = '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(DISTINCT(v.id)) ' . $from, $ph);
if ($membersonly) {
$from .= ' INNER JOIN {group_member} m2 ON m2.member = v.owner ';
$where .= ' AND m2.group = ? ';
$ph[] = $groupid;
}
$count = count_records_sql('SELECT COUNT(DISTINCT(v.id)) ' . $from . $where, $ph);
$viewdata = get_records_sql_assoc('
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
SELECT DISTINCT v.id, v.title, v.startdate, v.stopdate, v.description, v.group, v.owner, v.ownerformat, v.institution, v.urlid '
. $from
. $where
. ' ORDER BY v.title, v.id',
$ph,
$offset,
$limit
);
if ($viewdata) {
......@@ -4379,11 +4394,13 @@ 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
* @param integer $limit
* @param integer $offset
* @param integer $groupid
* @param boolean $membersonly Only return collections owned by members of the gorup
* @return array of collections
*/
public static function get_sharedcollections_data($limit=10, $offset=0, $groupid) {
public static function get_sharedcollections_data($limit=10, $offset=0, $groupid, $membersonly = false) {
global $USER;
$userid = $USER->get('id');
......@@ -4397,14 +4414,21 @@ class View {
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 != ?)';
INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL)) ';
$where = ' WHERE a.group = ? AND m.member = ? AND (c.group IS NULL OR c.group != ?) ';
$ph = array($groupid, $userid, $groupid);
if ($membersonly) {
$from .= ' INNER JOIN {group_member} m2 ON m2.member = c.owner ';
$where .= ' AND m2.group = ? ';
$ph[] = $groupid;
}
$count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from, $ph);
$count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from . $where, $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',
SELECT DISTINCT c.id, c.name, c.description, c.owner, c.group, c.institution '
. $from
. $where
. ' ORDER BY c.name, c.id',
$ph, $offset, $limit
);
......
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