summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-24 23:03:27 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-24 23:54:07 +0100
commitdb4f945609caf1c8a62beed5d5eb3103184ebed7 (patch)
tree684c7079e4c98be686aa7ec9aabdecfc944a3cc0
parentc81bbb7f56dbbfab2497ce936036bf53d6a6c1a0 (diff)
downloadsqltutor-plugin-db4f945609caf1c8a62beed5d5eb3103184ebed7.tar.gz
sqltutor-plugin-db4f945609caf1c8a62beed5d5eb3103184ebed7.tar.bz2
sqltutor-plugin-db4f945609caf1c8a62beed5d5eb3103184ebed7.zip
Add reportall to display tests results for all users..
-rw-r--r--sqlbox/reportall.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/sqlbox/reportall.php b/sqlbox/reportall.php
new file mode 100644
index 0000000..3efca91
--- /dev/null
+++ b/sqlbox/reportall.php
@@ -0,0 +1,59 @@
+<?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 {
+ error('You must specify a course_module ID or an instance ID');
+}
+
+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();
+
+$boxes = $DB->get_records("sqlbox");
+$b = array();
+foreach ($boxes as $box)
+ $b[$box->id] = $box->name;
+
+$table = new html_table;
+$table->head = array_merge(array("Nutzer"), $b);
+$table->align = array_merge(array("left"), array_fill(0, count($b), 'center'));
+
+$users = $DB->get_records("user");
+foreach ($users as $user) {
+ $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",
+ array('id'=>$user->id));
+ $s = array();
+ foreach ($solutions as $solution)
+ $s[$solution->id] = ($solution->correct == 1) ? '☑' : '☒';
+
+ $table->data[] = array_merge(array($name), $s);
+}
+
+echo html_writer::table($table);
+
+echo $OUTPUT->footer();
+
+?>