--- loncom/interface/lonnavmaps.pm 2003/02/06 22:58:12 1.139 +++ loncom/interface/lonnavmaps.pm 2003/02/21 20:05:00 1.145 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.139 2003/02/06 22:58:12 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.145 2003/02/21 20:05:00 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -56,21 +56,23 @@ sub NOTHING { return 3; } # Some data +my $resObj = "Apache::lonnavmaps::resource"; + # Keep these mappings in sync with lonquickgrades, which uses the colors # instead of the icons. my %statusIconMap = - ( Apache::lonnavmaps::resource->NETWORK_FAILURE => '', - Apache::lonnavmaps::resource->NOTHING_SET => '', - Apache::lonnavmaps::resource->CORRECT => 'navmap.correct.gif', - Apache::lonnavmaps::resource->EXCUSED => 'navmap.correct.gif', - Apache::lonnavmaps::resource->PAST_DUE_NO_ANSWER => 'navmap.wrong.gif', - Apache::lonnavmaps::resource->PAST_DUE_ANSWER_LATER => 'navmap.wrong.gif', - Apache::lonnavmaps::resource->ANSWER_OPEN => 'navmap.wrong.gif', - Apache::lonnavmaps::resource->OPEN_LATER => '', - Apache::lonnavmaps::resource->TRIES_LEFT => 'navmap.open.gif', - Apache::lonnavmaps::resource->INCORRECT => 'navmap.wrong.gif', - Apache::lonnavmaps::resource->OPEN => 'navmap.open.gif', - Apache::lonnavmaps::resource->ATTEMPTED => 'navmap.open.gif' ); + ( $resObj->NETWORK_FAILURE => '', + $resObj->NOTHING_SET => '', + $resObj->CORRECT => 'navmap.correct.gif', + $resObj->EXCUSED => 'navmap.correct.gif', + $resObj->PAST_DUE_NO_ANSWER => 'navmap.wrong.gif', + $resObj->PAST_DUE_ANSWER_LATER => 'navmap.wrong.gif', + $resObj->ANSWER_OPEN => 'navmap.wrong.gif', + $resObj->OPEN_LATER => '', + $resObj->TRIES_LEFT => 'navmap.open.gif', + $resObj->INCORRECT => 'navmap.wrong.gif', + $resObj->OPEN => 'navmap.open.gif', + $resObj->ATTEMPTED => 'navmap.open.gif' ); my %iconAltTags = ( 'navmap.correct.gif' => 'Correct', @@ -79,17 +81,17 @@ my %iconAltTags = # Defines a status->color mapping, null string means don't color my %colormap = - ( Apache::lonnavmaps::resource->NETWORK_FAILURE => '', - Apache::lonnavmaps::resource->CORRECT => '', - Apache::lonnavmaps::resource->EXCUSED => '#3333FF', - Apache::lonnavmaps::resource->PAST_DUE_ANSWER_LATER => '', - Apache::lonnavmaps::resource->PAST_DUE_NO_ANSWER => '', - Apache::lonnavmaps::resource->ANSWER_OPEN => '#006600', - Apache::lonnavmaps::resource->OPEN_LATER => '', - Apache::lonnavmaps::resource->TRIES_LEFT => '', - Apache::lonnavmaps::resource->INCORRECT => '', - Apache::lonnavmaps::resource->OPEN => '', - Apache::lonnavmaps::resource->NOTHING_SET => '' ); + ( $resObj->NETWORK_FAILURE => '', + $resObj->CORRECT => '', + $resObj->EXCUSED => '#3333FF', + $resObj->PAST_DUE_ANSWER_LATER => '', + $resObj->PAST_DUE_NO_ANSWER => '', + $resObj->ANSWER_OPEN => '#006600', + $resObj->OPEN_LATER => '', + $resObj->TRIES_LEFT => '', + $resObj->INCORRECT => '', + $resObj->OPEN => '', + $resObj->NOTHING_SET => '' ); # And a special case in the nav map; what to do when the assignment # is not yet done and due in less then 24 hours my $hurryUpColor = "#FF0000"; @@ -117,8 +119,6 @@ sub handler { sub real_handler { my $r = shift; - &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - # Handle header-only request if ($r->header_only) { if ($ENV{'browser.mathml'}) { @@ -164,83 +164,6 @@ sub real_handler { # Now that we've displayed some stuff to the user, init the navmap $navmap->init(); - $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)'. - '
'); - - my $condition = 0; - if ($ENV{'form.condition'}) { - $condition = 1; - } - - # Determine where the "here" marker is and where the screen jumps to. - 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 - - 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/^[^\/]+//; - - $hereType = $jumpType = URL; - $here = $jump = $currenturl; - } else { - # Nothing - $hereType = $jumpType = NOTHING(); - } - } - - - # alreadyHere allows us to only open the maps necessary to view - # the current location once, while at the same time remembering - # the current location. Without that check, the user would never - # be able to close those maps; the user would close it, and the - # currenturl scan would re-open it. - my $queryAdd = "&alreadyHere=1"; - - if ($condition) { - $r->print("Close All Folders"); - } else { - $r->print("Open All Folders"); - } $r->print('
 '); $r->rflush(); @@ -252,101 +175,11 @@ sub real_handler { return OK; } - my $res = "Apache::lonnavmaps::resource"; - - my %filterHash; - # Figure out what we're not displaying - foreach (split(/\,/, $ENV{"form.filter"})) { - if ($_) { - $filterHash{$_} = "1"; - } - } - - # Begin the HTML table - # four cols: resource + indent, chat+feedback, icon, text string - $r->print('' ."\n"); - - # This needs to be updated to use symbs from the remote, - # instead of uris. The changes to this and the main rendering - # loop should be obvious. - # Here's a simple example of the iterator. - # Preprocess the map: Look for current URL, open necessary maps - - my $mapIterator = $navmap->getIterator(undef, undef, undef, 1); - my $found = 0; - my $depth = 1; - my $currentJumpIndex = 0; # keeps track of when the current resource is found, - # so we can back up a few and put the anchor above the - # current resource - my $currentJumpDelta = 2; # change this to change how many resources are displayed - # before the current resource when using #current - $mapIterator->next(); # discard the first BEGIN_MAP - my $curRes = $mapIterator->next(); - my $counter = 0; - my $foundJump = ($jumpType == NOTHING()); # look for jump point if we have one - my $looped = 0; - - # We only need to do this if we need to open the maps to show the - # current position. This will change the counter so we can't count - # for the jump marker with this loop. - while ($depth > 0 && !$ENV{'form.alreadyHere'}) { - if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } - if ($curRes == $mapIterator->END_MAP()) { $depth--; } - - if (ref($curRes) && !$ENV{'form.alreadyHere'} && - ($hereType == SYMB() && $curRes->symb() eq $here) || - (ref($curRes) && $hereType == URL() && $curRes->src() eq $here)) { - my $mapStack = $mapIterator->getStack(); - - # Ensure the parent maps are open - for my $map (@{$mapStack}) { - if ($condition) { - undef $filterHash{$map->map_pc()}; - } else { - $filterHash{$map->map_pc()} = 1; - } - } - $ENV{'form.alreadyHere'} = 1; - } - $looped = 1; - - $curRes = $mapIterator->next(); - } - - $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, 0); - $depth = 1; - $mapIterator->next(); - $curRes = $mapIterator->next(); - - while ($depth > 0 && !$foundJump) { - if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } - if ($curRes == $mapIterator->END_MAP()) { $depth--; } - if (ref($curRes)) { $counter++; } - - if (ref($curRes) && - (($jumpType == SYMB() && $curRes->symb() eq $jump) || - ($jumpType == URL() && $curRes->src() eq $jump))) { - # If this is the correct resource, be sure to - # show it by making sure the containing maps - # are open. - - # This is why we have to use the main iterator instead of the - # potentially faster DFS: The count has to be the same, so - # the order has to be the same, which DFS won't give us. - $currentJumpIndex = $counter; - $foundJump = 1; - } - - $curRes = $mapIterator->next(); - } - # renderer call - $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, 0); - my $render = render({ 'cols' => [0,1,2,3], 'iterator' => $mapIterator, - 'url' => '/adm/navmaps', - 'queryString' => 'alreadyHere=1', - 'currentJumpIndex' => $currentJumpIndex}); - $r->print($render); + my $render = render({ 'cols' => [0,1,2,3], + 'url' => '/adm/navmaps', + 'printKey' => 1, + 'r' => $r}); $navmap->untieHashes(); @@ -630,6 +463,8 @@ The pre-packaged column names are refere =item * B: If true (default), the resource will show a part count if the full part list is not displayed. If false, the resource will never show a part count. +=item * B: If true, the resource's folder will not be clickable to open or close it. Default is false. + =back =item B: Whether there is discussion on the resource, email for the user, or (lumped in here) perl errors in the execution of the problem. This is the second column in the main nav map. @@ -654,9 +489,15 @@ Note these functions are responsible for =head2 Parameters +Most of these parameters are only useful if you are *not* using the folder interface (i.e., the default first column), which is probably the common case. If you are using this interface, then you should be able to get away with just using 'cols' (to specify the columns shown), 'url' (necessary for the folders to link to the current screen correctly), and possibly 'queryString' if your app calls for it. In that case, maintaining the state of the folders will be done automatically. + =over 4 -=item * B: A reference to a fresh ::iterator to use from the navmaps. The rendering will reflect the options passed to the iterator, so you can use that to just render a certain part of the course, if you like. +=item * B: A reference to a fresh ::iterator to use from the navmaps. The rendering will reflect the options passed to the iterator, so you can use that to just render a certain part of the course, if you like. If one is not passed, the renderer will attempt to construct one from ENV{'form.filter'} and ENV{'form.condition'} information, plus the 'iterator_map' parameter if any. + +=item * B: If you are letting the renderer do the iterator handling, you can instruct the renderer to render only a particular map by passing it the source of the map you want to process, like '/res/103/jerf/navmap.course.sequence'. + +=item * B: A reference to a navmap, used only if an iterator is not passed in. If this is necessary to make an iterator but it is not passed in, a new one will be constructed based on ENV info. This is useful to do basic error checking before passing it off to render. =item * B: An array reference @@ -664,11 +505,11 @@ Note these functions are responsible for =item * B: A flag. If yes (default), if all parts of the problem have the same status and that status is Nothing Set, Correct, or Network Failure, then only one line will be displayed for that resource anyhow. If no, all parts will always be displayed. If showParts is 0, this is ignored. -=item * B: A string identifying the URL to place the anchor 'curloc' at. Default to no anchor at all. It is the responsibility of the renderer user to ensure that the #curloc is in the URL. +=item * B: A string identifying the URL to place the anchor 'curloc' at. Default to no anchor at all. It is the responsibility of the renderer user to ensure that the #curloc is in the URL. By default, determined through the use of the ENV{} 'jump' and 'jumpType' information. -=item * B: A URL identifying where to place the 'here' marker. +=item * B: A URL identifying where to place the 'here' marker. By default, will pull this from the ENV{'form.here*'} info. -=item * B: A Symb identifying where to place the 'here' marker. +=item * B: A Symb identifying where to place the 'here' marker. Default same as hereURL. =item * B: A string identifying the indentation string to use. By default, this is a 25 pixel whitespace image with no alt text. @@ -676,16 +517,24 @@ Note these functions are responsible for =item * B: The url the folders will link to, which should be the current page. Required if the resource info column is shown. -=item * B: Describes the currently-open row number to cause the browser to jump to, because the user just opened that folder. +=item * B: Describes the currently-open row number to cause the browser to jump to, because the user just opened that folder. By default, pulled from the Jump information in the ENV{'form.*'}. =item * B: The standard Apache response object. If you pass this to the render, it will use it to flush the table every 20 rows and handle the rendering itself. +=item * B: If true, print the key that appears on the top of the standard navmaps. Default is false. + +=item * B: If true, print the "Close all folders" or "open all folders" links. Default is true. + +=item * B: A function that takes the resource object as its only parameter and returns a true or false value. If true, the resource is displayed. If false, it is simply skipped in the display. By default, all resources are showne. + =back =head2 Additional Info In addition to the parameters you can pass to the renderer, which will be passed through unchange to the column renderers, the renderer will generate the following information which your renderer may find useful: +If you want to know how many rows were printed, the 'counter' element of the hash passed into the render function will contain the count. You may want to check whether any resources were printed at all. + =over 4 =back @@ -720,7 +569,6 @@ sub render_resource { # If this is a new branch, label it so if ($params->{'isNewBranch'}) { $newBranchText = ""; - $params->{'isNewBranch'} = 0; } # links to open and close the folder @@ -745,19 +593,31 @@ sub render_resource { if ($it->{CONDITION}) { $nowOpen = !$nowOpen; } - $icon = 'navmap.folder.' . ($nowOpen ? 'closed' : 'open') . '.gif'; - $icon = ""; - - $linkopen = "{'queryString'} . '&filter='; - $linkopen .= ($nowOpen xor $it->{CONDITION}) ? - addToFilter($filter, $mapId) : - removeFromFilter($filter, $mapId); - $linkopen .= "&condition=" . $it->{CONDITION} . '&hereType=' - . $params->{'hereType'} . '&here=' . - &Apache::lonnet::escape($params->{'here'}) . - '&jumpType=' . SYMB() . '&jump=' . - &Apache::lonnet::escape($resource->symb()) . "'>"; + + if (!$params->{'resource_no_folder_link'}) { + $icon = 'navmap.folder.' . ($nowOpen ? 'closed' : 'open') . '.gif'; + $icon = ""; + + $linkopen = "{'queryString'} . '&filter='; + $linkopen .= ($nowOpen xor $it->{CONDITION}) ? + addToFilter($filter, $mapId) : + removeFromFilter($filter, $mapId); + $linkopen .= "&condition=" . $it->{CONDITION} . '&hereType=' + . $params->{'hereType'} . '&here=' . + &Apache::lonnet::escape($params->{'here'}) . + '&jumpType=' . SYMB() . '&jump=' . + &Apache::lonnet::escape($resource->symb()) . + "&folderManip=1'>"; + } else { + # Don't allow users to manipulate folder + $icon = 'navmap.folder.' . ($nowOpen ? 'closed' : 'open') . + '.nomanip.gif'; + $icon = ""; + + $linkopen = ""; + $linkclose = ""; + } } if ($resource->randomout()) { @@ -766,10 +626,12 @@ sub render_resource { # We're done preparing and finally ready to start the rendering my $result = ""; + if (!$params->{'resource_nolink'}) { + $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText"; + } else { + $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText"; + } return $result; } @@ -913,39 +779,236 @@ sub setDefault { sub render { my $args = shift; - + &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); + my $result = ''; + # Configure the renderer. my $cols = $args->{'cols'}; if (!defined($cols)) { # no columns, no nav maps. return ''; } - my $it = $args->{'iterator'}; - if (!defined($it)) { - # no iterator, no nav map. - return ''; + my $mustCloseNavMap = 0; + my $navmap; + if (defined($args->{'navmap'})) { + $navmap = $args->{'navmap'}; } - - my $showParts = setDefault($args->{'showParts'}, 1); - my $condenseParts = setDefault($args->{'condenseParts'}, 1); + + my $queryString = $args->{'queryString'}; my $jumpToURL = $args->{'jumpToURL'}; my $jumpToSymb = $args->{'jumpToSymb'}; + my $jumpType; my $hereURL = $args->{'hereURL'}; my $hereSymb = $args->{'hereSymb'}; - # keeps track of when the current resource is found, - # so we can back up a few and put the anchor above the - # current resource + my $hereType; + my $here; + my $jump; my $currentJumpIndex = setDefault($args->{'currentJumpIndex'}, 0); my $currentJumpDelta = 2; # change this to change how many resources are displayed # before the current resource when using #current - my $r = $args->{'r'}; + + # If we were passed 'here' information, we are not rendering + # after a folder manipulation, and we were not passed an + # iterator, make sure we open the folders to show the "here" + # marker + my $filterHash = {}; + # Figure out what we're not displaying + foreach (split(/\,/, $ENV{"form.filter"})) { + if ($_) { + $filterHash->{$_} = "1"; + } + } + + my $condition = 0; + if ($ENV{'form.condition'}) { + $condition = 1; + } + + if (!$ENV{'form.folderManip'} && !defined($args->{'iterator'})) { + # Step 1: Check to see if we have a navmap + if (!defined($navmap)) { + $navmap = Apache::lonnavmaps::navmap->new( + $ENV{"request.course.fn"}.".db", + $ENV{"request.course.fn"}."_parms.db", 1, 1); + $mustCloseNavMap = 1; + } + $navmap->init(); + + # Step two: Locate what kind of here marker is necessary + # Determine where the "here" marker is and where the screen jumps to. + + # 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/^[^\/]+//; + + $hereType = $jumpType = URL; + $here = $jump = $currenturl; + } else { + # Nothing + $hereType = $jumpType = NOTHING(); + } + # Step three: Ensure the folders are open + my $mapIterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $mapIterator->next(); # discard the first BEGIN_MAP + my $curRes = $mapIterator->next(); + my $counter = 0; + my $found = 0; + + # We only need to do this if we need to open the maps to show the + # current position. This will change the counter so we can't count + # for the jump marker with this loop. + while ($depth > 0 && !$found) { + if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } + if ($curRes == $mapIterator->END_MAP()) { $depth--; } + + if (ref($curRes) && + ($hereType == SYMB() && $curRes->symb() eq $here) || + (ref($curRes) && $hereType == URL() && $curRes->src() eq $here)) { + my $mapStack = $mapIterator->getStack(); + + # Ensure the parent maps are open + for my $map (@{$mapStack}) { + if ($condition) { + undef $filterHash->{$map->map_pc()}; + } else { + $filterHash->{$map->map_pc()} = 1; + } + } + $found = 1; + } + + $curRes = $mapIterator->next(); + } + + # Since we changed the folders, (re-)locate the jump point, if any + $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0); + $depth = 1; + $mapIterator->next(); + $curRes = $mapIterator->next(); + my $foundJump = 0; + + while ($depth > 0 && !$foundJump) { + if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; } + if ($curRes == $mapIterator->END_MAP()) { $depth--; } + if (ref($curRes)) { $counter++; } + + if (ref($curRes) && + (($jumpType == SYMB() && $curRes->symb() eq $jump) || + ($jumpType == URL() && $curRes->src() eq $jump))) { + + # This is why we have to use the main iterator instead of the + # potentially faster DFS: The count has to be the same, so + # the order has to be the same, which DFS won't give us. + $currentJumpIndex = $counter; + $foundJump = 1; + } + + $curRes = $mapIterator->next(); + } + } + if ( !defined($args->{'iterator'}) && $ENV{'form.folderManip'} ) { # 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'}; + } - + my $it = $args->{'iterator'}; + if (!defined($it)) { + # Construct a default iterator based on $ENV{'form.'} information + + # Step 1: Check to see if we have a navmap + if (!defined($navmap)) { + $navmap = Apache::lonnavmaps::navmap->new( + $ENV{"request.course.fn"}.".db", + $ENV{"request.course.fn"}."_parms.db", 1, 1); + $mustCloseNavMap = 1; + } + # Paranoia: Make sure it's ready + $navmap->init(); + + # See if we're being passed a specific map + if ($args->{'iterator_map'}) { + my $map = $args->{'iterator_map'}; + $map = $navmap->getResourceByUrl($map); + my $firstResource = $map->map_start(); + my $finishResource = $map->map_finish(); + + $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition); + } else { + $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition); + } + } + + my $showParts = setDefault($args->{'showParts'}, 1); + my $condenseParts = setDefault($args->{'condenseParts'}, 1); + # keeps track of when the current resource is found, + # so we can back up a few and put the anchor above the + # current resource + my $r = $args->{'r'}; + my $printKey = $args->{'printKey'}; + my $printCloseAll = $args->{'printCloseAll'}; + if (!defined($printCloseAll)) { $printCloseAll = 1; } + my $filterFunc = setDefault($args->{'filterFunc'}, + sub {return 1;}); + + # Print key? + if ($printKey) { + $result .= '
