Ejemplo n.º 1
0
 $bolt_ex->index = 0;
 $bolt_ex->score = 0;
 $bolt_query_string = $item->query_string;
 srand($view_id);
 ob_start();
 // buffer output to avoid showing exercise text
 require $item->filename;
 ob_end_clean();
 $bolt_ex->score /= $bolt_ex->index;
 if ($item->callback) {
     call_user_func($item->callback, $bolt_ex->score, $bolt_ex->query_string);
 }
 // make a record of the result
 $qs = BoltDb::escape_string($_SERVER['QUERY_STRING']);
 $now = time();
 $result_id = BoltResult::insert("(create_time, user_id, course_id, view_id, item_name, score, response)\n        values ({$now}, {$user->id}, {$course->id}, {$view->id}, '{$view->item_name}', {$bolt_ex->score}, '{$qs}')");
 $view->update("result_id={$result_id}");
 // If this is part of an exercise set, call its callback function
 //
 $repeat = null;
 $xset = $iter->xset;
 if ($xset) {
     $is_last = $xset->xset_record_score($iter, $bolt_ex->score, $view->id, $avg_score, $repeat);
     if ($repeat) {
         $repeat->avg_score = $avg_score;
     }
     if ($is_last) {
         // if the exercise set if finished, make or update DB records
         //
         if ($xset->callback) {
             call_user_func($xset->callback, $avg_score);
Ejemplo n.º 2
0
function map_gen_ex($uid, $unit, $sb)
{
    global $course, $now;
    if (frand() < $sb->attr) {
        $mode = BOLT_MODE_SHOW;
        $action = BOLT_ACTION_NONE;
        BoltView::insert("(user_id, course_id, item_name, mode, action, start_time) values ({$uid}, {$course->id}, '{$unit->name}', {$mode}, {$action}, {$now})");
        return false;
    } else {
        $t = $now + urand($sb->time_mean, $sb->time_dev);
        $mode = BOLT_MODE_SHOW;
        $action = BOLT_ACTION_NEXT;
        BoltView::insert("(user_id, course_id, item_name, mode, action, start_time, end_time) values ({$uid}, {$course->id}, '{$unit->name}', {$mode}, {$action}, {$now}, {$t})");
        $score = urand($sb->score_mean, $sb->score_dev);
        BoltResult::insert("(create_time, user_id, course_id, item_name, score) values ({$now}, {$uid}, {$course->id}, '{$unit->name}', {$score})");
        return map_gen_ans($uid, $unit, $sb);
    }
}