diff --git a/bolt_checkin_notes.txt b/bolt_checkin_notes.txt index c794b39939..6b1145206d 100644 --- a/bolt_checkin_notes.txt +++ b/bolt_checkin_notes.txt @@ -130,3 +130,12 @@ David Feb 8 2008 html/inc bolt_ex.inc + +David Feb 22 2008 + - added sketchy implementation of Maps + + html/ + inc/ + bolt.inc + ops/ + bolt_map.php diff --git a/html/inc/bolt.inc b/html/inc/bolt.inc index 1742c4f66e..388e839f1b 100644 --- a/html/inc/bolt.inc +++ b/html/inc/bolt.inc @@ -192,6 +192,22 @@ class BoltSet extends BoltUnit { } return false; } + + // return the name of our child, if we exist in the state + // + function get_child($state) { + if (array_key_exists($this->name, $state)) { + $state_rec = $state[$this->name]; + $child_name = $state_rec['child_name']; + foreach($this->units as $c) { + if ($c->name == $child_name) { + return $c; + } + } + } + return null; + } + } function name($n) { diff --git a/html/ops/bolt_map.php b/html/ops/bolt_map.php new file mode 100644 index 0000000000..2e986d8498 --- /dev/null +++ b/html/ops/bolt_map.php @@ -0,0 +1,73 @@ +name == $view->item_name) return true; + if ($unit->is_item) { + echo "ERROR: $unit->name $view->item_name
"; + print_r($state); + print_r($view); + return null; + } + $unit = $unit->get_child($state); + if (!$unit) return null; + } +} + +function add_to_totals($view, $state, &$unit) { + $u = $unit; + while (1) { + $u->nviews++; + if ($u->is_item) return; + $u = $u->get_child($state); + if (!$u) { + echo "ERROR - NOT ITEM"; + } + } +} + +function init_totals(&$unit) { + $unit->nviews = 0; + if ($unit->is_item) return; + foreach ($unit->units as $u) { + init_totals($u); + } +} + +function show_totals($unit, $level) { + for ($i=0; $i<$level; $i++) echo ' '; + echo "$unit->name: $unit->nviews\n"; + if ($unit->is_item) return; + foreach ($unit->units as $u) { + show_totals($u, $level+1); + } +} + +// scan the course's views and total up counts +// +function count_views($course, &$top_unit) { + $views = BoltView::enum("course_id=$course->id"); + init_totals($top_unit); + foreach ($views as $view) { + $state = json_decode($view->state, true); + if (consistent($view, $state, $top_unit)) { + add_to_totals($view, $state, $top_unit); + } + } +} + +$course_id = get_int('course_id'); +$course = BoltCourse::lookup_id($course_id); +if (!$course) error_page("no course"); +$top_unit = require_once("../user/$course->doc_file"); + +echo ""; +count_views($course, $top_unit); +show_totals($top_unit, 0); +echo ""; + +?>