mirror of https://github.com/BOINC/boinc.git
parent
820eb30596
commit
69042c3284
|
@ -20,24 +20,34 @@ create table bolt_enrollment (
|
||||||
create_time integer not null,
|
create_time integer not null,
|
||||||
user_id integer not null,
|
user_id integer not null,
|
||||||
course_id integer not null,
|
course_id integer not null,
|
||||||
last_view integer not null,
|
last_view_id integer not null,
|
||||||
fraction_done double not null,
|
mastery double not null
|
||||||
mastery double not null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- represents a view of an item;
|
||||||
|
-- created when we show the item,
|
||||||
|
-- and finalized when the user clicks on something to leave the page
|
||||||
|
--
|
||||||
create table bolt_view (
|
create table bolt_view (
|
||||||
id integer not null auto_increment,
|
id integer not null auto_increment,
|
||||||
user_id integer not null,
|
user_id integer not null,
|
||||||
course_id integer not null,
|
course_id integer not null,
|
||||||
item_name varchar(255) not null,
|
item_name varchar(255) not null,
|
||||||
|
-- name of the item
|
||||||
state text not null,
|
state text not null,
|
||||||
|
-- course state
|
||||||
mode integer not null,
|
mode integer not null,
|
||||||
|
-- distnguishes exercise show/answer
|
||||||
action integer not null,
|
action integer not null,
|
||||||
|
-- what the user clicked
|
||||||
start_time integer not null,
|
start_time integer not null,
|
||||||
end_time integer not null,
|
end_time integer not null,
|
||||||
previous_view integer not null,
|
prev_view_id integer not null,
|
||||||
|
fraction_done double not null,
|
||||||
result_id integer not null,
|
result_id integer not null,
|
||||||
|
-- if this was an exercise show, link to result record
|
||||||
refresh_id integer not null,
|
refresh_id integer not null,
|
||||||
|
-- if unit was flagged for review, link to review record
|
||||||
primary key (id)
|
primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ define('BOLT_MODE_ANSWER', 4);
|
||||||
|
|
||||||
define('BOLT_ACTION_NONE', 0);
|
define('BOLT_ACTION_NONE', 0);
|
||||||
define('BOLT_ACTION_NEXT', 1);
|
define('BOLT_ACTION_NEXT', 1);
|
||||||
define('BOLT_ACTION_SUBMIT', 2);
|
define('BOLT_ACTION_PREV', 2);
|
||||||
define('BOLT_ACTION_QUESTION', 3);
|
define('BOLT_ACTION_SUBMIT', 3);
|
||||||
|
define('BOLT_ACTION_QUESTION', 4);
|
||||||
|
|
||||||
class BoltDb extends DbConn {
|
class BoltDb extends DbConn {
|
||||||
static $instance;
|
static $instance;
|
||||||
|
@ -45,6 +46,10 @@ class BoltDb extends DbConn {
|
||||||
}
|
}
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
static function escape_string($string) {
|
||||||
|
$db = self::get();
|
||||||
|
return $db->base_escape_string($string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BoltUser {
|
class BoltUser {
|
||||||
|
|
|
@ -76,7 +76,8 @@ function bolt_inclusive_choice($choices) {
|
||||||
$score = 0;
|
$score = 0;
|
||||||
shuffle($choices);
|
shuffle($choices);
|
||||||
foreach ($choices as $choice) {
|
foreach ($choices as $choice) {
|
||||||
$response = $_GET["q_".$bolt_ex_index."_$i"];
|
$key = "q_".$bolt_ex_index."_$i";
|
||||||
|
$response = array_key_exists($key, $_GET);
|
||||||
$r = $choice[1];
|
$r = $choice[1];
|
||||||
$correct = ($r && $response) || (!$r && !$response);
|
$correct = ($r && $response) || (!$r && !$response);
|
||||||
if ($correct) $score += 1./$n;
|
if ($correct) $score += 1./$n;
|
||||||
|
@ -88,12 +89,14 @@ function bolt_inclusive_choice($choices) {
|
||||||
$n = count($choices);
|
$n = count($choices);
|
||||||
shuffle($choices);
|
shuffle($choices);
|
||||||
start_table();
|
start_table();
|
||||||
|
table_header("", "correct?", "your answer");
|
||||||
foreach ($choices as $choice) {
|
foreach ($choices as $choice) {
|
||||||
$c = $choice[0];
|
$c = $choice[0];
|
||||||
$response = $_GET["q_$bolt_ex_index_$i"];
|
$key = "q_".$bolt_ex_index."_$i";
|
||||||
|
$response = array_key_exists($key, $_GET);
|
||||||
$r = $choice[1];
|
$r = $choice[1];
|
||||||
$correct = ($r && $response) || (!$r && !$response);
|
$correct = ($r && $response) || (!$r && !$response);
|
||||||
row2($c, $x);
|
table_row($c, $r?"X":"<br>", $response?"X":"<br>");
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
end_table();
|
end_table();
|
||||||
|
|
|
@ -50,37 +50,18 @@ function default_mode($item) {
|
||||||
return $item->is_exercise()?BOLT_MODE_SHOW:BOLT_MODE_LESSON;
|
return $item->is_exercise()?BOLT_MODE_SHOW:BOLT_MODE_LESSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_view($user, $course, $item, $mode) {
|
function create_view($user, $course, $iter, $mode) {
|
||||||
$now = time();
|
$now = time();
|
||||||
return BoltView::insert("(user_id, course_id, item_name, start_time, mode) values ($user->id, $course->id, '$item->name', $now, $mode)");
|
$item = $iter->item;
|
||||||
}
|
|
||||||
|
|
||||||
function get_current_item($e, $course_doc) {
|
|
||||||
$frac_done = 0;
|
|
||||||
$iter = new BoltIter($course_doc);
|
|
||||||
$iter->decode_state($e->state);
|
|
||||||
$iter->at();
|
|
||||||
return $iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_next_item($e, $course_doc) {
|
|
||||||
$iter = new BoltIter($course_doc);
|
|
||||||
$iter->decode_state($e->state);
|
|
||||||
$iter->next();
|
|
||||||
$state = $iter->encode_state();
|
$state = $iter->encode_state();
|
||||||
$e->update("state='$state'");
|
return BoltView::insert("(user_id, course_id, item_name, start_time, mode, state, fraction_done) values ($user->id, $course->id, '$item->name', $now, $mode, '$state', $iter->frac_done)");
|
||||||
return $iter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_item(
|
function show_item($iter, $user, $course, $view_id, $mode) {
|
||||||
$item, $frac_done, $user, $course, $e, $view_id, $mode
|
|
||||||
) {
|
|
||||||
global $bolt_ex_mode;
|
global $bolt_ex_mode;
|
||||||
global $bolt_ex_index;
|
global $bolt_ex_index;
|
||||||
|
|
||||||
$now = time();
|
$item = $iter->item;
|
||||||
$e->update("last_view=$now, fraction_done=$frac_done");
|
|
||||||
|
|
||||||
if ($item->is_exercise()) {
|
if ($item->is_exercise()) {
|
||||||
$bolt_ex_mode = $mode;
|
$bolt_ex_mode = $mode;
|
||||||
$bolt_ex_index = 0;
|
$bolt_ex_index = 0;
|
||||||
|
@ -106,8 +87,9 @@ function show_item(
|
||||||
echo "<p><a href=bolt_sched.php?course_id=$course->id&action=next&view_id=$view_id>Next</a>";
|
echo "<p><a href=bolt_sched.php?course_id=$course->id&action=next&view_id=$view_id>Next</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<p>Fraction done: $frac_done
|
echo "<p>Fraction done: $iter->frac_done
|
||||||
<a href=bolt_course.php?course_id=$course->id>Course history</a>
|
<p><a href=bolt_course.php?course_id=$course->id>Course history</a>
|
||||||
|
<p><a href=bolt_sched.php?course_id=$course->id&action=prev&view_id=$view_id>Prev</a>
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,13 +99,10 @@ function start_course($user, $course, $course_doc) {
|
||||||
$iter->at();
|
$iter->at();
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
print_r($iter->state);
|
|
||||||
$state = $iter->encode_state();
|
|
||||||
BoltEnrollment::insert("(create_time, user_id, course_id, state) values ($now, $user->id, $course->id, '$state')");
|
|
||||||
$e = BoltEnrollment::lookup($user->id, $course->id);
|
|
||||||
$mode = default_mode($iter->item);
|
$mode = default_mode($iter->item);
|
||||||
$view_id = create_view($user, $course, $iter->item, $mode);
|
$view_id = create_view($user, $course, $iter, $mode);
|
||||||
show_item($iter->item, 0, $user, $course, $e, $view_id, $mode);
|
BoltEnrollment::insert("(create_time, user_id, course_id, last_view_id) values ($now, $user->id, $course->id, $view_id)");
|
||||||
|
show_item($iter, $user, $course, $view_id, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
$e = BoltEnrollment::lookup($user->id, $course_id);
|
$e = BoltEnrollment::lookup($user->id, $course_id);
|
||||||
|
@ -152,22 +131,33 @@ case 'start_confirm':
|
||||||
case 'update_info':
|
case 'update_info':
|
||||||
update_info();
|
update_info();
|
||||||
start_course($user, $course, $course_doc);
|
start_course($user, $course, $course_doc);
|
||||||
|
case 'prev':
|
||||||
|
$view = finalize_view($user, $view_id, BOLT_ACTION_NEXT);
|
||||||
|
break;
|
||||||
case 'next': // "next" button in lesson or exercise answer page
|
case 'next': // "next" button in lesson or exercise answer page
|
||||||
$view = finalize_view($user, $view_id, BOLT_ACTION_NEXT);
|
$view = finalize_view($user, $view_id, BOLT_ACTION_NEXT);
|
||||||
$iter = get_next_item($e, $course_doc);
|
|
||||||
|
$iter = new BoltIter($course_doc);
|
||||||
|
$iter->decode_state($view->state);
|
||||||
|
$iter->next();
|
||||||
|
|
||||||
if (!$iter->item) {
|
if (!$iter->item) {
|
||||||
page_head("Done with course");
|
page_head("Done with course");
|
||||||
echo "All done!";
|
echo "All done!";
|
||||||
page_tail();
|
page_tail();
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
$state = $iter->encode_state();
|
||||||
$mode = default_mode($iter->item);
|
$mode = default_mode($iter->item);
|
||||||
$view_id = create_view($user, $course, $iter->item, $mode);
|
$view_id = create_view($user, $course, $iter, $mode);
|
||||||
show_item($iter->item, $iter->frac_done, $user, $course, $e, $view_id, $mode);
|
show_item($iter, $user, $course, $view_id, $mode);
|
||||||
break;
|
break;
|
||||||
case 'answer': // submit answer in exercise
|
case 'answer': // submit answer in exercise
|
||||||
$view = finalize_view($user, $view_id, BOLT_ACTION_SUBMIT);
|
$view = finalize_view($user, $view_id, BOLT_ACTION_SUBMIT);
|
||||||
$iter = get_current_item($e, $course_doc);
|
$iter = new BoltIter($course_doc);
|
||||||
|
$iter->decode_state($view->state);
|
||||||
|
$iter->at();
|
||||||
|
|
||||||
$item = $iter->item;
|
$item = $iter->item;
|
||||||
if (!$item->is_exercise()) {
|
if (!$item->is_exercise()) {
|
||||||
error_page("expected an exercise");
|
error_page("expected an exercise");
|
||||||
|
@ -191,17 +181,16 @@ case 'answer': // submit answer in exercise
|
||||||
);
|
);
|
||||||
$view->update("result_id=$result_id");
|
$view->update("result_id=$result_id");
|
||||||
srand($view_id);
|
srand($view_id);
|
||||||
$view_id = create_view($user, $course, $item, BOLT_MODE_ANSWER);
|
$view_id = create_view($user, $course, $iter, BOLT_MODE_ANSWER);
|
||||||
show_item(
|
show_item($iter, $user, $course, $view_id, BOLT_MODE_ANSWER);
|
||||||
$iter->item, $iter->frac_done, $user, $course, $e,
|
|
||||||
$view_id, BOLT_MODE_ANSWER
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$iter = get_current_item($e, $course_doc);
|
$iter = new BoltIter($course_doc);
|
||||||
|
$iter->decode_state($view->state);
|
||||||
|
$iter->at();
|
||||||
$mode = default_mode($iter->item);
|
$mode = default_mode($iter->item);
|
||||||
$view_id = create_view($user, $course, $iter->item, $mode);
|
$view_id = create_view($user, $course, $iter, $mode);
|
||||||
show_item($iter->item, $iter->frac_done, $user, $course, $e, $view_id, $mode);
|
show_item($iter, $user, $course, $view_id, $mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue