[LON-CAPA-cvs] cvs: loncom /interface lonblockingmenu.pm loncommon.pm

raeburn raeburn at source.lon-capa.org
Mon Apr 9 20:28:05 EDT 2012


raeburn		Tue Apr 10 00:28:05 2012 EDT

  Modified files:              
    /loncom/interface	lonblockingmenu.pm loncommon.pm 
  Log:
  - Utility to prepare for display of folder hierarchy for a folder or resource
    in a course.    
    - move lonblockingmenu::path_to_trigger() to loncommon::get_folder_hierarchy()
      to facilitate re-use.
  
  
Index: loncom/interface/lonblockingmenu.pm
diff -u loncom/interface/lonblockingmenu.pm:1.7 loncom/interface/lonblockingmenu.pm:1.8
--- loncom/interface/lonblockingmenu.pm:1.7	Thu Apr  5 21:36:28 2012
+++ loncom/interface/lonblockingmenu.pm	Tue Apr 10 00:28:04 2012
@@ -2,7 +2,7 @@
 # Routines for configuring blocking of access to collaborative functions, 
 # and specific resources during an exam
 #
-# $Id: lonblockingmenu.pm,v 1.7 2012/04/05 21:36:28 raeburn Exp $
+# $Id: lonblockingmenu.pm,v 1.8 2012/04/10 00:28:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -238,23 +238,6 @@
 
 Side Effects: prints web form elements (in a table) for current blocks. 
 
-=item &path_to_trigger()
-
-Provides hierarchy of names of folders/sub-folders containing the current
-item identified as an item with an interval timer set, to be used as a 
-trigger. 
-
-Inputs: 3 
-     - $navmap - navmaps object
-
-     - $map - url for map (either the trigger itself, or map containing
-                           the resource, which is the trigger). 
-
-     - $type - type of trigger: map or resource.
-
-Outputs: 1 @pathitems - array of folder/subfolder names.  
-
-
 =item &convlim()
 
 Convert a time interval used for a timed quiz (in seconds) to
@@ -1129,46 +1112,6 @@
     return;
 }
 
-sub path_to_trigger {
-    my ($navmap,$map,$type) = @_;
-    my @pathitems;
-    if (ref($navmap)) {
-        my $mapres = $navmap->getResourceByUrl($map);
-        if (ref($mapres)) {
-            my $pcslist = $mapres->map_hierarchy();
-            if ($pcslist ne '') {
-                my @pcs = split(/,/,$pcslist);
-                foreach my $pc (@pcs) {    
-                    if ($pc == 1) {
-                        push(@pathitems,&mt('Main Course Documents'));
-                    } else {
-                        my $res = $navmap->getByMapPc($pc);
-                        if (ref($res)) {
-                            my $title = $res->compTitle();
-                            $title =~ s/\W+/_/g;
-                            if ($title ne '') {
-                                push(@pathitems,$title);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        if ($type eq 'resource') {
-            if ($mapres->{ID} eq '0.0') {
-                push(@pathitems,&mt('Main Course Documents'));
-            } else {
-                my $maptitle = $mapres->compTitle();
-                $maptitle =~ s/\W+/_/g;
-                if ($maptitle ne '') {
-                    push(@pathitems,$maptitle);
-                }
-            }
-        }
-    }
-    return @pathitems;
-}
-
 sub convlim {
     my ($timelimit) = @_;
     my $output;
@@ -1460,10 +1403,12 @@
     return unless(ref($navmap));
     my @pathitems;
     if ($type eq 'map') {
-        @pathitems = &path_to_trigger($navmap,$item,$type);
+        @pathitems = 
+            &Apache::loncommon::get_folder_hierarchy($navmap,$item);
     } elsif ($type eq 'resource') {
         my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
-        @pathitems = &path_to_trigger($navmap,$map,$type);
+        @pathitems = 
+            &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
     }
     if (@pathitems) {
         return join(' » ', at pathitems);
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1067 loncom/interface/loncommon.pm:1.1068
--- loncom/interface/loncommon.pm:1.1067	Sun Apr  8 22:34:57 2012
+++ loncom/interface/loncommon.pm	Tue Apr 10 00:28:04 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1067 2012/04/08 22:34:57 raeburn Exp $
+# $Id: loncommon.pm,v 1.1068 2012/04/10 00:28:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -11016,6 +11016,65 @@
 
 =pod
 
+=item &get_folder_hierarchy()
+
+Provides hierarchy of names of folders/sub-folders containing the current
+item,
+
+Inputs: 3
+     - $navmap - navmaps object
+
+     - $map - url for map (either the trigger itself, or map containing
+                           the resource, which is the trigger).
+
+     - $showitem - 1 => show title for map itself; 0 => do not show.
+
+Outputs: 1 @pathitems - array of folder/subfolder names.
+
+=cut
+
+sub get_folder_hierarchy {
+    my ($navmap,$map,$showitem) = @_;
+    my @pathitems;
+    if (ref($navmap)) {
+        my $mapres = $navmap->getResourceByUrl($map);
+        if (ref($mapres)) {
+            my $pcslist = $mapres->map_hierarchy();
+            if ($pcslist ne '') {
+                my @pcs = split(/,/,$pcslist);
+                foreach my $pc (@pcs) {
+                    if ($pc == 1) {
+                        push(@pathitems,&mt('Main Course Documents'));
+                    } else {
+                        my $res = $navmap->getByMapPc($pc);
+                        if (ref($res)) {
+                            my $title = $res->compTitle();
+                            $title =~ s/\W+/_/g;
+                            if ($title ne '') {
+                                push(@pathitems,$title);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        if ($showitem) {
+            if ($mapres->{ID} eq '0.0') {
+                push(@pathitems,&mt('Main Course Documents'));
+            } else {
+                my $maptitle = $mapres->compTitle();
+                $maptitle =~ s/\W+/_/g;
+                if ($maptitle ne '') {
+                    push(@pathitems,$maptitle);
+                }
+            }
+        }
+    }
+    return @pathitems;
+}
+
+=pod
+
 =item * &get_turnedin_filepath()
 
 Determines path in a user's portfolio file for storage of files uploaded




More information about the LON-CAPA-cvs mailing list