Commit 457e2f19 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow users to put their own files into group views (bug 3283)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d4f0e071
......@@ -189,7 +189,7 @@ function pieform_element_filebrowser_build_path($form, $element, $folder, $owner
}
function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null, $group=null, $institution=null) {
function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null, $user=null, $group=null, $institution=null) {
if (!$form->submitted_by_js()) {
// We're going to rebuild the page from scratch anyway.
return;
......@@ -199,7 +199,7 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$smarty = smarty_core();
if (is_null($group)) {
if (is_null($group) && is_null($user)) {
$group = $form->get_property('group');
}
else {
......@@ -260,6 +260,7 @@ function pieform_element_filebrowser_configure_tabs($viewowner) {
else if ($viewowner['type'] == 'group') {
$selectedtab = param_variable('owner', 'group');
$upload = $selectedtab == 'group';
$tabs['user'] = get_string('myfiles', 'artefact.file');
$tabs['group'] = get_string('groupfiles', 'artefact.file');
}
else { // $viewowner['type'] == 'user'
......@@ -924,6 +925,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
$group = null;
$institution = null;
$user = null;
$folder = 0;
if ($newtabdata['owner'] == 'site') {
global $USER;
......@@ -938,6 +940,9 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
else if ($newtabdata['owner'] == 'group') {
$group = $newtabdata['ownerid'];
}
else if ($newtabdata['owner'] == 'user') {
$user = true;
}
return array(
'error' => false,
......@@ -945,7 +950,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
'changedfolder' => true,
'tabupload' => $newtabdata['upload'],
'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $newtabdata['owner'], $newtabdata['ownerid']),
'newtabs' => $newtabhtml,
'newsubtabs' => $newsubtabhtml,
......@@ -954,7 +959,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
function pieform_element_filebrowser_changefolder(Pieform $form, $element, $folder) {
$owner = $ownerid = $group = $institution = null;
$owner = $ownerid = $group = $institution = $user = null;
if (isset($element['tabs'])) {
if ($owner = param_variable('owner', null)) {
......@@ -964,9 +969,13 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold
} else if ($ownerid = param_variable('ownerid', null)) {
if ($owner == 'group') {
$group = (int) $ownerid;
} else if ($owner == 'institution') {
}
else if ($owner == 'institution') {
$institution = $ownerid;
}
else if ($owner == 'user') {
$user = true;
}
}
}
}
......@@ -975,7 +984,7 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold
'error' => false,
'changedfolder' => true,
'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid),
);
}
......
......@@ -807,6 +807,11 @@ class BlockInstance {
public function rebuild_artefact_list() {
db_begin();
// Remember what was in this block before saving, and always allow those artefacts to remain
// in it, regardless of the user's current permissions.
$old = get_records_assoc('view_artefact', 'block', $this->id, '', 'artefact, id');
delete_records('view_artefact', 'block', $this->id);
safe_require('blocktype', $this->get('blocktype'));
if (!$artefacts = call_static_method(
......@@ -832,6 +837,7 @@ class BlockInstance {
require_once('view.php');
$searchdata = array(
'extraselect' => 'id IN (' . join(',', $artefacts) . ')',
'userartefactsallowed' => true, // If this is a group view, the user can add personally owned artefacts
);
list($allowed, $count) = View::get_artefactchooser_artefacts(
$searchdata,
......@@ -846,7 +852,7 @@ class BlockInstance {
$va->block = $this->id;
foreach ($artefacts as $id) {
if (isset($allowed[$id])) {
if (isset($allowed[$id]) || isset($old[$id])) {
$va->artefact = $id;
insert_record('view_artefact', $va);
}
......
......@@ -1849,7 +1849,11 @@ class View {
AND m.member = ' . $user->get('id') . '
AND r.can_view = 1
) ga ON (ga.group = a.group AND a.id = ga.artefact)';
$select = "(a.institution = 'mahara' OR ga.can_view = 1)";
$select = "(a.institution = 'mahara' OR ga.can_view = 1";
if (!empty($data['userartefactsallowed'])) {
$select .= ' OR owner = ' . $user->get('id');
}
$select .= ')';
}
else if ($institution) {
// Site artefacts & artefacts owned by this institution
......
Supports Markdown
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