"; - + + my $indentLevel = $params->{'indentLevel'}; + if ($newBranchText) { $indentLevel--; } + # print indentation - for (my $i = 0; $i < $params->{'indentLevel'} - - $params->{'deltaLevel'}; $i++) { + for (my $i = 0; $i < $indentLevel; $i++) { $result .= $params->{'indentString'}; } @@ -799,7 +661,11 @@ sub render_resource { $nonLinkedText .= ' (' . $resource->countParts() . ' parts)'; } - $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText
'; + my $date=localtime; + $result.=''; + if ($navmap->{LAST_CHECK}) { + $result .= + ' New discussion since '. + strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})). + ''; + } else { + $result .= ''; + } + + $result .= '
Key:    '. + ' New message (click to open)

'. + '

  '. + ' Discussions'. + '   New message (click to open)'. + '
'; + } + + if ($printCloseAll) { + if ($condition) { + $result.="Close All Folders"; + } else { + $result.="Open All Folders"; + } + $result .= "

\n"; + } + + if ($r) { + $r->print($result); + $r->rflush(); + $result = ""; + } # End parameter setting # Data - my $result .= '' ."\n"; + $result .= '
' ."\n"; my $res = "Apache::lonnavmaps::resource"; my %condenseStatuses = ( $res->NETWORK_FAILURE => 1, @@ -970,6 +1033,10 @@ sub render { my $in24Hours = $now + 24 * 60 * 60; my $rownum = 0; + # export "here" marker information + $args->{'here'} = $here; + $args->{'hereType'} = $hereType; + while ($depth > 0) { if ($curRes == $it->BEGIN_MAP()) { $depth++; } if ($curRes == $it->END_MAP()) { $depth--; } @@ -995,15 +1062,13 @@ sub render { } $args->{'counter'}++; - # reserve space for branch symbol - $args->{'deltalevel'} = $args->{'isNewBranch'}? 1 : 0; - if ($args->{'indentLevel'} - $args->{'deltalevel'} < 0) { - # If this would be at a negative depth (top-level maps in - # new-style courses, we want to suppress their title display) - # then ignore it. + + # If this has been filtered out, continue on + if (!(&$filterFunc($curRes))) { $curRes = $it->next(); + $args->{'isNewBranch'} = 0; # Don't falsely remember this next; - } + } # Does it have multiple parts? $args->{'multipart'} = 0; @@ -1114,6 +1179,7 @@ sub render { $result .= $colHTML . "\n"; } $result .= " \n"; + $args->{'isNewBranch'} = 0; } if ($r && $rownum % 20 == 0) { @@ -1131,6 +1197,14 @@ sub render { } $result .= "
"; + + if ($r) { + $r->print($result); + $result = ""; + $r->rflush(); + } + + if ($mustCloseNavMap) { $navmap->untieHashes(); } return $result; } @@ -1200,6 +1274,7 @@ sub new { $self->{HASH_TIED} = 1; $self->{NAV_HASH} = \%navmaphash; $self->{PARM_HASH} = \%parmhash; + $self->{INITED} = 0; bless($self); @@ -1208,6 +1283,7 @@ sub new { sub init { my $self = shift; + if ($self->{INITED}) { return; } # If the course opt hash and the user opt hash should be generated, # generate them @@ -1313,6 +1389,7 @@ sub init { } $self->{PARM_CACHE} = {}; + $self->{INITED} = 1; } # Internal function: Takes a key to look up in the nav hash and implements internal @@ -1536,6 +1613,57 @@ sub parmval_real { return ''; } +=pod + +=item * B(url): Retrieves a resource object by URL of the resource. If passed a resource object, it will simply return it, so it is safe to use this method in code like "$res = $navmap->getResourceByUrl($res)", if you're not sure if $res is already an object, or just a URL. If the resource appears multiple times in the course, only the first instance will be returned. As a result, this is probably useful only for maps. + +=item * B(map, filterFunc, recursive, bailout): The map is a specification of a map to retreive the resources from, either as a url or as an object. The filterFunc is a reference to a function that takes a resource object as its one argument and returns true if the resource should be included, or false if it should not be. If recursive is true, the map will be recursively examined, otherwise it will not be. If bailout is true, the function will return as soon as it finds a resource, if false it will finish. By default, the map is the top-level map of the course, filterFunc is a function that always returns 1, recursive is true, bailout is false. The resources will be returned in a list reference containing the resource objects for the corresponding resources, with B in the list; regardless of branching, recursion, etc., it will be a flat list. + +Thus, this is suitable for cases where you don't want the structure, just a list of all resources. It is also suitable for finding out how many resources match a given description; for this use, if all you want to know is if I resources match the description, the bailout parameter will allow you to avoid potentially expensive enumeration of all matching resources. + +=cut + +sub getResourceByUrl { + my $self = shift; + my $resUrl = shift; + + if (ref($resUrl)) { return $resUrl; } + + $resUrl = &Apache::lonnet::clutter($resUrl); + my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl}; + if ($resId =~ /,/) { + $resId = (split (/,/, $resId))[0]; + } + if (!$resId) { return ''; } + return $self->getById($resId); +} + +sub retrieveResources { + my $self = shift; + my $map = shift; + my $filterFunc = shift; + if (!defined ($filterFunc)) { + $filterFunc = sub {return 1;}; + } + my $recursive = shift; + if (!defined($recursive)) { $recursive = 1; } + my $bailout = shift; + if (!defined($bailout)) { $bailout = 0; } + + # Create the necessary iterator. + if (!ref($map)) { # assume it's a url of a map. + $map = $self->getMapByUrl($map); + } + + # Check the map's validity. + if (!$map || !$map->is_map()) { + # Oh, to throw an exception.... how I'd love that! + return (); + } + + # UNFINISHED... I was checking in getResourceByUrl +} + 1; package Apache::lonnavmaps::iterator; @@ -1964,7 +2092,7 @@ sub new { # A hash, used as a set, of resource already seen $self->{ALREADY_SEEN} = shift; - if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} }; + if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} }; $self->{CONDITION} = shift; $self->{DIRECTION} = shift || FORWARD(); @@ -2087,7 +2215,7 @@ A resource object encapsulates a resourc A resource only makes sense in the context of a navmap, as some of the data is stored in the navmap object. -You will probably never need to instantiate this object directly. Use Apache::lonnavmap::navmap, and use the "start" method to obtain the starting resource. +You will probably never need to instantiate this object directly. Use Apache::lonnavmaps::navmap, and use the "start" method to obtain the starting resource. =head2 Public Members @@ -2218,8 +2346,6 @@ These methods are shortcuts to deciding =item * B: Returns true if the resource is a page. -=item * B: Returns true if the resource is a problem. - =item * B: Returns true if the resource is a sequence. =back @@ -2280,6 +2406,7 @@ These methods are useful for getting inf sub map_finish { my $self = shift; my $src = $self->src(); + $src = Apache::lonnet::clutter($src); my $res = $self->navHash("map_finish_$src", 0); $res = $self->{NAV_MAP}->getById($res); return $res; @@ -2292,6 +2419,7 @@ sub map_pc { sub map_start { my $self = shift; my $src = $self->src(); + $src = Apache::lonnet::clutter($src); my $res = $self->navHash("map_start_$src", 0); $res = $self->{NAV_MAP}->getById($res); return $res; @@ -2468,7 +2596,7 @@ sub getErrors { =pod -=item * B(): Returns a list reference containing sorted strings corresponding to each part of the problem. To count the number of parts, use the list in a scalar context, and subtract one if greater then two. (One part problems have a part 0. Multi-parts have a part 0, plus a part for each part. Filtering part 0 if you want it is up to you.) +=item * B(): Returns a list reference containing sorted strings corresponding to each part of the problem. To count the number of parts, use the list in a scalar context, and subtract one if greater than two. (One part problems have a part 0. Multi-parts have a part 0, plus a part for each part. Filtering part 0 if you want it is up to you.) =item * B(): Returns the number of parts of the problem a student can answer. Thus, for single part problems, returns 1. For multipart, it returns the number of parts in the problem, not including psuedo-part 0. Thus, B may return an array with fewer parts in it then countParts might lead you to believe.