Exemple #1
0
$PAGE->set_url($url);
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course);
$context = context_course::instance($course->id);
require_capability('gradereport/history:view', $context);
require_capability('moodle/grade:viewall', $context);
// Last selected report session tracking.
if (!isset($USER->grade_last_report)) {
    $USER->grade_last_report = array();
}
$USER->grade_last_report[$course->id] = 'history';
$select = "itemtype <> 'course' AND courseid = :courseid AND " . $DB->sql_isnotempty('grade_items', 'itemname', true, true);
$itemids = $DB->get_records_select_menu('grade_items', $select, array('courseid' => $course->id), 'itemname ASC', 'id, itemname');
$itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $itemids;
$output = $PAGE->get_renderer('gradereport_history');
$graders = \gradereport_history\helper::get_graders($course->id);
$params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => null);
$mform = new \gradereport_history\filter_form(null, $params);
$filters = array();
if ($data = $mform->get_data()) {
    $filters = (array) $data;
    if (!empty($filters['datetill'])) {
        $filters['datetill'] += DAYSECS - 1;
        // Set to end of the chosen day.
    }
} else {
    $filters = array('id' => $courseid, 'userids' => optional_param('userids', '', PARAM_SEQUENCE), 'itemid' => optional_param('itemid', 0, PARAM_INT), 'grader' => optional_param('grader', 0, PARAM_INT), 'datefrom' => optional_param('datefrom', 0, PARAM_INT), 'datetill' => optional_param('datetill', 0, PARAM_INT), 'revisedonly' => optional_param('revisedonly', 0, PARAM_INT));
}
$table = new \gradereport_history\output\tablelog('gradereport_history', $context, $url, $filters, $download, $page);
$names = array();
foreach ($table->get_selected_users() as $key => $user) {
Exemple #2
0
 /**
  * Test the get graders helper method.
  */
 public function test_graders()
 {
     $this->resetAfterTest();
     // Making the setup.
     $c1 = $this->getDataGenerator()->create_course();
     $c2 = $this->getDataGenerator()->create_course();
     $c1m1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1));
     $c2m1 = $this->getDataGenerator()->create_module('assign', array('course' => $c2));
     // Users.
     $u1 = $this->getDataGenerator()->create_user(array('firstname' => 'Eric', 'lastname' => 'Cartman'));
     $u2 = $this->getDataGenerator()->create_user(array('firstname' => 'Stan', 'lastname' => 'Marsh'));
     $u3 = $this->getDataGenerator()->create_user(array('firstname' => 'Kyle', 'lastname' => 'Broflovski'));
     $u4 = $this->getDataGenerator()->create_user(array('firstname' => 'Kenny', 'lastname' => 'McCormick'));
     // Creating grade history for some users.
     $gi = grade_item::fetch(array('iteminstance' => $c1m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign'));
     $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u1->id));
     $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u2->id));
     $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u3->id));
     $gi = grade_item::fetch(array('iteminstance' => $c2m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign'));
     $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u4->id));
     // Checking fetching some users.
     $graders = \gradereport_history\helper::get_graders($c1->id);
     $this->assertCount(4, $graders);
     // Including "all graders" .
     $this->assertArrayHasKey($u1->id, $graders);
     $this->assertArrayHasKey($u2->id, $graders);
     $this->assertArrayHasKey($u3->id, $graders);
     $graders = \gradereport_history\helper::get_graders($c2->id);
     $this->assertCount(2, $graders);
     // Including "all graders" .
     $this->assertArrayHasKey($u4->id, $graders);
 }