Merge branch 'MDL-39173-master' of git://github.com/damyon/moodle

This commit is contained in:
Dan Poltawski
2013-04-22 11:41:41 +01:00
3 changed files with 65 additions and 13 deletions
+1
View File
@@ -533,6 +533,7 @@ class comment {
$c->time = userdate($c->timecreated, $c->strftimeformat);
$c->content = format_text($c->content, $c->format, $formatoptions);
$c->avatar = $OUTPUT->user_picture($u, array('size'=>18));
$c->userid = $u->id;
$candelete = $this->can_delete($c->id);
if (($USER->id == $u->id) || !empty($candelete)) {
+64
View File
@@ -106,6 +106,70 @@ function assignsubmission_comments_comment_permissions(stdClass $options) {
return array('post' => true, 'view' => true);
}
/**
* Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
*
* @param array $comments
* @param stdClass $options
* @return array
* @throws comment_exception
*/
function assignsubmission_comments_comment_display($comments, $options) {
global $CFG, $DB, $USER;
if ($options->commentarea != 'submission_comments' &&
$options->commentarea != 'submission_comments_upgrade') {
throw new comment_exception('invalidcommentarea');
}
if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
throw new comment_exception('invalidcommentitemid');
}
$context = $options->context;
$cm = $options->cm;
$course = $options->courseid;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assignment = new assign($context, $cm, $course);
if ($assignment->get_instance()->id != $submission->assignment) {
throw new comment_exception('invalidcontext');
}
if ($assignment->is_blind_marking() && !empty($comments)) {
// Blind marking is being used, may need to map unique anonymous ids to the comments.
$usermappings = array();
$hiddenuserstr = trim(get_string('hiddenuser', 'assign'));
$guestuser = guest_user();
foreach ($comments as $comment) {
// Anonymize the comments.
if (empty($usermappings[$comment->userid])) {
// The blind-marking information for this commenter has not been generated; do so now.
$anonid = $assignment->get_uniqueid_for_user($comment->userid);
$commenter = new stdClass();
$commenter->firstname = $hiddenuserstr;
$commenter->lastname = $anonid;
$commenter->picture = 0;
$commenter->id = $guestuser->id;
$commenter->email = $guestuser->email;
$commenter->imagealt = $guestuser->imagealt;
// Temporarily store blind-marking information for use in later comments if necessary.
$usermappings[$comment->userid]->fullname = fullname($commenter);
$usermappings[$comment->userid]->avatar = $assignment->get_renderer()->user_picture($commenter,
array('size'=>18, 'link' => false));
}
// Set blind-marking information for this comment.
$comment->fullname = $usermappings[$comment->userid]->fullname;
$comment->avatar = $usermappings[$comment->userid]->avatar;
$comment->profileurl = null;
}
}
return $comments;
}
/**
* Callback to force the userid for all comments to be the userid of the submission and NOT the global $USER->id. This
* is required by the upgrade code. Note the comment area is used to identify upgrades.
@@ -168,17 +168,4 @@ class assign_submission_comments extends assign_submission_plugin {
public function allow_submissions() {
return false;
}
/**
* If blind marking is enabled then disable this plugin (it shows names)
*
* @return bool
*/
public function is_enabled() {
if ($this->assignment->has_instance() && $this->assignment->is_blind_marking()) {
return false;
}
return parent::is_enabled();
}
}