2008-01-01 18:07:13 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-01 18:07:13 +00:00
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
class BoltExerciseSet extends BoltRandom {
|
2008-01-01 18:07:13 +00:00
|
|
|
public $repeats;
|
2008-08-14 21:05:02 +00:00
|
|
|
public $refresh;
|
2008-10-29 00:09:36 +00:00
|
|
|
public $weight;
|
2008-10-23 20:35:39 +00:00
|
|
|
public $callback;
|
2008-10-27 21:30:55 +00:00
|
|
|
|
2008-10-23 20:35:39 +00:00
|
|
|
function __construct(
|
2008-10-29 00:09:36 +00:00
|
|
|
$name, $units, $number, $repeats, $refresh, $attrs, $callback, $weight
|
2008-10-23 20:35:39 +00:00
|
|
|
) {
|
2008-10-27 21:30:55 +00:00
|
|
|
parent::__construct($name, $units, $number, $attrs);
|
|
|
|
|
2008-01-01 18:07:13 +00:00
|
|
|
$this->repeats = $repeats;
|
2008-08-14 21:05:02 +00:00
|
|
|
$this->refresh = $refresh;
|
2008-10-23 20:35:39 +00:00
|
|
|
$this->callback = $callback;
|
2008-10-29 00:09:36 +00:00
|
|
|
$this->weight = $weight;
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
// called when an exercise in this set has just been graded.
|
2008-01-03 17:37:38 +00:00
|
|
|
// - record the score in our state structure
|
2008-08-14 21:05:02 +00:00
|
|
|
// - return true if this was last exercise in the set
|
|
|
|
// - if so, also return a structure saying what navigation info to show:
|
2008-01-01 18:07:13 +00:00
|
|
|
// - review
|
|
|
|
// - repeat now
|
|
|
|
// - next
|
|
|
|
//
|
2008-10-23 20:35:39 +00:00
|
|
|
function xset_record_score(
|
|
|
|
&$iter, $score, $view_id, &$avg_score, &$repeat
|
|
|
|
) {
|
2008-01-30 19:29:51 +00:00
|
|
|
global $course;
|
|
|
|
global $user;
|
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
$nav_info = null;
|
2008-01-01 18:07:13 +00:00
|
|
|
$state_rec = $iter->state[$this->name];
|
2008-01-28 22:42:05 +00:00
|
|
|
$nshown = $state_rec['nshown'];
|
|
|
|
$state_rec['scores'][$nshown] = $score;
|
|
|
|
$iter->state[$this->name] = $state_rec;
|
2008-01-30 19:29:51 +00:00
|
|
|
$is_last = ($nshown+1 == $this->ntoshow);
|
|
|
|
if (!$is_last) {
|
2008-01-31 23:43:37 +00:00
|
|
|
return false;
|
2008-01-30 19:29:51 +00:00
|
|
|
}
|
2008-01-28 22:42:05 +00:00
|
|
|
|
|
|
|
// this exercise set is now "completed".
|
|
|
|
// - create exercise_set_result record
|
|
|
|
// - optionally create or update bolt_refresh record
|
|
|
|
//
|
|
|
|
$total_score = 0;
|
2008-01-30 19:29:51 +00:00
|
|
|
for ($i=0; $i<$nshown+1; $i++) {
|
|
|
|
$total_score += $state_rec['scores'][$i];
|
|
|
|
}
|
|
|
|
$avg_score = $total_score/($nshown+1);
|
|
|
|
|
|
|
|
$repeat = null;
|
2008-02-07 23:21:31 +00:00
|
|
|
$least = 2;
|
2008-01-30 19:29:51 +00:00
|
|
|
foreach ($this->repeats as $r) {
|
|
|
|
if ($avg_score < $r->score && $r->score<$least) {
|
|
|
|
$repeat = $r;
|
|
|
|
$least = $r->score;
|
|
|
|
}
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
2008-01-31 23:43:37 +00:00
|
|
|
return true;
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function walk(&$iter, $incr, &$frac_done) {
|
|
|
|
$iter->xset = $this;
|
2008-01-30 19:29:51 +00:00
|
|
|
// see if we're doing a review
|
|
|
|
//
|
|
|
|
if (array_key_exists($this->name, $iter->state)) {
|
|
|
|
$state_rec = $iter->state[$this->name];
|
|
|
|
$child_name = $state_rec['child_name'];
|
|
|
|
foreach ($this->repeats as $r) {
|
|
|
|
if ($r->unit && ($r->unit->name == $child_name)) {
|
|
|
|
// we're doing a review
|
|
|
|
//
|
|
|
|
$child = $r->unit;
|
|
|
|
if ($incr) {
|
|
|
|
if ($child->is_item) {
|
|
|
|
$my_inc = true;
|
|
|
|
} else {
|
|
|
|
$my_inc = $child->walk($iter, $incr, $frac_done);
|
|
|
|
}
|
|
|
|
if ($my_inc) {
|
|
|
|
// we're done with review. do exercises again
|
|
|
|
//
|
|
|
|
$state_rec['child_name'] = null;
|
|
|
|
$state_rec['nshown'] = 0;
|
|
|
|
$iter->state[$this->name] = $state_rec;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($child->is_item) {
|
|
|
|
$iter->item = $child;
|
|
|
|
} else {
|
|
|
|
$child->walk($iter, false, $f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
return parent::walk($iter, $incr, $frac_done);
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
2008-01-30 19:29:51 +00:00
|
|
|
|
|
|
|
function start_review(&$iter, $unit_name) {
|
|
|
|
foreach ($this->repeats as $r) {
|
|
|
|
if ($r->unit->name == $unit_name) {
|
|
|
|
$state_rec = $iter->state[$this->name];
|
|
|
|
$state_rec['child_name'] = $unit_name;
|
|
|
|
$iter->state[$this->name] = $state_rec;
|
2008-02-07 23:21:31 +00:00
|
|
|
if (!$r->unit->is_item) {
|
|
|
|
$r->unit->restart($iter);
|
|
|
|
}
|
2008-01-30 19:29:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoltRefresh{
|
|
|
|
public $intervals;
|
|
|
|
function __construct($i) {
|
|
|
|
$this->intervals = $i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoltRepeat {
|
|
|
|
public $score;
|
|
|
|
public $unit;
|
|
|
|
public $flags;
|
|
|
|
function __construct($s, $u, $f) {
|
|
|
|
$this->score = $s;
|
|
|
|
$this->unit = $u;
|
|
|
|
$this->flags = $f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define('REVIEW', 1);
|
|
|
|
define('REPEAT', 2);
|
|
|
|
define('NEXT', 4);
|
|
|
|
|
|
|
|
function repeat($s, $u, $f) {
|
|
|
|
return new BoltRepeat($s, $u, $f);
|
|
|
|
}
|
|
|
|
|
|
|
|
function refresh($a) {
|
|
|
|
return new BoltRefresh($a);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exercise_set() {
|
|
|
|
$args = func_get_args();
|
|
|
|
$units = array();
|
|
|
|
$repeats = array();
|
|
|
|
$refresh = null;
|
2008-10-23 20:35:39 +00:00
|
|
|
$callback = null;
|
2008-01-01 18:07:13 +00:00
|
|
|
$name = "";
|
2008-10-23 20:35:39 +00:00
|
|
|
$number = 0;
|
2008-10-27 21:30:55 +00:00
|
|
|
$attrs = null;
|
2008-10-29 00:09:36 +00:00
|
|
|
$weight = 1;
|
2008-01-01 18:07:13 +00:00
|
|
|
foreach ($args as $arg) {
|
|
|
|
if (is_array($arg)) {
|
|
|
|
switch ($arg[0]) {
|
|
|
|
case 'name': $name = $arg[1]; break;
|
|
|
|
case 'title': $title = $arg[1]; break;
|
|
|
|
case 'number': $number = $arg[1]; break;
|
2008-10-27 21:30:55 +00:00
|
|
|
case 'attrs': $attrs = $arg[1]; break;
|
2008-10-23 20:35:39 +00:00
|
|
|
case 'callback': $callback = $arg[1]; break;
|
2008-10-29 00:09:36 +00:00
|
|
|
case 'weight': $weight = $arg[1]; break;
|
2008-01-01 18:07:13 +00:00
|
|
|
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
|
|
|
|
}
|
|
|
|
} else if (is_object($arg)) {
|
|
|
|
if (get_class($arg) == "BoltExercise") {
|
|
|
|
$units[] = $arg;
|
|
|
|
} else if (get_class($arg) == "BoltRepeat") {
|
|
|
|
$repeats[] = $arg;
|
|
|
|
} else if (get_class($arg) == "BoltRefresh") {
|
|
|
|
$refresh= $arg;
|
|
|
|
} else {
|
2008-01-28 15:48:09 +00:00
|
|
|
echo "Can't include object of type ".get_class($arg)." within an exercise set.";
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
2008-10-23 20:35:39 +00:00
|
|
|
} else {
|
|
|
|
echo "Unexpected arg to exercise_set(): "; print_r($arg);
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-27 21:30:55 +00:00
|
|
|
|
2008-10-23 20:35:39 +00:00
|
|
|
if ($number == 0) $number = count($units);
|
|
|
|
return new BoltExerciseSet(
|
2008-10-29 00:09:36 +00:00
|
|
|
$name, $units, $number, $repeats, $refresh, $attrs, $callback, $weight
|
2008-10-23 20:35:39 +00:00
|
|
|
);
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|