Permalink
Browse files

Changes to use new database stuff

  • Loading branch information...
moodler
moodler committed Dec 23, 2002
1 parent 1d881d9 commit e323955db8336f5619fb2539c62ed48281ef90a2
Showing with 237 additions and 173 deletions.
  1. +4 −1 mod/survey/details.php
  2. +4 −4 mod/survey/download.php
  3. +119 −99 mod/survey/graph.php
  4. +68 −34 mod/survey/lib.php
  5. +1 −1 mod/survey/mod.html
  6. +30 −28 mod/survey/report.php
  7. +9 −4 mod/survey/save.php
  8. +2 −2 mod/survey/view.php
View
@@ -35,7 +35,10 @@
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><? print_string("introtext", "survey") ?>:</B></P><BR>
- <? helpbutton("text", get_string("helptext")) ?>
+ <font SIZE="1">
+ <? helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br \>
+ <? helpbutton("text", get_string("helptext"), "moodle", true, true) ?><br \>
+ </font>
</TD>
<TD>
<TEXTAREA NAME="intro" ROWS=20 COLS=50 WRAP="virtual"><?
View
@@ -30,7 +30,7 @@
// Get all the questions and their proper order
- $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
+ $questions = get_records_list("survey_questions", "id", $survey->questions);
$order = explode(",", $survey->questions);
foreach ($order as $key => $qid) { // Do we have virtual scales?
@@ -63,7 +63,7 @@
}
}
- $fullquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($fullorderlist)");
+ $fullquestions = get_records_list("survey_questions", "id", $fullorderlist);
// Question type of multi-questions overrides the type of single questions
foreach ($order as $key => $qid) {
@@ -136,7 +136,7 @@
if (! $u = get_record("user", "id", $user)) {
error("Error finding student # $user");
}
- if ($n = get_record_sql("SELECT * FROM survey_analysis WHERE survey='$survey->id' AND user='$user'")) {
+ if ($n = get_record("survey_analysis", "survey", $survey->id, "user", $user)) {
$notes = $n->notes;
} else {
$notes = "No notes made";
@@ -190,7 +190,7 @@
// Print all the lines of data.
foreach ($results as $user => $rest) {
- if (! $u = get_record_sql("SELECT firstname,lastname,email,idnumber FROM user WHERE id = '$user'")) {
+ if (! $u = get_record("user", "id", $user)) {
error("Error finding student # $user");
}
echo $survey->id."\t";
View
@@ -51,16 +51,15 @@
$buckets2[$key] = 0;
}
- $aa = $db->Execute("SELECT * FROM survey_answers WHERE survey = $cm->instance AND question = $qid");
-
- while (!$aa->EOF) {
- if ($a1 = $aa->fields["answer1"]) {
- $buckets1[$a1 - 1]++;
- }
- if ($a2 = $aa->fields["answer2"]) {
- $buckets2[$a2 - 1]++;
+ if ($aaa = get_records_select("survey_answers", "survey = '$cm->instance' AND question = '$qid'")) {
+ foreach ($aaa as $aa) {
+ if ($a1 = $aa->answer1) {
+ $buckets1[$a1 - 1]++;
+ }
+ if ($a2 = $aa->answer2) {
+ $buckets2[$a2 - 1]++;
+ }
}
- $aa->MoveNext();
}
@@ -111,7 +110,7 @@
$options = explode(",",$question->options);
$questionorder = explode( ",", $question->multi);
- $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
+ $qqq = get_records_list("survey_questions", "id", $question->multi);
foreach ($questionorder as $i => $val) {
$names[$i] = get_string($qqq["$val"]->shorttext, "survey");
@@ -122,17 +121,19 @@
$indexof[$val] = $i;
}
- $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
+ $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
- foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->answer1) {
- $buckets1[$index] += $a->answer1;
- $count1[$index]++;
- }
- if ($a->answer2) {
- $buckets2[$index] += $a->answer2;
- $count2[$index]++;
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ $index = $indexof[$a->question];
+ if ($a->answer1) {
+ $buckets1[$index] += $a->answer1;
+ $count1[$index]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$index] += $a->answer2;
+ $count2[$index]++;
+ }
}
}
@@ -145,15 +146,17 @@
}
}
- foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$index]);
- $stdev1[$index] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$index]);
- $stdev2[$index] += ($difference * $difference);
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ $index = $indexof[$a->question];
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$index]);
+ $stdev1[$index] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$index]);
+ $stdev2[$index] += ($difference * $difference);
+ }
}
}
@@ -223,20 +226,24 @@
case "overall.png":
- $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
+ $qqq = get_records_list("survey_questions", "id", $survey->questions);
foreach ($qqq as $key => $qq) {
- $qqq[$key]->text = get_string($qq->text, "survey");
- $qqq[$key]->options = get_string($qq->options, "survey");
- if ($qq->type < 0) {
- $virtualscales = true;
+ if ($qq->multi) {
+ $qqq[$key]->text = get_string($qq->text, "survey");
+ $qqq[$key]->options = get_string($qq->options, "survey");
+ if ($qq->type < 0) {
+ $virtualscales = true;
+ }
}
}
foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
- if ($virtualscales && $qq->type < 0) {
- $question[] = $qq;
- } else if (!$virtualscales && $qq->type > 0) {
- $question[] = $qq;
+ if ($qq->multi) {
+ if ($virtualscales && $qq->type < 0) {
+ $question[] = $qq;
+ } else if (!$virtualscales && $qq->type > 0) {
+ $question[] = $qq;
+ }
}
}
$numquestions = count($question);
@@ -253,16 +260,18 @@
$count1[$i] = 0;
$count2[$i] = 0;
$subquestions = $question[$i]->multi; // otherwise next line doesn't work
- $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
+ $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($subquestions)))");
- foreach ($aaa as $a) {
- if ($a->answer1) {
- $buckets1[$i] += $a->answer1;
- $count1[$i]++;
- }
- if ($a->answer2) {
- $buckets2[$i] += $a->answer2;
- $count2[$i]++;
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ if ($a->answer1) {
+ $buckets1[$i] += $a->answer1;
+ $count1[$i]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$i] += $a->answer2;
+ $count2[$i]++;
+ }
}
}
@@ -274,14 +283,16 @@
}
// Calculate the standard devaiations
- foreach ($aaa as $a) {
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$i]);
- $stdev1[$i] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$i]);
- $stdev2[$i] += ($difference * $difference);
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$i]);
+ $stdev1[$i] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$i]);
+ $stdev2[$i] += ($difference * $difference);
+ }
}
}
@@ -350,20 +361,24 @@
case "student.png":
- $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
+ $qqq = get_records_list("survey_questions", "id", $survey->questions);
foreach ($qqq as $key => $qq) {
- $qqq[$key]->text = get_string($qq->text, "survey");
- $qqq[$key]->options = get_string($qq->options, "survey");
- if ($qq->type < 0) {
- $virtualscales = true;
+ if ($qq->multi) {
+ $qqq[$key]->text = get_string($qq->text, "survey");
+ $qqq[$key]->options = get_string($qq->options, "survey");
+ if ($qq->type < 0) {
+ $virtualscales = true;
+ }
}
}
foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
- if ($virtualscales && $qq->type < 0) {
- $question[] = $qq;
- } else if (!$virtualscales && $qq->type > 0) {
- $question[] = $qq;
+ if ($qq->multi) {
+ if ($virtualscales && $qq->type < 0) {
+ $question[] = $qq;
+ } else if (!$virtualscales && $qq->type > 0) {
+ $question[] = $qq;
+ }
}
}
$numquestions= count($question);
@@ -381,28 +396,31 @@
$studbuckets2[$i] = 0.0;
$studcount1[$i] = 0;
$studcount2[$i] = 0;
- $subquestions = $question[$i]->multi; // otherwise next line doesn't work
- $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
- foreach ($aaa as $a) {
- if ($a->user == $sid) {
+ $subquestions = $question[$i]->multi; // otherwise next line doesn't work
+ $aaa = get_records_select("survey_answers","((survey = $cm->instance) AND (question in ($subquestions)))");
+
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ if ($a->user == $sid) {
+ if ($a->answer1) {
+ $studbuckets1[$i] += $a->answer1;
+ $studcount1[$i]++;
+ }
+ if ($a->answer2) {
+ $studbuckets2[$i] += $a->answer2;
+ $studcount2[$i]++;
+ }
+ }
if ($a->answer1) {
- $studbuckets1[$i] += $a->answer1;
- $studcount1[$i]++;
+ $buckets1[$i] += $a->answer1;
+ $count1[$i]++;
}
if ($a->answer2) {
- $studbuckets2[$i] += $a->answer2;
- $studcount2[$i]++;
+ $buckets2[$i] += $a->answer2;
+ $count2[$i]++;
}
}
- if ($a->answer1) {
- $buckets1[$i] += $a->answer1;
- $count1[$i]++;
- }
- if ($a->answer2) {
- $buckets2[$i] += $a->answer2;
- $count2[$i]++;
- }
}
if ($count1[$i]) {
@@ -510,7 +528,7 @@
$options = explode(",",$question->options);
$questionorder = explode( ",", $question->multi);
- $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
+ $qqq = get_records_list("survey_questions", "id", $question->multi);
foreach ($questionorder as $i => $val) {
$names[$i] = get_string($qqq[$val]->shorttext, "survey");
@@ -525,27 +543,29 @@
$studcount2[$i] = 0;
}
- $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
+ $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
- foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->user == $sid) {
- if ($a->answer1) {
- $studbuckets1[$index] += $a->answer1;
- $studcount1[$index]++;
- }
- if ($a->answer2) {
- $studbuckets2[$index] += $a->answer2;
- $studcount2[$index]++;
+ if ($aaa) {
+ foreach ($aaa as $a) {
+ $index = $indexof[$a->question];
+ if ($a->user == $sid) {
+ if ($a->answer1) {
+ $studbuckets1[$index] += $a->answer1;
+ $studcount1[$index]++;
+ }
+ if ($a->answer2) {
+ $studbuckets2[$index] += $a->answer2;
+ $studcount2[$index]++;
+ }
}
+ if ($a->answer1) {
+ $buckets1[$index] += $a->answer1;
+ $count1[$index]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$index] += $a->answer2;
+ $count2[$index]++;
}
- if ($a->answer1) {
- $buckets1[$index] += $a->answer1;
- $count1[$index]++;
- }
- if ($a->answer2) {
- $buckets2[$index] += $a->answer2;
- $count2[$index]++;
}
}
Oops, something went wrong.

0 comments on commit e323955

Please sign in to comment.