summaryrefslogtreecommitdiff
path: root/sqlbox
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-25 09:25:23 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-25 09:25:23 +0100
commita278371368e6ece009bd62504788898ae256d868 (patch)
tree99363223bdb719833e3d5bd99d0578bf1d8c6410 /sqlbox
parenta3d5dfe86e51c71a7b29776f48e107ccd6fabb31 (diff)
downloadsqltutor-plugin-a278371368e6ece009bd62504788898ae256d868.tar.gz
sqltutor-plugin-a278371368e6ece009bd62504788898ae256d868.tar.bz2
sqltutor-plugin-a278371368e6ece009bd62504788898ae256d868.zip
Fix coding style
Diffstat (limited to 'sqlbox')
-rw-r--r--sqlbox/lib.php7
-rw-r--r--sqlbox/locallib.php28
-rw-r--r--sqlbox/report.php6
-rw-r--r--sqlbox/reportall.php12
-rw-r--r--sqlbox/sqlbox_form.php6
-rw-r--r--sqlbox/view.php60
6 files changed, 59 insertions, 60 deletions
diff --git a/sqlbox/lib.php b/sqlbox/lib.php
index f762532..ed441f5 100644
--- a/sqlbox/lib.php
+++ b/sqlbox/lib.php
@@ -48,8 +48,8 @@ defined('MOODLE_INTERNAL') || die();
*/
function sqlbox_supports($feature) {
switch($feature) {
- case FEATURE_MOD_INTRO: return true;
- default: return null;
+ case FEATURE_MOD_INTRO: return true;
+ default: return null;
}
}
@@ -394,7 +394,6 @@ function sqlbox_extend_settings_navigation(settings_navigation $settingsnav, nav
if (has_capability('mod/sqlbox:readqueries', $PAGE->cm->context)) {
$sqlboxnode->add(get_string('viewresults', 'sqlbox'),
- new moodle_url('/mod/sqlbox/report.php',
- array('id'=>$PAGE->cm->id)));
+ new moodle_url('/mod/sqlbox/report.php', array('id'=>$PAGE->cm->id)));
}
}
diff --git a/sqlbox/locallib.php b/sqlbox/locallib.php
index 359d5ae..2968e3f 100644
--- a/sqlbox/locallib.php
+++ b/sqlbox/locallib.php
@@ -40,22 +40,22 @@ defined('MOODLE_INTERNAL') || die();
//}
function db_table_from_query($db, $query) {
- global $PAGE;
+ global $PAGE;
- $table = new html_table;
- $result = @pg_query($db, $query);
- if (!$result)
- print_error('queryfailed', 'sqlbox', $PAGE->url, pg_last_error($db));
+ $table = new html_table;
+ $result = @pg_query($db, $query);
+ if (!$result)
+ print_error('queryfailed', 'sqlbox', $PAGE->url, pg_last_error($db));
- $table = new html_table;
- $n = pg_num_fields($result);
- for ($i = 0; $i < $n; $i++)
- $table->head[] = pg_field_name($result, $i);
- $table->align = array_fill(0, $n, 'left');
- while ($row = pg_fetch_row($result))
- $table->data[] = $row;
+ $table = new html_table;
+ $n = pg_num_fields($result);
+ for ($i = 0; $i < $n; $i++)
+ $table->head[] = pg_field_name($result, $i);
+ $table->align = array_fill(0, $n, 'left');
+ while ($row = pg_fetch_row($result))
+ $table->data[] = $row;
- return $table;
+ return $table;
}
function sqlbox_submit_response($query, $sqlbox, $correct, $userid) {
@@ -73,7 +73,7 @@ function sqlbox_submit_response($query, $sqlbox, $correct, $userid) {
}
$newsolution->query = $query;
$newsolution->correct = $correct;
-
+
if ($current)
$DB->update_record("sqlbox_solutions", $newsolution);
else
diff --git a/sqlbox/report.php b/sqlbox/report.php
index d9371d9..a3e0e08 100644
--- a/sqlbox/report.php
+++ b/sqlbox/report.php
@@ -6,9 +6,9 @@ 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);
+ $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');
}
diff --git a/sqlbox/reportall.php b/sqlbox/reportall.php
index b11a422..e6a6dab 100644
--- a/sqlbox/reportall.php
+++ b/sqlbox/reportall.php
@@ -6,9 +6,9 @@ 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);
+ $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');
}
@@ -44,14 +44,14 @@ 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
+ 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);
}
diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php
index 5360b59..19a5e93 100644
--- a/sqlbox/sqlbox_form.php
+++ b/sqlbox/sqlbox_form.php
@@ -8,9 +8,9 @@ class mod_sqlbox_form extends moodleform {
public function definition() {
$mform = &$this->_form;
- $mform->addElement('header', 'sqlbox_general', 'SQLBox');
- $mform->addElement('text', 'sqlbox_query', 'SQL Query', 'size="50"');
- $mform->addElement('submit', 'sqlbox_button', 'Submit');
+ $mform->addElement('header', 'sqlbox_general', 'SQLBox');
+ $mform->addElement('text', 'sqlbox_query', 'SQL Query', 'size="50"');
+ $mform->addElement('submit', 'sqlbox_button', 'Submit');
}
public function set_query($query) {
diff --git a/sqlbox/view.php b/sqlbox/view.php
index fababb7..47a9de4 100644
--- a/sqlbox/view.php
+++ b/sqlbox/view.php
@@ -36,13 +36,13 @@ $id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$n = optional_param('n', 0, PARAM_INT); // sqlbox instance ID - it should be named as the first character of the module
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);
+ $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);
} elseif ($n) {
- $sqlbox = $DB->get_record('sqlbox', array('id' => $n), '*', MUST_EXIST);
- $course = $DB->get_record('course', array('id' => $sqlbox->course), '*', MUST_EXIST);
- $cm = get_coursemodule_from_instance('sqlbox', $sqlbox->id, $course->id, false, MUST_EXIST);
+ $sqlbox = $DB->get_record('sqlbox', array('id' => $n), '*', MUST_EXIST);
+ $course = $DB->get_record('course', array('id' => $sqlbox->course), '*', MUST_EXIST);
+ $cm = get_coursemodule_from_instance('sqlbox', $sqlbox->id, $course->id, false, MUST_EXIST);
} else {
print_error('invalidcourse');
}
@@ -86,30 +86,30 @@ $data = $form->get_data();
$correct = true;
if (isset($data->sqlbox_query)) {
- echo $OUTPUT->heading('SQL Query: '.$data->sqlbox_query);
-
- $con = sprintf("host=%s dbname=%s user=%s password=%s",
- $CFG->sqlbox_hostname ? $CFG->sqlbox_hostname : "localhost",
- $CFG->sqlbox_database ? $CFG->sqlbox_database : "sqlbox",
- $CFG->sqlbox_user ? $CFG->sqlbox_user : "sqlbox",
- $CFG->sqlbox_password ? $CFG->sqlbox_password : "sqlbox_pw" );
-
- $db = pg_connect($con);
- if (!$db)
- print_error('dbconnectionfailed', 'sqlbox');
-
- $table = db_table_from_query($db, $data->sqlbox_query);
- if (strlen($sqlbox->query) > 0) {
- $table_orig = db_table_from_query($db, $sqlbox->query);
- if ($table->data != $table_orig->data ||
- $table->head != $table_orig->head)
- $correct = false;
- }
- pg_close($db);
-
- echo html_writer::table($table);
-
- sqlbox_submit_response($data->sqlbox_query, $sqlbox, $correct, $USER->id);
+ echo $OUTPUT->heading('SQL Query: '.$data->sqlbox_query);
+
+ $con = sprintf("host=%s dbname=%s user=%s password=%s",
+ $CFG->sqlbox_hostname ? $CFG->sqlbox_hostname : "localhost",
+ $CFG->sqlbox_database ? $CFG->sqlbox_database : "sqlbox",
+ $CFG->sqlbox_user ? $CFG->sqlbox_user : "sqlbox",
+ $CFG->sqlbox_password ? $CFG->sqlbox_password : "sqlbox_pw" );
+
+ $db = pg_connect($con);
+ if (!$db)
+ print_error('dbconnectionfailed', 'sqlbox');
+
+ $table = db_table_from_query($db, $data->sqlbox_query);
+ if (strlen($sqlbox->query) > 0) {
+ $table_orig = db_table_from_query($db, $sqlbox->query);
+ if ($table->data != $table_orig->data ||
+ $table->head != $table_orig->head)
+ $correct = false;
+ }
+ pg_close($db);
+
+ echo html_writer::table($table);
+
+ sqlbox_submit_response($data->sqlbox_query, $sqlbox, $correct, $USER->id);
} else if ($current) {
$correct = $current->correct;
}