--- loncom/interface/lonnavmaps.pm 2003/02/07 22:16:53 1.141 +++ 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.141 2003/02/07 22:16:53 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.145 2003/02/21 20:05:00 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -463,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. @@ -491,7 +493,9 @@ Most of these parameters are only useful =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. If one is not passed, the renderer will attempt to construct one from ENV{'form.filter'} and ENV{'form.condition'} information. +=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. @@ -521,12 +525,16 @@ Most of these parameters are only useful =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 @@ -585,20 +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()) . - "&folderManip=1'>"; + + 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()) { @@ -642,7 +661,11 @@ sub render_resource { $nonLinkedText .= ' (' . $resource->countParts() . ' parts)'; } - $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText"; + if (!$params->{'resource_nolink'}) { + $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText"; + } else { + $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText"; + } return $result; } @@ -917,7 +940,17 @@ sub render { # Paranoia: Make sure it's ready $navmap->init(); - $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition); + # 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); @@ -929,7 +962,9 @@ sub render { 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 .= ''; @@ -962,6 +997,7 @@ sub render { "&hereType=$hereType&here=" . Apache::lonnet::escape($here) . "\">Open All Folders"; } + $result .= "

\n"; } if ($r) { @@ -1027,6 +1063,13 @@ sub render { $args->{'counter'}++; + # 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; $args->{'condensed'} = 0; @@ -1570,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; @@ -2312,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; @@ -2324,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; @@ -2500,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.