Commit 648b5607 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Split group views page into shared & owned sections

parent e7c0a48c
......@@ -68,6 +68,8 @@ $string['Views'] = 'Views';
$string['viewsubmittedtogroup'] = 'This View has been submitted to <a href="' . get_config('wwwroot') . 'group/view.php?id=%s">%s</a>';
$string['nobodycanseethisview'] = 'Nobody can see this View';
$string['noviews'] = 'You have no Views.';
$string['viewsownedbygroup'] = 'Views owned by this group';
$string['viewssharedtogroup'] = 'Views shared to this group';
// access levels
$string['public'] = 'Public';
......
......@@ -362,7 +362,9 @@ class View {
break;
case 'group':
$accessrecord->group = $item['id'];
$accessrecord->role = $item['role'];
if ($item['role']) {
$accessrecord->role = $item['role'];
}
insert_record('view_access_group', $accessrecord);
break;
}
......@@ -1255,6 +1257,82 @@ class View {
return array($result, $pagination, $totalartefacts, $offset);
}
public static function owner_name($ownerformat, $user) {
switch ($ownerformat) {
case FORMAT_NAME_FIRSTNAME:
return $user->firstname;
case FORMAT_NAME_LASTNAME:
return $user->lastname;
case FORMAT_NAME_FIRSTNAMELASTNAME:
return $user->firstname . ' ' . $user->lastname;
case FORMAT_NAME_PREFERREDNAME:
return $user->preferredname;
case FORMAT_NAME_STUDENTID:
return $user->studentid;
case FORMAT_NAME_DISPLAYNAME:
default:
return display_name($user);
}
}
public static function get_sharedviews_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();
}
$from = '
FROM {view} v
INNER JOIN {view_access_group} 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 a.group <> v.group';
$ph = array($groupid, $userid);
$count = count_records_sql('SELECT COUNT(*) ' . $from, $ph);
$viewdata = get_records_sql_array('
SELECT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat ' . $from . '
ORDER BY v.title, v.id',
$ph, $offset, $limit
);
if ($viewdata) {
// Get view owner details for display
$owners = array();
$groups = array();
foreach ($viewdata as $v) {
if ($v->owner && !isset($owners[$v->owner])) {
$owners[$v->owner] = $v->owner;
} else if ($v->group && !isset($groups[$v->group])) {
$groups[$v->group] = $v->group;
}
}
if (!empty($owners)) {
$owners = get_records_select_assoc('usr', 'id IN (' . join(',', $owners) . ')', null, '',
'id,username,firstname,lastname,preferredname,admin,staff,studentid');
}
if (!empty($groups)) {
$groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name');
}
foreach ($viewdata as &$v) {
if ($v->owner) {
$v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]);
} else if ($v->group) {
$v->sharedby = $groups[$v->group]->name;
}
$v = (array)$v;
}
}
return (object) array(
'data' => $viewdata,
'count' => $count,
);
}
public static function get_myviews_data($limit=5, $offset=0, $groupid=null) {
......@@ -1262,10 +1340,6 @@ class View {
$userid = $USER->get('id');
if ($groupid) {
require_once(get_config('docroot') . 'lib/group.php');
if (!group_user_access($groupid)) {
throw new AccessDeniedException();
}
$count = count_records('view', 'group', $groupid);
$viewdata = get_records_sql_array('SELECT v.id,v.title,v.startdate,v.stopdate,v.description
FROM {view} v
......
......@@ -2,14 +2,26 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
{if (!$groupid || $caneditgroupview)}
<span class="addicon fr">
<a href="{$WWWROOT}view/edit.php{if $groupid}?group={$groupid}{/if}">{str tag="createview" section="view"}</a>
</span>
{/if}
<h2>{$heading}</h2>
{if $groupid}{include file="group/tabstart.tpl" current="views"}{/if}
{if $groupid}
{include file="group/tabstart.tpl" current="views"}
<ul>
<li>
{if $shared}<a href="groupviews.php?group={$groupid}">{str tag="viewsownedbygroup" section="view"}</a>
{else}{str tag="viewsownedbygroup" section="view"}
{/if}
</li>
<li>
{if $shared}{str tag="viewssharedtogroup" section="view"}
{else}<a href="groupviews.php?group={$groupid}&shared=1">{str tag="viewssharedtogroup" section="view"}</a>
{/if}
</li>
</ul>
{/if}
{if $views}
<table id="myviewstable">
......
{include file="header.tpl"}
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
{if ($caneditgroupview)}
<span class="addicon fr">
<a href="{$WWWROOT}view/edit.php?group={$groupid}">{str tag="createview" section="view"}</a>
</span>
{/if}
<h2>{$heading}</h2>
{include file="group/tabstart.tpl" current="views"}
{if $member}
<ul>
<li>
{if $shared}<a href="groupviews.php?group={$groupid}">{str tag="viewsownedbygroup" section="view"}</a>
{else}{str tag="viewsownedbygroup" section="view"}
{/if}
</li>
<li>
{if $shared}{str tag="viewssharedtogroup" section="view"}
{else}<a href="groupviews.php?group={$groupid}&shared=1">{str tag="viewssharedtogroup" section="view"}</a>
{/if}
</li>
</ul>
{/if}
{if $views}
<table id="myviewstable">
{foreach from=$views item=view}
<tr class="{cycle values=r0,r1}">
<td><h3><a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.title|escape}</a></h3></td>
<td>
by <a href="{$WWWROOT}{if $view.group}group{else}user{/if}/view.php?id={if $view.group}{$view.group}{else}{$view.owner}{/if}">{if $view.sharedby}{$view.sharedby}{else}{$groupname}{/if}</a>
</td>
<td>{$view.description}</td>
</tr>
{/foreach}
</table>
<div class="center">{$pagination}</div>
{else}
<div class="message">{str tag="noviews" section="view"}</div>
{/if}
{include file="group/tabend.tpl"}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -189,11 +189,11 @@ function editview_submit(Pieform $form, $values) {
if (empty($editing) && $group) {
// By default, group views should be visible to the group
$view->set_access(array(array(
'type' => 'group',
'id' => $group,
'type' => 'group',
'id' => $group,
'startdate' => null,
'stopdate' => null,
'role' => null
'stopdate' => null,
'role' => null
)));
$view->commit();
}
......
......@@ -32,8 +32,8 @@ define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'groupviews');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'lib/view.php');
require_once(get_config('docroot') . 'lib/group.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('groupviews', 'view'));
......@@ -43,7 +43,14 @@ $limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$group = param_integer('group');
$data = View::get_myviews_data($limit, $offset, $group);
$member = group_user_access($group);
$shared = param_boolean('shared', 0) && $member;
if ($shared) {
$data = View::get_sharedviews_data($limit, $offset, $group);
} else {
$data = View::get_myviews_data($limit, $offset, $group);
}
$userid = $USER->get('id');
......@@ -56,12 +63,20 @@ $pagination = build_pagination(array(
'resultcounttextplural' => get_string('views', 'view')
));
$groupname = get_field('group', 'name', 'id', $group);
$smarty = smarty();
$smarty->assign('groupid', $group);
$smarty->assign('groupname', $groupname);
$smarty->assign('shared', $shared);
$smarty->assign('member', $member);
$smarty->assign('views', $data->data);
$smarty->assign('caneditgroupview', group_user_can_edit_views($group));
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('heading', get_string('groupviewsfor', 'view', get_field('group', 'name', 'id', $group)));
$smarty->display('view/index.tpl');
$smarty->assign('heading', get_string('groupviews', 'view'));
if (group_user_can_edit_views($group) && !$shared) {
$smarty->display('view/index.tpl');
} else {
$smarty->display('view/sharedviews.tpl');
}
?>
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