public function test_participation_grades()
 {
     global $USER, $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     // Whole course.
     $course = $this->get_new_course();
     $student1 = $this->get_new_user('student', $course->id);
     $student2 = $this->get_new_user('student', $course->id);
     $oublog = $this->get_new_oublog($course->id, array('grade' => 100));
     $cm = get_coursemodule_from_id('oublog', $oublog->cmid);
     $context = context_module::instance($oublog->cmid);
     $participation = oublog_get_participation($oublog, $context, 0, $cm, $course);
     $this->assertArrayHasKey($student1->id, $participation);
     $this->assertTrue(isset($participation[$student1->id]->gradeobj));
     $this->assertNotEmpty($participation[$student1->id]->gradeobj);
     $this->assertEmpty($participation[$student1->id]->gradeobj->grade);
     oublog_update_manual_grades(array($student1->id => 55), $participation, $cm, $oublog, $course);
     $participation = oublog_get_participation($oublog, $context, 0, $cm, $course);
     $this->assertTrue(isset($participation[$student1->id]->gradeobj));
     $this->assertNotEmpty($participation[$student1->id]->gradeobj);
     $this->assertEquals(55, $participation[$student1->id]->gradeobj->grade);
     $userparticipation = oublog_get_user_participation($oublog, $context, $student1->id, 0, $cm, $course, null, null, true, true, null, null, true);
     $this->assertTrue(isset($userparticipation->gradeobj));
     $this->assertNotEmpty($userparticipation->gradeobj);
     $this->assertEquals(55, $userparticipation->gradeobj->grade);
 }
    $PAGE->set_cm($cm);
}
$context = context_module::instance($cm->id);
require_course_login($course, true, $cm);
require_sesskey();
// participation capability check
$canview = oublog_can_view_participation($course, $oublog, $cm, $groupid);
if ($canview != OUBLOG_USER_PARTICIPATION) {
    print_error('nopermissiontoshow');
}
// grading capability check
if (!oublog_can_grade($course, $oublog, $cm, $groupid)) {
    print_error('nopermissiontoshow');
}
$mode = '';
if (!empty($_POST['menu'])) {
    $gradeinfo = $_POST['menu'];
    $oldgrades = oublog_get_participation($oublog, $context, $groupid, $cm, $course);
} else {
    if ($userid && !empty($_POST['grade'])) {
        $gradeinfo[$userid] = $_POST['grade'];
        $user = oublog_get_user_participation($oublog, $context, $userid, $groupid, $cm, $course);
        $oldgrades = array($userid => $user);
    }
}
// update grades
if (!empty($gradeinfo)) {
    oublog_update_grades($gradeinfo, $oldgrades, $cm, $oublog, $course);
}
// redirect
redirect('participation.php?id=' . $id . '&group=' . $groupid);
$default = get_user_preferences('mod_oublog_postformfilter', OUBLOG_STATS_TIMEFILTER_ALL);
// Create time filter options form.
$customdata = array('type' => 'participation', 'cmid' => $cm->id, 'user' => $USER->id, 'group' => $groupid, 'download' => $download, 'page' => $page, 'startyear' => $course->startdate, 'params' => array('curgroup', $curgroup));
$timefilter = new oublog_participation_timefilter_form(null, $customdata);
// If data has been received from this form.
$start = $end = 0;
$info = 'The info needs to be provided';
if ($submitted = $timefilter->get_data()) {
    if ($submitted->start) {
        $start = strtotime('00:00:00', $submitted->start);
    }
    if ($submitted->end) {
        $end = strtotime('23:59:59', $submitted->end);
    }
}
$participation = oublog_get_participation($oublog, $context, $groupid, $cm, $course, $start, $end);
$PAGE->navbar->add(get_string('userparticipation', 'oublog'));
$PAGE->set_title(format_string($oublog->name));
$PAGE->set_heading(format_string($oublog->name));
// Log visit list event.
$params = array('context' => $context, 'objectid' => $oublog->id, 'other' => array('info' => 'user participation', 'logurl' => 'participation.php?id=' . $cm->id));
$event = \mod_oublog\event\participation_viewed::create($params);
$event->add_record_snapshot('course', $course);
$event->trigger();
$oublogoutput = $PAGE->get_renderer('mod_oublog');
if (empty($download)) {
    echo $OUTPUT->header();
    // Gets a message after grades updated.
    if (isset($SESSION->oubloggradesupdated)) {
        $message = $SESSION->oubloggradesupdated;
        unset($SESSION->oubloggradesupdated);