summaryrefslogtreecommitdiff
path: root/sqlbox/reportall.php
blob: abb799c77a862069ec5f521b67ceb5a0e7e2acfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');

$id  = required_param('id', PARAM_INT);   //moduleid

if ($id) {
    $cm     = get_coursemodule_from_id('sqlbox', $id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $sqlbox = $DB->get_record('sqlbox', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
    print_error('invalidcourse');
}

require_login($course, true, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/sqlbox:readqueries', $context);

add_to_log($course->id, 'sqlbox', 'report', "reportall.php?id={$cm->id}", $sqlbox->name, $cm->id);

$PAGE->set_url('/mod/sqlbox/reportall.php', array('id' => $cm->id));
$PAGE->set_title("Results for all SQLBoxes");
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);

echo $OUTPUT->header();

// TODO: Order Results using the frontend ordering. sth like this would get the ordering right for a given course_id:
/*
select mdl_sqlbox.name
from (
  select to_number(unnest(string_to_array(sequence,',')),'99999') as id
  from (select sequence from mdl_course_sections
  where course=:course_id order by section) as tmp
) sid, mdl_course_modules, mdl_sqlbox, mdl_modules
where sid.id = mdl_course_modules.id and mdl_course_modules.instance = mdl_sqlbox.id and mdl_modules.name='sqlbox' and mdl_modules.id=mdl_course_modules.module;
 */

$boxes = $DB->get_records_sql("SELECT * FROM {sqlbox} ORDER BY id");
$b = array();
foreach ($boxes as $box)
    $b[] = $box->name;

$table = new html_table;
$table->head = array_merge(array("Nutzer", "Fortschritt"), $b);
$table->align = array_merge(array("left", "left"), array_fill(0, count($b), 'center'));

$users = $DB->get_records_sql("select u.* from {enrol} e, {user_enrolments} ue, {user} u
	where e.courseid=:courseid and
	      ue.enrolid = e.id and
	      ue.userid = u.id and
	      u.deleted = 0",
	array('courseid'=>$course->id));

foreach ($users as $user) {
    if (isguestuser($user))
        continue;

    $name = $user->firstname.' '.$user->lastname;

    $solutions = $DB->get_records_sql("SELECT s.id, sol.correct
        FROM {sqlbox} s LEFT JOIN (
            SELECT sqlboxid,correct FROM {sqlbox_solutions} WHERE userid=:id) as sol
            ON s.id = sol.sqlboxid ORDER BY s.id",
            array('id'=>$user->id));
    $s = array();
    $progress = 0;
    foreach ($solutions as $solution) {
        $s[] = ($solution->correct == '1') ? '☑' : ($solution->correct == '0' ? '☒' : '☐');
        if ($solution->correct == '1')
            $progress++;
    }
    $progress /= count($s);

    $table->data[] = array_merge(array($name, round($progress * 100) . "%"), $s);
}

echo '<div style="overflow-x: scroll">';
echo html_writer::table($table);
echo '</div>';

echo $OUTPUT->footer();

?>