Skip to content

Commit

Permalink
MDL-53821 mod_assign: Hide full name when blind marking
Browse files Browse the repository at this point in the history
Hide the student's full name in the new grading intferface when blind
marking is on.
  • Loading branch information
ryanwyllie committed May 10, 2016
1 parent 1e72daa commit 1b2f9dc
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mod/assign/amd/build/grading_navigation_user_info.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 39 additions & 16 deletions mod/assign/amd/src/grading_navigation_user_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function(
var UserInfo = function(selector) {
this._regionSelector = selector;
this._region = $(selector);
this._userCache = [];
this._userCache = {};

$(document).on('user-changed', this._refreshUserInfo.bind(this));
};
Expand All @@ -51,6 +51,17 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function(
/** @type {Integer} Remember the last user id to prevent unnessecary reloads. */
UserInfo.prototype._lastUserId = 0;

/**
* Get the assignment id
*
* @private
* @method _getAssignmentId
* @return int assignment id
*/
UserInfo.prototype._getAssignmentId = function() {
return this._region.attr('data-assignmentid');
};

/**
* Get the user context - re-render the template in the page.
*
Expand Down Expand Up @@ -92,18 +103,21 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function(
promise.resolve(this._userCache[userid]);
} else {
// Load context from ajax.
var assignmentId = this._getAssignmentId();
var requests = ajax.call([{
methodname: 'core_user_get_users_by_field',
args: { field: 'id', values: [ userid ] }
methodname: 'mod_assign_get_participant',
args: {
userid: userid,
assignid: assignmentId,
embeduser: true
}
}]);

requests[0].done(function(result) {
if (result.length < 1) {
requests[0].done(function(participant) {
if (!participant.hasOwnProperty('id')) {
promise.reject('No users');
} else {
$.each(result, function(index, user) {
this._userCache[user.id] = user;
}.bind(this));
this._userCache[userid] = participant;
promise.resolve(this._userCache[userid]);
}
}.bind(this)).fail(notification.exception);
Expand All @@ -114,14 +128,22 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function(
identity = [];
// Render the template.
context.courseid = $('[data-region="grading-navigation-panel"]').attr('data-courseid');
// Build a string for the visible identity fields listed in showuseridentity config setting.
$.each(identityfields, function(i, k) {
if (typeof context[k] !== 'undefined' && context[k] !== '') {
context.hasidentity = true;
identity.push(context[k]);

if (context.user) {
// Build a string for the visible identity fields listed in showuseridentity config setting.
$.each(identityfields, function(i, k) {
if (typeof context.user[k] !== 'undefined' && context.user[k] !== '') {
context.hasidentity = true;
identity.push(context.user[k]);
}
});
context.identity = identity.join(', ');

// Add profile image url to context.
if (context.user.profileimageurl) {
context.profileimageurl = context.user.profileimageurl;
}
});
context.identity = identity.join(', ');
}

templates.render('mod_assign/grading_navigation_user_summary', context).done(function(html, js) {
// Update the page.
Expand All @@ -139,7 +161,8 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates'], function(
this._region.fadeIn("fast");
}.bind(this));
}.bind(this)).fail(notification.exception);
});
}
.bind(this));
}.bind(this)).fail(notification.exception);
};

Expand Down
9 changes: 9 additions & 0 deletions mod/assign/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,13 @@
'ajax' => true,
'capabilities' => 'mod/assign:grade'
),
'mod_assign_get_participant' => array(
'classname' => 'mod_assign_external',
'methodname' => 'get_participant',
'classpath' => 'mod/assign/externallib.php',
'description' => 'Get a participant for an assignment, with some summary info about their submissions.',
'type' => 'read',
'ajax' => true,
'capabilities' => 'mod/assign:view, mod/assign:viewgrades'
),
);
102 changes: 102 additions & 0 deletions mod/assign/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
defined('MOODLE_INTERNAL') || die;

require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/user/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php");

/**
Expand Down Expand Up @@ -2762,4 +2763,105 @@ public static function list_participants_returns() {
))
);
}

/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.1
*/
public static function get_participant_parameters() {
return new external_function_parameters(
array(
'assignid' => new external_value(PARAM_INT, 'assign instance id'),
'userid' => new external_value(PARAM_INT, 'user id'),
'embeduser' => new external_value(PARAM_BOOL, 'user id', VALUE_DEFAULT, false),
)
);
}

/**
* Get the user participating in the given assignment. An error with code 'usernotincourse'
* is thrown is the user isn't a participant of the given assignment.
*
* @param int $assignid the assign instance id
* @param int $userid the user id
* @param bool $embeduser return user details (only applicable if not blind marking)
* @return array of warnings and status result
* @since Moodle 3.1
* @throws moodle_exception
*/
public static function get_participant($assignid, $userid, $embeduser) {
global $DB, $CFG;
require_once($CFG->dirroot . "/mod/assign/locallib.php");
require_once($CFG->dirroot . "/user/lib.php");

$params = self::validate_parameters(self::get_participant_parameters(), array(
'assignid' => $assignid,
'userid' => $userid,
'embeduser' => $embeduser
));

// Request and permission validation.
$assign = $DB->get_record('assign', array('id' => $params['assignid']), 'id', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign');

$context = context_module::instance($cm->id);
self::validate_context($context);

$assign = new assign($context, null, null);
$assign->require_view_grades();

$participant = $assign->get_participant($params['userid']);
if (!$participant) {
// No participant found so we can return early.
throw new moodle_exception('usernotincourse');
}

$return = array(
'id' => $participant->id,
'fullname' => $participant->fullname,
'submitted' => $participant->submitted,
'requiregrading' => $participant->requiregrading,
'blindmarking' => $assign->is_blind_marking(),
);

if (!empty($participant->groupid)) {
$return['groupid'] = $participant->groupid;
}
if (!empty($participant->groupname)) {
$return['groupname'] = $participant->groupname;
}

// Skip the expensive lookup of user detail if we're blind marking or the caller
// hasn't asked for user details to be embedded.
if (!$assign->is_blind_marking() && $embeduser) {
$return['user'] = user_get_user_details($participant, $course);
}

return $return;
}

/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 3.1
*/
public static function get_participant_returns() {
$userdescription = core_user_external::user_description();
$userdescription->default = [];
$userdescription->required = VALUE_OPTIONAL;

return new external_single_structure(array(
'id' => new external_value(PARAM_INT, 'ID of the user'),
'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
'submitted' => new external_value(PARAM_BOOL, 'have they submitted their assignment'),
'requiregrading' => new external_value(PARAM_BOOL, 'is their submission waiting for grading'),
'blindmarking' => new external_value(PARAM_BOOL, 'is blind marking enabled for this assignment'),
'groupid' => new external_value(PARAM_INT, 'for group assignments this is the group id', VALUE_OPTIONAL),
'groupname' => new external_value(PARAM_NOTAGS, 'for group assignments this is the group name', VALUE_OPTIONAL),
'user' => $userdescription,
));
}
}
10 changes: 8 additions & 2 deletions mod/assign/gradingtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,14 @@ public function col_grade(stdClass $row) {
if (!$this->is_downloading() && $this->hasgrade) {
$urlparams = array('id' => $this->assignment->get_course_module()->id,
'rownum' => 0,
'action' => 'grader',
'userid' => $row->userid);
'action' => 'grader');

if ($this->assignment->is_blind_marking()) {
$urlparams['blindid'] = $this->assignment->get_uniqueid_for_user($row->userid);
} else {
$urlparams['userid'] = $row->userid;
}

$url = new moodle_url('/mod/assign/view.php', $urlparams);
$link = '<a href="' . $url . '" class="btn btn-primary">' . get_string('grade') . '</a>';
$grade .= $link . $separator;
Expand Down
60 changes: 54 additions & 6 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1446,18 +1446,20 @@ class="quickgrade"/>';
}

/**
* Get the submission status/grading status for all submissions in this assignment.
* Get the submission status/grading status for all submissions in this assignment for the
* given paticipants.
*
* These statuses match the available filters (requiregrading, submitted, notsubmitted).
* If this is a group assignment, group info is also returned.
*
* @param int $currentgroup
* @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'groupid', 'groupname'
* @param array $participants an associative array where the key is the participant id and
* the value is the participant record.
* @return array an associative array where the key is the participant id and the value is
* the participant record.
*/
public function list_participants_with_filter_status_and_group($currentgroup) {
private function get_submission_info_for_participants($participants) {
global $DB;

$participants = $this->list_participants($currentgroup, false);

if (empty($participants)) {
return $participants;
}
Expand Down Expand Up @@ -1523,6 +1525,24 @@ public function list_participants_with_filter_status_and_group($currentgroup) {
return $participants;
}

/**
* Get the submission status/grading status for all submissions in this assignment.
* These statuses match the available filters (requiregrading, submitted, notsubmitted).
* If this is a group assignment, group info is also returned.
*
* @param int $currentgroup
* @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'groupid', 'groupname'
*/
public function list_participants_with_filter_status_and_group($currentgroup) {
$participants = $this->list_participants($currentgroup, false);

if (empty($participants)) {
return $participants;
} else {
return $this->get_submission_info_for_participants($participants);
}
}

/**
* Load a list of users enrolled in the current course with the specified permission and group.
* 0 for no group.
Expand Down Expand Up @@ -1564,6 +1584,29 @@ public function list_participants($currentgroup, $idsonly) {
return $this->participants[$key];
}

/**
* Load a user if they are enrolled in the current course. Populated with submission
* status for this assignment.
*
* @param int $userid
* @return null|stdClass user record
*/
public function get_participant($userid) {
global $DB;

$participant = $DB->get_record('user', array('id' => $userid));
if (!$participant) {
return null;
}

if (!is_enrolled($this->context, $participant, 'mod/assign:submit', $this->show_only_active_users())) {
return null;
}

$result = $this->get_submission_info_for_participants(array($participant->id => $participant));
return $result[$participant->id];
}

/**
* Load a count of valid teams for this assignment.
*
Expand Down Expand Up @@ -3779,6 +3822,11 @@ protected function view_grader() {
$o .= $this->get_renderer()->header();

$userid = optional_param('userid', 0, PARAM_INT);
$blindid = optional_param('blindid', 0, PARAM_INT);

if (!$userid && $blindid) {
$userid = $this->get_user_id_for_uniqueid($blindid);
}

$currentgroup = groups_get_activity_group($this->get_course_module(), true);
$framegrader = new grading_app($userid, $currentgroup, $this);
Expand Down
Loading

0 comments on commit 1b2f9dc

Please sign in to comment.