--- loncom/interface/lonnavmaps.pm 2002/12/02 14:22:50 1.121 +++ loncom/interface/lonnavmaps.pm 2021/08/04 19:59:10 1.554 @@ -1,8 +1,7 @@ - # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.121 2002/12/02 14:22:50 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.554 2021/08/04 19:59:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,658 +25,545 @@ # # http://www.lon-capa.org/ # -# (Page Handler -# -# (TeX Content Handler -# -# 05/29/00,05/30 Gerd Kortemeyer) -# 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23, -# 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer) -# -# 3/1/1,6/1,17/1,29/1,30/1,2/8,9/21,9/24,9/25 Gerd Kortemeyer -# YEAR=2002 -# 1/1 Gerd Kortemeyer -# Oct-Nov Jeremy Bowers +### -package Apache::lonnavmaps; +=pod -use strict; -use Apache::Constants qw(:common :http); -use Apache::loncommon(); -use POSIX qw (floor strftime); +=head1 NAME -sub handler { - my $r = shift; - real_handler($r); -} +Apache::lonnavmaps - Subroutines to handle and render the navigation -sub real_handler { - my $r = shift; +=head1 SYNOPSIS - &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); +Handles navigational maps. - # Handle header-only request - if ($r->header_only) { - if ($ENV{'browser.mathml'}) { - $r->content_type('text/xml'); - } else { - $r->content_type('text/html'); - } - $r->send_http_header; - return OK; - } +The main handler generates the navigational listing for the course, +the other objects export this information in a usable fashion for +other modules. + + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + + +=head1 OVERVIEW + +X When a user enters a course, LON-CAPA examines the +course structure and caches it in what is often referred to as the +"big hash" X. You can see it if you are logged into +LON-CAPA, in a course, by going to /adm/test. The content of +the hash will be under the heading "Big Hash". + +Access to /adm/test is controlled by a domain configuration, +which a Domain Coordinator will set for a server's default domain +via: Main Menu > Set domain configuration > Display (Access to +server status pages checked), and entering a username:domain +or IP address in the "Show user environment" row. Users with +an unexpired domain coordinator role in the server's domain +automatically receive access to /adm/test. + +Big Hash contains, among other things, how resources are related +to each other (next/previous), what resources are maps, which +resources are being chosen to not show to the student (for random +selection), and a lot of other things that can take a lot of time +to compute due to the amount of data that needs to be collected and +processed. + +Apache::lonnavmaps provides an object model for manipulating this +information in a higher-level fashion than directly manipulating +the hash. It also provides access to several auxiliary functions +that aren't necessarily stored in the Big Hash, but are a per- +resource sort of value, like whether there is any feedback on +a given resource. + +Apache::lonnavmaps also abstracts away branching, and someday, +conditions, for the times where you don't really care about those +things. + +Apache::lonnavmaps also provides fairly powerful routines for +rendering navmaps, and last but not least, provides the navmaps +view for when the user clicks the NAV button. + +B: Apache::lonnavmaps by default will show information +for the "currently logged in user". However, if information +about resources is needed for a different user, e.g., a bubblesheet +exam which uses randomorder, or randompick needs to be printed or +graded for named user(s) or specific CODEs, then the username, +domain, or CODE can be passed as arguments when creating a new +navmap object. + +Note if you want things like "due dates for another student", +you would use the EXT function instead of lonnavmaps. +That said, the lonnavmaps module can still help, because many +things, such as the course structure, are usually constant +between users, and Apache::lonnavmaps can help by providing +symbs for the EXT call. + +The rest of this file will cover the provided rendering routines, +which can often be used without fiddling with the navmap object at +all, then documents the Apache::lonnavmaps::navmap object, which +is the key to accessing the Big Hash information, covers the use +of the Iterator (which provides the logic for traversing the +somewhat-complicated Big Hash data structure), documents the +Apache::lonnavmaps::Resource objects that are returned singularly +by: getBySymb(), getById(), getByMapPc(), and getResourceByUrl() +(can also be as an array), or in an array by retrieveResources(). + +=head1 Subroutine: render + +The navmap renderer package provides a sophisticated rendering of the +standard navigation maps interface into HTML. The provided nav map +handler is actually just a glorified call to this. + +Because of the large number of parameters this function accepts, +instead of passing it arguments as is normal, pass it in an anonymous +hash with the desired options. + +The package provides a function called 'render', called as +Apache::lonnavmaps::render({}). + +=head2 Overview of Columns + +The renderer will build an HTML table for the navmap and return +it. The table consists of several columns, and a row for each +resource (or possibly each part). You tell the renderer how many +columns to create and what to place in each column, optionally using +one or more of the prepared columns, and the renderer will assemble +the table. + +Any additional generally useful column types should be placed in the +renderer code here, so anybody can use it anywhere else. Any code +specific to the current application (such as the addition of +elements in a column) should be placed in the code of the thing using +the renderer. + +At the core of the renderer is the array reference COLS (see Example +section below for how to pass this correctly). The COLS array will +consist of entries of one of two types of things: Either an integer +representing one of the pre-packaged column types, or a sub reference +that takes a resource reference, a part number, and a reference to the +argument hash passed to the renderer, and returns a string that will +be inserted into the HTML representation as it. - # Send header, don't cache this page - if ($ENV{'browser.mathml'}) { - $r->content_type('text/xml'); - } else { - $r->content_type('text/html'); - } - &Apache::loncommon::no_cache($r); - $r->send_http_header; +All other parameters are ways of either changing how the columns +are printing, or which rows are shown. - # Create the nav map - my $navmap = Apache::lonnavmaps::navmap->new( - $ENV{"request.course.fn"}.".db", - $ENV{"request.course.fn"}."_parms.db", 1, 1); - - - if (!defined($navmap)) { - my $requrl = $r->uri; - $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized"; - return HTTP_NOT_ACCEPTABLE; - } - - $r->print("\n"); - $r->print("Navigate Course Contents"); - - # Header - $r->print(&Apache::loncommon::bodytag('Navigate Course Contents','', - '')); - $r->print(''); - - $r->print(''); - my $date=localtime; - $r->print(''); - - # Print discussions and feedback header - if ($navmap->{LAST_CHECK}) { - $r->print(''); - } else { - $r->print(''); - } - $r->print('
Key:    '. - ' New discussion since '. - strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})). - '  '. - ' New message (click to open)

