version 1.162, 2003/03/20 18:03:14
|
version 1.173, 2003/04/04 21:00:54
|
Line 49 use Apache::loncommon();
|
Line 49 use Apache::loncommon();
|
use Apache::lonmenu(); |
use Apache::lonmenu(); |
use POSIX qw (floor strftime); |
use POSIX qw (floor strftime); |
|
|
my %navmaphash; |
|
my %parmhash; |
|
|
|
# symbolic constants |
# symbolic constants |
sub SYMB { return 1; } |
sub SYMB { return 1; } |
sub URL { return 2; } |
sub URL { return 2; } |
Line 99 my %colormap =
|
Line 96 my %colormap =
|
# is not yet done and due in less then 24 hours |
# is not yet done and due in less then 24 hours |
my $hurryUpColor = "#FF0000"; |
my $hurryUpColor = "#FF0000"; |
|
|
sub cleanup { |
|
if (tied(%navmaphash)){ |
|
&Apache::lonnet::logthis('Cleanup navmaps: navmaphash'); |
|
unless (untie(%navmaphash)) { |
|
&Apache::lonnet::logthis('Failed cleanup navmaps: navmaphash'); |
|
} |
|
} |
|
if (tied(%parmhash)){ |
|
&Apache::lonnet::logthis('Cleanup navmaps: parmhash'); |
|
unless (untie(%parmhash)) { |
|
&Apache::lonnet::logthis('Failed cleanup navmaps: parmhash'); |
|
} |
|
} |
|
} |
|
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
real_handler($r); |
real_handler($r); |
Line 217 sub real_handler {
|
Line 199 sub real_handler {
|
# renderer call |
# renderer call |
my $render = render({ 'cols' => [0,1,2,3], |
my $render = render({ 'cols' => [0,1,2,3], |
'url' => '/adm/navmaps', |
'url' => '/adm/navmaps', |
|
'navmap' => $navmap, |
'suppressNavmap' => 1, |
'suppressNavmap' => 1, |
'r' => $r}); |
'r' => $r}); |
|
|
Line 508 The pre-packaged column names are refere
|
Line 491 The pre-packaged column names are refere
|
|
|
=item * B<resource_part_count>: 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<resource_part_count>: 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<resource_no_folder_link>: If true, the resource's folder will not be clickable to open or close it. Default is false. |
=item * B<resource_no_folder_link>: If true, the resource's folder will not be clickable to open or close it. Default is false. True implies printCloseAll is false, since you can't close or open folders when this is on anyhow. |
|
|
=back |
=back |
|
|
Line 544 Most of these parameters are only useful
|
Line 527 Most of these parameters are only useful
|
|
|
=item * B<navmap>: 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<navmap>: 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<r>: The standard Apache response object. This must be passed to the renderer or the course hash will be locked. |
|
|
=item * B<cols>: An array reference |
=item * B<cols>: An array reference |
|
|
=item * B<showParts>: A flag. If yes (default), a line for the resource itself, and a line for each part will be displayed. If not, only one line for each resource will be displayed. |
=item * B<showParts>: A flag. If yes (default), a line for the resource itself, and a line for each part will be displayed. If not, only one line for each resource will be displayed. |
Line 562 Most of these parameters are only useful
|
Line 547 Most of these parameters are only useful
|
|
|
=item * B<currentJumpIndex>: 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<currentJumpIndex>: 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<r>: 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<printKey>: If true, print the key that appears on the top of the standard navmaps. Default is false. |
=item * B<printKey>: If true, print the key that appears on the top of the standard navmaps. Default is false. |
|
|
=item * B<printCloseAll>: If true, print the "Close all folders" or "open all folders" links. Default is true. |
=item * B<printCloseAll>: If true, print the "Close all folders" or "open all folders" links. Default is true. |
Line 700 sub render_resource {
|
Line 683 sub render_resource {
|
$title = ""; |
$title = ""; |
} |
} |
|
|
if ($params->{'multipart'} && $params->{'condensed'}) { |
if ($params->{'condensed'} && $resource->countParts() > 1) { |
$nonLinkedText .= ' (' . $resource->countParts() . ' parts)'; |
$nonLinkedText .= ' (' . $resource->countParts() . ' parts)'; |
} |
} |
|
|
Line 931 sub render {
|
Line 914 sub render {
|
|
|
# Step 1: Check to see if we have a navmap |
# Step 1: Check to see if we have a navmap |
if (!defined($navmap)) { |
if (!defined($navmap)) { |
$navmap = Apache::lonnavmaps::navmap->new( |
$navmap = Apache::lonnavmaps::navmap->new($r, |
$ENV{"request.course.fn"}.".db", |
$ENV{"request.course.fn"}.".db", |
$ENV{"request.course.fn"}."_parms.db", 1, 1); |
$ENV{"request.course.fn"}."_parms.db", 1, 1); |
$mustCloseNavMap = 1; |
$mustCloseNavMap = 1; |
Line 1010 sub render {
|
Line 993 sub render {
|
$result .= '</tr></table>'; |
$result .= '</tr></table>'; |
} |
} |
|
|
if ($printCloseAll) { |
if ($printCloseAll && !$args->{'resource_no_folder_link'}) { |
if ($condition) { |
if ($condition) { |
$result.="<a href=\"navmaps?condition=0&filter=&$queryString" . |
$result.="<a href=\"navmaps?condition=0&filter=&$queryString" . |
"&here=" . Apache::lonnet::escape($here) . |
"&here=" . Apache::lonnet::escape($here) . |
Line 1226 sub render {
|
Line 1209 sub render {
|
$r->rflush(); |
$r->rflush(); |
} |
} |
|
|
if ($mustCloseNavMap) { $navmap->untieHashes(); } |
#if ($mustCloseNavMap) { $navmap->untieHashes(); } |
|
|
return $result; |
return $result; |
} |
} |
Line 1251 You must obtain resource objects through
|
Line 1234 You must obtain resource objects through
|
|
|
=over 4 |
=over 4 |
|
|
=item * B<new>(navHashFile, parmHashFile, genCourseAndUserOptions, genMailDiscussStatus): Binds a new navmap object to the compiled nav map hash and parm hash given as filenames. genCourseAndUserOptions is a flag saying whether the course options and user options hash should be generated. This is for when you are using the parameters of the resources that require them; see documentation in resource object documentation. genMailDiscussStatus causes the nav map to retreive information about the email and discussion status of resources. Returns the navmap object if this is successful, or B<undef> if not. You must check for undef; errors will occur when you try to use the other methods otherwise. |
=item * B<new>(navHashFile, parmHashFile, genCourseAndUserOptions, |
|
genMailDiscussStatus): Binds a new navmap object to the compiled nav map |
|
hash and parm hash given as filenames. genCourseAndUserOptions is a flag |
|
saying whether the course options and user options hash should be generated. |
|
This is for when you are using the parameters of the resources that require |
|
them; see documentation in resource object documentation. genMailDiscussStatus |
|
causes the nav map to retreive information about the email and discussion |
|
status of resources. Returns the navmap object if this is successful, or |
|
B<undef> if not. You must check for undef; errors will occur when you try |
|
to use the other methods otherwise. |
|
|
=item * B<getIterator>(first, finish, filter, condition): See iterator documentation below. |
=item * B<getIterator>(first, finish, filter, condition): See iterator documentation below. |
|
|
Line 1281 sub new {
|
Line 1273 sub new {
|
|
|
# tie the nav hash |
# tie the nav hash |
|
|
|
my %navmaphash; |
|
my %parmhash; |
if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE}, |
if (!(tie(%navmaphash, 'GDBM_File', $self->{NAV_HASH_FILE}, |
&GDBM_READER(), 0640))) { |
&GDBM_READER(), 0640))) { |
return undef; |
return undef; |
Line 1289 sub new {
|
Line 1283 sub new {
|
if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE}, |
if (!(tie(%parmhash, 'GDBM_File', $self->{PARM_HASH_FILE}, |
&GDBM_READER(), 0640))) |
&GDBM_READER(), 0640))) |
{ |
{ |
untie $self->{PARM_HASH}; |
untie %{$self->{PARM_HASH}}; |
return undef; |
return undef; |
} |
} |
|
|
$self->{HASH_TIED} = 1; |
|
$self->{NAV_HASH} = \%navmaphash; |
$self->{NAV_HASH} = \%navmaphash; |
$self->{PARM_HASH} = \%parmhash; |
$self->{PARM_HASH} = \%parmhash; |
$self->{INITED} = 0; |
$self->{INITED} = 0; |
Line 1441 sub getIterator {
|
Line 1434 sub getIterator {
|
# unties the hash when done |
# unties the hash when done |
sub untieHashes { |
sub untieHashes { |
my $self = shift; |
my $self = shift; |
untie %{$self->{NAV_HASH}} if ($self->{HASH_TIED}); |
untie %{$self->{NAV_HASH}}; |
untie %{$self->{PARM_HASH}} if ($self->{HASH_TIED}); |
untie %{$self->{PARM_HASH}}; |
$self->{HASH_TIED} = 0; |
|
} |
|
|
|
# when the object is destroyed, be sure to untie all the hashes we tied. |
|
sub DESTROY { |
|
my $self = shift; |
|
$self->untieHashes(); |
|
} |
} |
|
|
# Private method: Does the given resource (as a symb string) have |
# Private method: Does the given resource (as a symb string) have |
Line 1511 sub getById {
|
Line 1497 sub getById {
|
return "Apache::lonnavmaps::resource"->new($self, $id); |
return "Apache::lonnavmaps::resource"->new($self, $id); |
} |
} |
|
|
|
sub getBySymb { |
|
my $self = shift; |
|
my $symb = shift; |
|
my ($mapUrl, $id, $filename) = split (/___/, $symb); |
|
my $map = $self->getResourceByUrl($mapUrl); |
|
return $self->getById($map->map_pc() . '.' . $id); |
|
} |
|
|
=pod |
=pod |
|
|
=item * B<firstResource>(): Returns a resource object reference corresponding to the first resource in the navmap. |
=item * B<firstResource>(): Returns a resource object reference corresponding to the first resource in the navmap. |
Line 1637 sub parmval_real {
|
Line 1631 sub parmval_real {
|
|
|
=item * B<getResourceByUrl>(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<getResourceByUrl>(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<retrieveResources>(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<no structure information> in the list; regardless of branching, recursion, etc., it will be a flat list. |
=item * B<retrieveResources>(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 containing the resource objects for the corresponding resources, with B<no structure information> 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<any> resources match the description, the bailout parameter will allow you to avoid potentially expensive enumeration of all matching resources. |
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<any> resources match the description, the bailout parameter will allow you to avoid potentially expensive enumeration of all matching resources. |
|
|
Line 1678 sub retrieveResources {
|
Line 1672 sub retrieveResources {
|
|
|
# Create the necessary iterator. |
# Create the necessary iterator. |
if (!ref($map)) { # assume it's a url of a map. |
if (!ref($map)) { # assume it's a url of a map. |
$map = $self->getMapByUrl($map); |
$map = $self->getResourceByUrl($map); |
} |
} |
|
|
# Check the map's validity. |
# Check the map's validity. |
Line 2698 sub countParts {
|
Line 2692 sub countParts {
|
my $self = shift; |
my $self = shift; |
|
|
my $parts = $self->parts(); |
my $parts = $self->parts(); |
|
my $delta = 0; |
|
for my $part (@$parts) { |
|
if ($part eq '0') { $delta--; } |
|
} |
|
|
if ($self->{RESOURCE_ERROR}) { |
if ($self->{RESOURCE_ERROR}) { |
return 0; |
return 0; |
} |
} |
|
|
if (scalar(@{$parts}) < 2) { return 1;} |
return scalar(@{$parts}) + $delta; |
|
|
return scalar(@{$parts}) - 1; |
|
} |
} |
|
|
# Private function: Extracts the parts information and saves it |
# Private function: Extracts the parts information and saves it |