Skip to content

Commit

Permalink
Merge branch 'MDL-45151-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllaó committed Feb 19, 2019
2 parents 53bc11d + 5ac7838 commit 4f3f8fb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
3 changes: 3 additions & 0 deletions mod/assign/classes/event/base.php
Expand Up @@ -60,6 +60,9 @@ public function set_assign(\assign $assign) {
if ($assign->get_context()->id != $this->get_context()->id) {
throw new \coding_exception('Invalid assign isntance supplied!');
}
if ($assign->is_blind_marking()) {
$this->data['anonymous'] = 1;
}
$this->assign = $assign;
}

Expand Down
13 changes: 9 additions & 4 deletions mod/assign/locallib.php
Expand Up @@ -8987,10 +8987,15 @@ public function set_module_viewed() {

// Trigger the course module viewed event.
$assigninstance = $this->get_instance();
$event = \mod_assign\event\course_module_viewed::create(array(
'objectid' => $assigninstance->id,
'context' => $this->get_context()
));
$params = [
'objectid' => $assigninstance->id,
'context' => $this->get_context()
];
if ($this->is_blind_marking()) {
$params['anonymous'] = 1;
}

$event = \mod_assign\event\course_module_viewed::create($params);

$event->add_record_snapshot('assign', $assigninstance);
$event->trigger();
Expand Down
3 changes: 3 additions & 0 deletions mod/assign/submission/file/locallib.php
Expand Up @@ -252,6 +252,9 @@ public function save(stdClass $submission, stdClass $data) {
if (!empty($submission->userid) && ($submission->userid != $USER->id)) {
$params['relateduserid'] = $submission->userid;
}
if ($this->assignment->is_blind_marking()) {
$params['anonymous'] = 1;
}
$event = \assignsubmission_file\event\assessable_uploaded::create($params);
$event->set_legacy_files($files);
$event->trigger();
Expand Down
3 changes: 3 additions & 0 deletions mod/assign/submission/onlinetext/locallib.php
Expand Up @@ -251,6 +251,9 @@ public function save(stdClass $submission, stdClass $data) {
if (!empty($submission->userid) && ($submission->userid != $USER->id)) {
$params['relateduserid'] = $submission->userid;
}
if ($this->assignment->is_blind_marking()) {
$params['anonymous'] = 1;
}
$event = \assignsubmission_onlinetext\event\assessable_uploaded::create($params);
$event->trigger();

Expand Down
39 changes: 39 additions & 0 deletions mod/assign/tests/events_test.php
Expand Up @@ -1353,4 +1353,43 @@ public function test_course_module_viewed() {
$this->assertInstanceOf('\mod_assign\event\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
}

/**
* Test that all events generated with blindmarking enabled are anonymous
*/
public function test_anonymous_events() {
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student1 = $this->getDataGenerator()->create_and_enrol($course, 'student');
$student2 = $this->getDataGenerator()->create_and_enrol($course, 'student');

$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $course->id, 'blindmarking' => 1));

$cm = get_coursemodule_from_instance('assign', $instance->id, $course->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $course);

$this->setUser($teacher);
$sink = $this->redirectEvents();

$assign->lock_submission($student1->id);

$events = $sink->get_events();
$event = reset($events);

$this->assertTrue((bool)$event->anonymous);

$assign->reveal_identities();
$sink = $this->redirectEvents();
$assign->lock_submission($student2->id);

$events = $sink->get_events();
$event = reset($events);

$this->assertFalse((bool)$event->anonymous);
}

}

0 comments on commit 4f3f8fb

Please sign in to comment.