Bolt stuff

svn path=/trunk/boinc/; revision=16325
This commit is contained in:
David Anderson 2008-10-27 21:30:55 +00:00
parent be4cd9bb79
commit 79c7b981b0
5 changed files with 40 additions and 16 deletions

View File

@ -30,6 +30,7 @@ abstract class BoltUnit {
public $title;
// Optional; used when showing course history outline.
public $is_item;
public $attrs; // course-defined
abstract function walk(&$iter, $incr, &$frac_done);
// multi-purpose function for traversing a course.
@ -47,7 +48,7 @@ abstract class BoltUnit {
class BoltItem extends BoltUnit {
public $filename;
public $query_string;
function __construct($filename, $title) {
function __construct($filename, $title, $attrs) {
$p = strpos($filename, '?');
if ($p === false) {
$this->filename = $filename;
@ -59,6 +60,7 @@ class BoltItem extends BoltUnit {
$this->name = $filename;
$this->title = $title;
$this->is_item = true;
$this->attrs = $attrs;
}
function begin() {
return array(new BoltFrame($this));
@ -108,12 +110,13 @@ class BoltExercise extends BoltItem {
//
class BoltSet extends BoltUnit {
public $units;
function __construct($name, $units, $ntoshow) {
function __construct($name, $units, $ntoshow, $attrs) {
$this->name = $name;
$this->is_item = false;
$this->units = $units;
$this->ntoshow = $ntoshow;
$this->ordered = false;
$this->attrs = $attrs;
}
// restart this unit - set its state record to an initial state
@ -252,6 +255,10 @@ function filename($n) {
return array('filename', $n);
}
function attrs($n) {
return array('attrs', $n);
}
function callback($n) {
return array('callback', $n);
}
@ -259,12 +266,15 @@ function callback($n) {
function lesson() {
$filename = "";
$title = "";
$attrs = null;
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
switch ($arg[0]) {
case 'title': $title = $arg[1]; break;
case 'filename': $filename = $arg[1]; break;
case 'attrs': $attrs = $arg[1]; break;
default: echo "Unrecognized lesson parameter: ", $arg[0], "\n"; break;
}
} else {
@ -277,12 +287,14 @@ function lesson() {
if (!$filename) {
error_page("Missing filename in lesson");
}
return new BoltLesson($filename, $title);
return new BoltLesson($filename, $title, $attrs);
}
function exercise() {
$filename = "";
$title = "";
$attrs = null;
$args = func_get_args();
$callback = null;
foreach ($args as $arg) {
@ -290,6 +302,7 @@ function exercise() {
switch ($arg[0]) {
case 'title': $title = $arg[1]; break;
case 'filename': $filename = $arg[1]; break;
case 'attrs': $attrs = $arg[1]; break;
case 'callback': $callback = $arg[1]; break;
default: echo "Unrecognized exercise parameter: ", $arg[0], "\n"; break;
}
@ -301,7 +314,7 @@ function exercise() {
if (!$filename) {
error_page("Missing filename in lesson");
}
return new BoltExercise($filename, $title, $callback);
return new BoltExercise($filename, $title, $attrs, $callback);
}
require_once('../inc/bolt_seq.inc');

View File

@ -18,8 +18,8 @@
class BoltRandom extends BoltSet {
public $units;
function __construct($name, $units, $number) {
parent::__construct($name, $units, $number);
function __construct($name, $units, $number, $attrs) {
parent::__construct($name, $units, $number, $attrs);
}
function order(&$iter) {
@ -49,12 +49,14 @@ function random() {
$units = array();
$name = "";
$number = 0;
$attrs = null;
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;
case 'attrs': $attrs = $arg[1]; break;
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
}
} else if (is_object($arg)) {
@ -67,7 +69,7 @@ function random() {
}
}
if ($number == 0) $number = count($units);
return new BoltRandom($name, $units, $number);
return new BoltRandom($name, $units, $number, $attrs);
}
?>

View File

@ -24,9 +24,9 @@ function select_cmp($a, $b) {
class BoltSelect extends BoltSet {
public $valuator;
function __construct($name, $units, $valuator) {
function __construct($name, $units, $valuator, $attrs) {
$this->valuator = $valuator;
parent::__construct($name, $units, 1);
parent::__construct($name, $units, 1, $attrs);
}
function order() {
@ -60,12 +60,14 @@ function select() {
$args = func_get_args();
$units = array();
$name = "";
$attrs = null;
foreach ($args as $arg) {
if (is_array($arg)) {
switch ($arg[0]) {
case 'name': $name = $arg[1]; break;
case 'title': $title = $arg[1]; break;
case 'valuator': $valuator = $arg[1]; break;
case 'attrs': $attrs = $arg[1]; break;
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
}
} else if (is_object($arg)) {
@ -80,7 +82,7 @@ function select() {
if (!$valuator) {
error_page("missing valuator");
}
return new BoltSelect($name, $units, $valuator);
return new BoltSelect($name, $units, $valuator, $attrs);
}
?>

View File

@ -17,8 +17,8 @@
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
class BoltSequence extends BoltSet {
function __construct($name, $units) {
parent::__construct($name, $units, count($units));
function __construct($name, $units, $attrs) {
parent::__construct($name, $units, count($units), $attrs);
}
function order() {
@ -39,11 +39,13 @@ function sequence() {
$args = func_get_args();
$units = array();
$name = "";
$attrs = null;
foreach ($args as $arg) {
if (is_array($arg)) {
switch ($arg[0]) {
case 'name': $name = $arg[1]; break;
case 'title': $title = $arg[1]; break;
case 'attrs': $attrs = $arg[1]; break;
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
}
} else if (is_object($arg)) {
@ -55,7 +57,7 @@ function sequence() {
}
}
}
return new BoltSequence($name, $units);
return new BoltSequence($name, $units, $attrs);
}
?>

View File

@ -20,10 +20,12 @@ class BoltExerciseSet extends BoltRandom {
public $repeats;
public $refresh;
public $callback;
function __construct(
$name, $units, $number, $repeats, $refresh, $callback
$name, $units, $number, $repeats, $refresh, $attrs, $callback
) {
parent::__construct($name, $units, $number);
parent::__construct($name, $units, $number, $attrs);
$this->repeats = $repeats;
$this->refresh = $refresh;
$this->callback = $callback;
@ -168,12 +170,14 @@ function exercise_set() {
$callback = null;
$name = "";
$number = 0;
$attrs = null;
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;
case 'attrs': $attrs = $arg[1]; break;
case 'callback': $callback = $arg[1]; break;
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
}
@ -191,9 +195,10 @@ function exercise_set() {
echo "Unexpected arg to exercise_set(): "; print_r($arg);
}
}
if ($number == 0) $number = count($units);
return new BoltExerciseSet(
$name, $units, $number, $repeats, $refresh, $callback
$name, $units, $number, $repeats, $refresh, $attrs, $callback
);
}