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

raeburn raeburn at source.lon-capa.org
Fri Dec 7 11:48:20 EST 2012


raeburn		Fri Dec  7 16:48:20 2012 EDT

  Modified files:              
    /loncom/interface	loncommon.pm londocs.pm 
  Log:
  - Code used to generate "folderpath" (encapsulates hierarchy of folders and/or
    composite pages) containing a resource moved from londocs.pm to 
    &symb_to_docspath() routine in loncommon.pm to facilitate re-use. 
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1100 loncom/interface/loncommon.pm:1.1101
--- loncom/interface/loncommon.pm:1.1100	Tue Dec  4 18:50:33 2012
+++ loncom/interface/loncommon.pm	Fri Dec  7 16:48:19 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1100 2012/12/04 18:50:33 raeburn Exp $
+# $Id: loncommon.pm,v 1.1101 2012/12/07 16:48:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -14106,6 +14106,74 @@
     return $title;
 }
 
+sub symb_to_docspath {
+    my ($symb) = @_;
+    return unless ($symb);
+    my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
+    if ($resurl=~/\.(sequence|page)$/) {
+        $mapurl=$resurl;
+    } elsif ($resurl eq 'adm/navmaps') {
+        $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
+    }
+    my $mapresobj;
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    if (ref($navmap)) {
+        $mapresobj = $navmap->getResourceByUrl($mapurl);
+    }
+    $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
+    my $type=$2;
+    my $path;
+    if (ref($mapresobj)) {
+        my $pcslist = $mapresobj->map_hierarchy();
+        if ($pcslist ne '') {
+            foreach my $pc (split(/,/,$pcslist)) {
+                next if ($pc <= 1);
+                my $res = $navmap->getByMapPc($pc);
+                if (ref($res)) {
+                    my $thisurl = $res->src();
+                    $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
+                    my $thistitle = $res->title();
+                    $path .= '&'.
+                             &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
+                             &Apache::lonhtmlcommon::entity_encode($thistitle).
+                             ':'.$res->randompick().
+                             ':'.$res->randomout().
+                             ':'.$res->encrypted().
+                             ':'.$res->randomorder().
+                             ':'.$res->is_page();
+                }
+            }
+        }
+        $path =~ s/^\&//;
+        my $maptitle = $mapresobj->title();
+        if ($mapurl eq 'default') {
+            $maptitle = 'Main Course Documents';
+        }
+        $path .= (($path ne '')? '&' : '').
+                 &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+                 &Apache::lonhtmlcommon::entity_encode($maptitle).
+                 ':'.$mapresobj->randompick().
+                 ':'.$mapresobj->randomout().
+                 ':'.$mapresobj->encrypted().
+                 ':'.$mapresobj->randomorder().
+                 ':'.$mapresobj->is_page();
+    } else {
+        my $maptitle = &Apache::lonnet::gettitle($mapurl);
+        my $ispage = (($type eq 'page')? 1 : '');
+        if ($mapurl eq 'default') {
+            $maptitle = 'Main Course Documents';
+        }
+        $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+                &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
+    }
+    unless ($mapurl eq 'default') {
+        $path = 'default&'.
+                &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
+                ':::::&'.$path;
+    }
+    return $path;
+}
+
 sub captcha_display {
     my ($context,$lonhost) = @_;
     my ($output,$error);
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.521 loncom/interface/londocs.pm:1.522
--- loncom/interface/londocs.pm:1.521	Wed Dec  5 13:50:32 2012
+++ loncom/interface/londocs.pm	Fri Dec  7 16:48:19 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.521 2012/12/05 13:50:32 bisitz Exp $
+# $Id: londocs.pm,v 1.522 2012/12/07 16:48:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3214,69 +3214,8 @@
    if ($env{'form.command'} eq 'direct') {
        my ($mapurl,$id,$resurl);
        if ($env{'form.symb'} ne '') {
-           ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
-           if ($resurl=~/\.(sequence|page)$/) {
-               $mapurl=$resurl;
-           } elsif ($resurl eq 'adm/navmaps') {
-               $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
-           }
-           my $mapresobj;
-           my $navmap = Apache::lonnavmaps::navmap->new();
-           if (ref($navmap)) {
-               $mapresobj = $navmap->getResourceByUrl($mapurl);
-           }
-           $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
-           my $type=$2;
-           my $path;
-           if (ref($mapresobj)) {
-               my $pcslist = $mapresobj->map_hierarchy();
-               if ($pcslist ne '') {
-                   foreach my $pc (split(/,/,$pcslist)) {
-                       next if ($pc <= 1);
-                       my $res = $navmap->getByMapPc($pc);
-                       if (ref($res)) {
-                           my $thisurl = $res->src();
-                           $thisurl=~s{^.*/([^/]+)\.\w+$}{$1}; 
-                           my $thistitle = $res->title();
-                           $path .= '&'.
-                                    &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
-                                    &Apache::lonhtmlcommon::entity_encode($thistitle).
-                                    ':'.$res->randompick().
-                                    ':'.$res->randomout().
-                                    ':'.$res->encrypted().
-                                    ':'.$res->randomorder().
-                                    ':'.$res->is_page();
-                       }
-                   }
-               }
-               $path =~ s/^\&//;
-               my $maptitle = $mapresobj->title();
-               if ($mapurl eq 'default') {
-                   $maptitle = 'Main Course Documents';
-               }
-               $path .= (($path ne '')? '&' : '').
-                    &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
-                    &Apache::lonhtmlcommon::entity_encode($maptitle).
-                    ':'.$mapresobj->randompick().
-                    ':'.$mapresobj->randomout().
-                    ':'.$mapresobj->encrypted().
-                    ':'.$mapresobj->randomorder().
-                    ':'.$mapresobj->is_page(); 
-           } else {
-               my $maptitle = &Apache::lonnet::gettitle($mapurl);
-               my $ispage = (($type eq 'page')? 1 : '');
-               if ($mapurl eq 'default') {
-                   $maptitle = 'Main Course Documents';
-               }
-               $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
-                       &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
-           }
-           unless ($mapurl eq 'default') {
-               $path = 'default&'.
-                       &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
-                       ':::::&'.$path;
-           }
-           $env{'form.folderpath'}=$path;
+           $env{'form.folderpath'}=
+               &Apache::loncommon::symb_to_docspath($env{'form.symb'});
        } elsif ($env{'form.supppath'} ne '') {
            $env{'form.folderpath'}=$env{'form.supppath'};
        }




More information about the LON-CAPA-cvs mailing list