'. - '

  '. - ' Discussions'. - '   New message (click to open)'. - '
'); +The pre-packaged column names are refered to by constants in the +Apache::lonnavmaps namespace. The following currently exist: - my $condition = 0; - if ($ENV{'form.condition'}) { - $condition = 1; - } +=over 4 - # Determine where the "here" marker is and where the screen jumps to. - my $SYMB = 1; my $URL = 2; my $NOTHING = 3; # symbolic constants - my $hereType; # the type of marker, $SYMB, $URL, or $NOTHING - my $here; # the actual URL or SYMB for the here marker - my $jumpType; # The type of the thing we have a jump for, $SYMB or $URL - my $jump; # the SYMB/URL of the resource we need to jump to +=item * B: - if ( $ENV{'form.alreadyHere'} ) { # we came from a user's manipulation of the nav page - # If this is a click on a folder or something, we want to preserve the "here" - # from the querystring, and get the new "jump" marker - $hereType = $ENV{'form.hereType'}; - $here = $ENV{'form.here'}; - $jumpType = $ENV{'form.jumpType'} || $NOTHING; - $jump = $ENV{'form.jump'}; - } else { # the user is visiting the nav map from the remote - # We're coming from the remote. We have either a url, a symb, or nothing, - # and we need to figure out what. - # Preference: Symb - - if ($ENV{'form.symb'}) { - $hereType = $jumpType = $SYMB; - $here = $jump = $ENV{'form.symb'}; - } elsif ($ENV{'form.postdata'}) { - # couldn't find a symb, is there a URL? - my $currenturl = $ENV{'form.postdata'}; - $currenturl=~s/^http\:\/\///; - $currenturl=~s/^[^\/]+//; +The general info about the resource: Link, icon for the type, etc. The +first column in the standard nav map display. This column provides the +indentation effect seen in the B