From c3491a40d97a0bd7acea2bc56e1563f97084c1f7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 19 Dec 2007 16:31:41 +0000 Subject: [PATCH] David Dec 19 2007 - May as well start keeping checkin notes for Bolt. At this point the fundamental structure of Bolt is more or less complete, I hope; many features are missing. Items for this particular checkin: - Make things work right when you resume a course at an exercise answer page. This creates a new View, whose prev_view_id link points to the exercise view, not the answer page view - When leave a page using "Up", terminate the view accordingly. - Rather than using $_GET, Form vars are now passed to exercise primitives in a global variable $bolt_ex_query_string, which they must parse. svn path=/trunk/boinc/; revision=14414 --- bolt_checkin_notes.txt | 24 ++++++++++++++++++++++++ db/bolt_schema.sql | 4 ++++ html/inc/bolt_db.inc | 1 + html/inc/bolt_ex.inc | 21 +++++++++++++++------ html/user/bolt_course.php | 1 + html/user/bolt_sched.php | 29 +++++++++++++++++++++++++---- 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 bolt_checkin_notes.txt diff --git a/bolt_checkin_notes.txt b/bolt_checkin_notes.txt new file mode 100644 index 0000000000..415a105bd4 --- /dev/null +++ b/bolt_checkin_notes.txt @@ -0,0 +1,24 @@ +David Dec 19 2007 + - May as well start keeping checkin notes for Bolt. + At this point the fundamental structure of Bolt is + more or less complete, I hope; many features are missing. + + Items for this particular checkin: + + - Make things work right when you resume a course at an + exercise answer page. + This creates a new View, whose prev_view_id link points + to the exercise view, not the answer page view + - When leave a page using "Up", terminate the view accordingly. + - Rather than using $_GET, Form vars are now passed to exercise primitives + in a global variable $bolt_ex_query_string, which they must parse. + + db/ + bolt_schema.sql + html/ + inc/ + bolt_db.inc + bolt_ex.inc + user/ + bolt_course.php + bolt_sched.php diff --git a/db/bolt_schema.sql b/db/bolt_schema.sql index f1da76375c..6f57166ec2 100644 --- a/db/bolt_schema.sql +++ b/db/bolt_schema.sql @@ -45,6 +45,8 @@ create table bolt_view ( start_time integer not null, end_time integer not null, prev_view_id integer not null, + -- for exercise answer views, + -- this always refers to the original exercise show fraction_done double not null, result_id integer not null, -- if this was an exercise show, link to result record @@ -58,8 +60,10 @@ create table bolt_view ( create table bolt_exercise_result ( id integer not null auto_increment, view_id integer not null, + -- the original display of exercise score double not null, response text not null, + -- the query string containing user's responses primary key(id) ); diff --git a/html/inc/bolt_db.inc b/html/inc/bolt_db.inc index e94aaabcb4..832d82eed9 100644 --- a/html/inc/bolt_db.inc +++ b/html/inc/bolt_db.inc @@ -14,6 +14,7 @@ define('BOLT_ACTION_NEXT', 1); define('BOLT_ACTION_PREV', 2); define('BOLT_ACTION_SUBMIT', 3); define('BOLT_ACTION_QUESTION', 4); +define('BOLT_ACTION_COURSE_HOME', 5); class BoltDb extends DbConn { static $instance; diff --git a/html/inc/bolt_ex.inc b/html/inc/bolt_ex.inc index 4e196e755d..4025ab1c4c 100644 --- a/html/inc/bolt_ex.inc +++ b/html/inc/bolt_ex.inc @@ -4,11 +4,15 @@ $bolt_ex_mode = 0; $bolt_ex_index = 0; $bolt_ex_state = 0; $bolt_ex_score = 0; +$bolt_ex_query_string = ""; function bolt_exclusive_choice($choices) { global $bolt_ex_mode; // input global $bolt_ex_index; // input global $bolt_ex_score; // incremental output if SCORE + global $bolt_ex_query_string; + + parse_str($bolt_ex_query_string); switch ($bolt_ex_mode) { case BOLT_MODE_SHOW: @@ -25,8 +29,8 @@ function bolt_exclusive_choice($choices) { $right_ans = $choices[0]; shuffle($choices); $key = "q_$bolt_ex_index"; - if (array_key_exists($key, $_GET)) { - $response = $_GET[$key]; + if (isset($$key)) { + $response = $$key; if ($choices[$response] == $right_ans) { $bolt_ex_score += 1; } @@ -36,8 +40,8 @@ function bolt_exclusive_choice($choices) { $right_ans = $choices[0]; shuffle($choices); $key = "q_$bolt_ex_index"; - if (array_key_exists($key, $_GET)) { - $response = $_GET[$key]; + if (isset($$key)) { + $response = $$key; } else { $response = -1; } @@ -60,6 +64,9 @@ function bolt_inclusive_choice($choices) { global $bolt_ex_mode; // input global $bolt_ex_index; // input global $bolt_ex_score; // incremental output if SCORE + global $bolt_ex_query_string; + + parse_str($bolt_ex_query_string); switch ($bolt_ex_mode) { case BOLT_MODE_SHOW: @@ -80,7 +87,7 @@ function bolt_inclusive_choice($choices) { shuffle($choices); foreach ($choices as $choice) { $key = "q_".$bolt_ex_index."_$i"; - $response = array_key_exists($key, $_GET); + $response = isset($$key); $r = $choice[1]; $correct = ($r && $response) || (!$r && !$response); if ($correct) $score += 1./$n; @@ -97,7 +104,7 @@ function bolt_inclusive_choice($choices) { foreach ($choices as $choice) { $c = $choice[0]; $key = "q_".$bolt_ex_index."_$i"; - $response = array_key_exists($key, $_GET); + $response = isset($$key); $r = $choice[1]; $correct = ($r && $response) || (!$r && !$response); table_row($c, $r?"yes":"no", $response?"yes":"no"); @@ -115,6 +122,8 @@ function bolt_image_rect($img, $rect) { global $bolt_ex_state; // output if SHOW, else input global $bolt_ex_score; // incremental output if SCORE + parse_str($bolt_ex_query_string); + switch ($bolt_ex_mode) { case BOLT_MODE_SHOW: echo " - +
$prevUpid&action=course_home&view_id=$view_id>Up $next
@@ -253,6 +253,7 @@ case 'answer': // submit answer in exercise if ($view->item_name != $item->name) { error_page("unexpected name"); } + $bolt_ex_query_string = $_SERVER['QUERY_STRING']; $bolt_ex_mode = BOLT_MODE_SCORE; $bolt_ex_index = 0; $bolt_ex_score = 0; @@ -283,8 +284,13 @@ case 'answer_page': } $result = BoltResult::lookup_id($view->result_id); srand($view_id); + $bolt_ex_query_string = $result->response; show_answer_page($iter, $result->score); break; +case 'course_home': + $view = finalize_view($user, $view_id, BOLT_ACTION_COURSE_HOME); + Header("Location: bolt.php"); + break; default: $view = $e?BoltView::lookup_id($e->last_view_id):null; if (!$view) { @@ -298,9 +304,24 @@ default: $iter = new BoltIter($course_doc); $iter->decode_state($view->state); $iter->at(); - $mode = default_mode($iter->item); - $view_id = create_view($user, $course, $iter, $mode, $view->id); - show_item($iter, $user, $course, $view_id, $view->id, $mode); + $mode = $view->mode; + if ($view->item_name == $iter->item->name && ($mode == BOLT_MODE_ANSWER)) { + // if we're returning to an answer page, + // we need to look up the user's responses and the score. + // + $view_orig = BoltView::lookup_id($view->prev_view_id); + $result = BoltResult::lookup_id($view_orig->result_id); + srand($view_orig->id); + echo "reshow: $result->response"; + $bolt_ex_query_string = $result->response; + $bolt_ex_score = $result->score; + $bolt_ex_index = 0; + $view_id = create_view($user, $course, $iter, $mode, $view_orig->id); + show_item($iter, $user, $course, $view_id, $view_orig->id, $mode); + } else { + $view_id = create_view($user, $course, $iter, $mode, $view->id); + show_item($iter, $user, $course, $view_id, $view->id, $mode); + } break; }