/** * Test feedback with assignment restricted to future date. * * @throws \coding_exception */ public function test_feedback_restricted() { global $DB; $this->resetAfterTest(); $generator = $this->getDataGenerator(); $course = $generator->create_course(); $student = $generator->create_user(); // Enrol student. $studentrole = $DB->get_record('role', array('shortname' => 'student')); $generator->enrol_user($student->id, $course->id, $studentrole->id); // Create assign instance. $this->create_assignment($course->id, time() + DAYSECS * 2); $actual = local::upcoming_deadlines($student->id); $expected = 1; $this->assertCount($expected, $actual); // Create restricted assign instance. $opts = ['availability' => $this->get_date_condition_json(time() + WEEKSECS)]; $assign = $this->create_assignment($course->id, time() + DAYSECS * 2, $opts); // Mark restricted assign instasnce. $data = $assign->get_user_grade($student->id, true); $data->grade = '50.5'; $assign->update_grade($data); // Student should only see 1 feedback item as one is normal and one is restricted until next week. $this->setUser($student); $actual = activity::events_graded(); $expected = 1; $this->assertCount($expected, $actual); }
public static function graded() { global $USER, $PAGE; $output = $PAGE->get_renderer('theme_snap', 'core', RENDERER_TARGET_GENERAL); $grades = activity::events_graded(); $o = ''; foreach ($grades as $grade) { $modinfo = get_fast_modinfo($grade->courseid); $course = $modinfo->get_course(); $modtype = $grade->itemmodule; $cm = $modinfo->instances[$modtype][$grade->iteminstance]; $coursecontext = \context_course::instance($grade->courseid); $canviewhiddengrade = has_capability('moodle/grade:viewhidden', $coursecontext); $url = new \moodle_url('/grade/report/user/index.php', ['id' => $grade->courseid]); if (in_array($modtype, ['quiz', 'assign']) && (!empty($grade->rawgrade) || !empty($grade->feedback))) { // Only use the course module url if the activity was graded in the module, not in the gradebook, etc. $url = $cm->url; } $modimageurl = $output->pix_url('icon', $cm->modname); $modname = get_string('modulename', 'mod_' . $cm->modname); $modimage = \html_writer::img($modimageurl, $modname); $gradetitle = "<small>{$course->fullname} / </small> {$cm->name}"; $releasedon = isset($grade->timemodified) ? $grade->timemodified : $grade->timecreated; $meta = get_string('released', 'theme_snap', $output->friendly_datetime($releasedon)); $grade = new \grade_grade(array('itemid' => $grade->itemid, 'userid' => $USER->id)); if (!$grade->is_hidden() || $canviewhiddengrade) { $o .= $output->snap_media_object($url, $modimage, $gradetitle, $meta, ''); } } if (empty($o)) { return '<p>' . get_string('nograded', 'theme_snap') . '</p>'; } return $o; }
public function test_events_graded() { $this->setUser($this->editingteachers[0]); $this->create_instance(); $assign = $this->create_instance(array('duedate' => time(), 'submissiondrafts' => 1, 'assignsubmission_onlinetext_enabled' => 1)); // Add a submission. $this->setUser($this->students[0]); $submission = $assign->get_user_submission($this->students[0]->id, true); $data = new stdClass(); $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_HTML); $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); // And now submit it for marking. $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; $assign->testable_update_submission($submission, $this->students[0]->id, true, false); // Mark the submission. $this->setUser($this->teachers[0]); $data = new stdClass(); $data->grade = '50.0'; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); // TODO remove this next line when the above is fixed to stop triggering debug messages. $this->resetDebugging(); $this->setUser($this->students[0]); $actual = activity::events_graded(); $this->assertCount(1, $actual); $this->setUser($this->students[1]); $actual = activity::events_graded(); $this->assertCount(0, $actual); }