$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);
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_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); $this->assertTrue(isset($userparticipation->gradeobj)); $this->assertNotEmpty($userparticipation->gradeobj); $this->assertEquals(55, $userparticipation->gradeobj->grade); }