Commit 63129f38 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols Committed by Evan Goldenberg
Browse files

Add view submission to group



This gives users a list of all views they haven't yet submitted to any
group if they're in the group/view.php page for a group which is of a
submittableto group type, and to which they haven't already submitted a
view to.
I've added a duplicate language string for 'Submit' as I suspect the submit
button text won't work for translations in this context.
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Signed-off-by: default avatarEvan Goldenberg <evang@catalyst.net.nz>
parent 2e930abb
......@@ -122,6 +122,14 @@ if ($role) {
$smarty->assign('submittedviews', View::get_submitted_views($group->id));
}
}
if (group_allows_submission($group->grouptype) &&
!get_record_select('view', 'owner = ? AND submittedgroup = ?', array($USER->get('id'), $group->id))
&& ($viewdata = View::get_user_views())) {
$group_view_submission_form = group_view_submission_form($group->id, $viewdata);
$smarty->assign('group_view_submission_form', $group_view_submission_form);
}
$smarty->assign('role', $role);
$smarty->display('group/view.tpl');
......
......@@ -283,4 +283,7 @@ $string['Joined'] = 'Joined';
$string['instructions:invite'] = 'This is an invite-only group. Invite users through their profile pages.';
$string['instructions:controlled'] = 'This is a controlled membership group. Add users through their profile pages.';
// View submission
$string['submit'] = 'Submit';
?>
......@@ -618,6 +618,49 @@ function group_removeuser_submit(Pieform $form, $values) {
redirect('/group/members.php?id=' . $group);
}
/**
* Form for submitting views to a group
*/
function group_view_submission_form($groupid, $viewdata) {
$options = array();
foreach ($viewdata as $view) {
$options[$view->id] = $view->title;
}
return pieform(array(
'name' => 'group_view_submission_form_' . $groupid,
'method' => 'post',
'renderer' => 'oneline',
'autofocus' => false,
'successcallback' => 'group_view_submission_form_submit',
'elements' => array(
'text1' => array(
'type' => 'html', 'value' => get_string('submit', 'group') . ' ',
),
'options' => array(
'type' => 'select',
'collapseifoneoption' => false,
'options' => $options,
),
'text2' => array(
'type' => 'html',
'value' => get_string('forassessment', 'view'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('submit')
),
'group' => array(
'type' => 'hidden',
'value' => $groupid
)
),
));
}
function group_view_submission_form_submit(Pieform $form, $values) {
redirect('/view/submit.php?id=' . $values['options'] . '&group=' . $values['group']);
}
// Miscellaneous group related functions
/**
......@@ -1179,4 +1222,8 @@ function group_get_user_course_groups($userid=null) {
}
return array();
}
function group_allows_submission($grouptype) {
return get_field('grouptype', 'submittableto', 'name', $grouptype);
}
?>
......@@ -2123,6 +2123,24 @@ class View {
);
}
public function get_user_views($userid=null) {
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
}
if ($views = get_records_sql_array(
"SELECT v.id, v.title
FROM {view} v
LEFT OUTER JOIN {group} g on (v.submittedgroup = g.id AND g.deleted = 0)
LEFT OUTER JOIN {host} h on (v.submittedhost = h.wwwroot)
WHERe v.owner = ?
AND v.type != 'profile'
ORDER BY v.title, v.id
", array($userid))) {
return $views;
}
return array();
}
/**
* Returns an SQL snippet that can be used in a where clause to get views
......
......@@ -62,6 +62,11 @@
</p>
{/if}
{if $group_view_submission_form}
<h3>{str tag="viewssubmittedtogroup" section="view"}</h3>
<div>{$group_view_submission_form}</div>
{/if}
{if $submittedviews}
<h3>{str tag="viewssubmittedtogroup" section="view"}</h3>
<p>
......
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