Commit 1d32b517 authored by Nigel McNie's avatar Nigel McNie
Browse files

Rename can_assess_submitted_views to group_user_can_assess_submitted_views.

Perform validation on the parameters while we're in the area.
parent cb212bf2
......@@ -191,6 +191,45 @@ function group_user_can_edit_views($groupid, $userid=null) {
AND m.member = ?', array($groupid, $userid));
}
/**
* Returns whether a user is allowed to assess views that have been submitted
* to the given group.
*
* @param int $groupid ID of group
* @param int $userid ID of user
* @return boolean
*/
function group_user_can_assess_submitted_views($groupid, $userid) {
$groupid = (int)$groupid;
if ($groupid == 0) {
throw new InvalidArgumentException("group_user_can_assess_submitted_views: group argument should be an integer");
}
if (is_null($userid)) {
global $USER;
$userid = (int)$USER->get('id');
}
else {
$userid = (int)$userid;
}
if ($userid == 0) {
throw new InvalidArgumentException("group_user_can_assess_submitted_views: user argument should be an integer");
}
return get_field_sql('
SELECT
r.see_submitted_views
FROM
{group_member} m
INNER JOIN {group} g ON (m.group = g.id AND g.deleted = 0)
INNER JOIN {grouptype_roles} r ON (g.grouptype = r.grouptype AND r.role = m.role)
WHERE
m.member = ?
AND m.group = ?', array($userid, $groupid));
}
/**
* Creates a group.
*
......@@ -689,20 +728,6 @@ function group_get_grouptypes() {
}
function can_assess_submitted_views($userid, $groupid) {
return get_field_sql('
SELECT
r.see_submitted_views
FROM
{group_member} m
INNER JOIN {group} g ON (m.group = g.id AND g.deleted = 0)
INNER JOIN {grouptype_roles} r ON (g.grouptype = r.grouptype AND r.role = m.role)
WHERE
m.member = ?
AND m.group = ?', array($userid, $groupid));
}
/**
* Returns a list of grouptype & jointype options to be used in create
* group/edit group drop-downs.
......
......@@ -1306,7 +1306,7 @@ function can_view_view($view_id, $user_id=null) {
if ($submitgroup = $view->get('submittedto')) {
require_once(get_config('docroot') . 'lib/group.php');
if (can_assess_submitted_views($user_id, $submitgroup)) {
if (group_user_can_assess_submitted_views($submitgroup, $user_id)) {
return true;
}
}
......
......@@ -54,7 +54,7 @@ if (!$group) {
$tutorfilefeedbackformrow = '';
$submittedgroup = (int)$view->get('submittedto');
if ($submittedgroup && can_assess_submitted_views($USER->get('id'), $submittedgroup)) {
if ($submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
// The user is a tutor of the group that this view has
// been submitted to, and is entitled to upload an additional
// file when submitting feedback.
......
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