--- loncom/interface/loncommon.pm 2008/07/06 05:01:52 1.664 +++ loncom/interface/loncommon.pm 2008/07/07 15:10:23 1.665 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.664 2008/07/06 05:01:52 raeburn Exp $ +# $Id: loncommon.pm,v 1.665 2008/07/07 15:10:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -8340,6 +8340,9 @@ idx (reference to hash of counters used jsarray (reference to array of categories used to create Javascript arrays for Domain Coordinator interface for editing Course Categories). +subcats (reference to hash of arrays containing all subcategories within each + category, -recursive) + Returns: nothing Side effects: populates trails and allitems hash references. @@ -8347,7 +8350,7 @@ Side effects: populates trails and allit =cut sub extract_categories { - my ($categories,$cats,$trails,$allitems,$idx,$jsarray) = @_; + my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_; if (ref($categories) eq 'HASH') { &gather_categories($categories,$cats,$idx,$jsarray); if (ref($cats->[0]) eq 'ARRAY') { @@ -8368,7 +8371,14 @@ sub extract_categories { if (ref($cats->[1]{$name}) eq 'ARRAY') { for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) { my $category = $cats->[1]{$name}[$j]; - &recurse_categories($cats,2,$category,$trails,$allitems,\@parents); + if (ref($subcats) eq 'HASH') { + push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1'); + } + &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats); + } + } else { + if (ref($subcats) eq 'HASH') { + $subcats->{$item} = []; } } } @@ -8407,7 +8417,7 @@ Side effects: populates trails and allit =cut sub recurse_categories { - my ($cats,$depth,$category,$trails,$allitems,$parents) = @_; + my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_; my $shallower = $depth - 1; if (ref($cats->[$depth]{$category}) eq 'ARRAY') { for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) { @@ -8420,7 +8430,21 @@ sub recurse_categories { } my $deeper = $depth+1; push(@{$parents},$category); - &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents); + if (ref($subcats) eq 'HASH') { + my $subcat = &escape($name).':'.$category.':'.$depth; + for (my $j=@{$parents}; $j>=0; $j--) { + my $higher; + if ($j > 0) { + $higher = &escape($parents->[$j]).':'. + &escape($parents->[$j-1]).':'.$j; + } else { + $higher = &escape($parents->[$j]).'::'.$j; + } + push(@{$subcats->{$higher}},$subcat); + } + } + &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents, + $subcats); pop(@{$parents}); } } else {