--- loncom/interface/lonnavmaps.pm 2012/12/29 17:37:20 1.492 +++ loncom/interface/lonnavmaps.pm 2015/10/05 16:23:49 1.511 @@ -1,8 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.492 2012/12/29 17:37:20 raeburn Exp $ - +# $Id: lonnavmaps.pm,v 1.511 2015/10/05 16:23:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -164,6 +163,12 @@ If true, the resource's folder will not it. Default is false. True implies printCloseAll is false, since you can't close or open folders when this is on anyhow. +=item * B: + +If true, the title of the folder or page will not be followed by an +icon/link to direct editing of a folder or composite page, originally +added via the Course Editor. + =back =item * B: @@ -488,7 +493,7 @@ use HTML::Entities; # For debugging -use Data::Dumper; +#use Data::Dumper; # symbolic constants @@ -613,49 +618,57 @@ sub getDescription { return &mt("Having technical difficulties; please check status later"); } if ($status == $res->NOTHING_SET) { - return &Apache::lonhtmlcommon::direct_parm_link(&mt("Not currently assigned.",$res->symb(),'opendate'),$part); + return &Apache::lonhtmlcommon::direct_parm_link(&mt('Not currently assigned'),$res->symb(),'opendate',$part); } if ($status == $res->OPEN_LATER) { return &mt("Open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($open,'start'),$res->symb(),'opendate',$part)); } + my $slotinfo; if ($res->simpleStatus($part) == $res->OPEN) { unless (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) { my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part); + my $slotmsg; if ($slot_status == $res->UNKNOWN) { - return &mt('Reservation status unknown'); + $slotmsg = &mt('Reservation status unknown'); } elsif ($slot_status == $res->RESERVED) { - return &mt('Reserved - ends [_1]', + $slotmsg = &mt('Reserved - ends [_1]', timeToHumanString($slot_time,'end')); } elsif ($slot_status == $res->RESERVED_LOCATION) { - return &mt('Reserved - specific location(s) - ends [_1]', + $slotmsg = &mt('Reserved - specific location(s) - ends [_1]', timeToHumanString($slot_time,'end')); } elsif ($slot_status == $res->RESERVED_LATER) { - return &mt('Reserved - next open [_1]', + $slotmsg = &mt('Reserved - next open [_1]', timeToHumanString($slot_time,'start')); } elsif ($slot_status == $res->RESERVABLE) { - return &mt('Reservable, reservations close [_1]', + $slotmsg = &mt('Reservable, reservations close [_1]', timeToHumanString($slot_time,'end')); } elsif ($slot_status == $res->RESERVABLE_LATER) { - return &mt('Reservable, reservations open [_1]', + $slotmsg = &mt('Reservable, reservations open [_1]', timeToHumanString($slot_time,'start')); } elsif ($slot_status == $res->NOT_IN_A_SLOT) { - return &mt('Reserve a time/place to work'); + $slotmsg = &mt('Reserve a time/place to work'); } elsif ($slot_status == $res->NOTRESERVABLE) { - return &mt('Reservation not available'); + $slotmsg = &mt('Reservation not available'); } elsif ($slot_status == $res->WAITING_FOR_GRADE) { - return &mt('Submission in grading queue'); + $slotmsg = &mt('Submission in grading queue'); + } + if ($slotmsg) { + if ($res->is_task() || !$due) { + return $slotmsg; + } + $slotinfo = (' ' x 2).'('.$slotmsg.')'; } } } if ($status == $res->OPEN) { if ($due) { if ($res->is_practice()) { - return &mt("Closes [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'duedate',$part)); + return &mt("Closes [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'duedate',$part)).$slotinfo; } else { - return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)); + return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)).$slotinfo; } } else { - return &Apache::lonhtmlcommon::direct_parm_link(&mt("Open, no due date"),$res->symb(),'duedate',$part); + return &Apache::lonhtmlcommon::direct_parm_link(&mt("Open, no due date"),$res->symb(),'duedate',$part).$slotinfo; } } if ($status == $res->PAST_DUE_ANSWER_LATER) { @@ -981,11 +994,13 @@ sub render_resource { } if ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) && ($resource->symb=~/\_\_\_[^\_]+\_\_\_uploaded/)) { - my $icon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png'; - $editmapLink=' '. - ''. + if (!$params->{'map_no_edit_link'}) { + my $icon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png'; + $editmapLink=' '. + ''. ''.&mt('Edit Content').''. ''; + } } } @@ -1132,12 +1147,17 @@ sub render_long_status { my $info = ''; if ($resource->is_problem() || $resource->is_practice()) { $color = $colormap{$resource->status}; - - if (dueInLessThan24Hours($resource, $part) || - lastTry($resource, $part)) { + + if (dueInLessThan24Hours($resource, $part)) { $color = $hurryUpColor; $info = ' title="'.&mt('Due in less than 24 hours!').'"'; - } + } elsif (lastTry($resource, $part)) { + unless (($resource->problemstatus($part) eq 'no') || + ($resource->problemstatus($part) eq 'no_feedback_ever')) { + $color = $hurryUpColor; + $info = ' title="'.&mt('One try remaining!').'"'; + } + } } if ($resource->kind() eq "res" && @@ -2007,11 +2027,12 @@ sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; - bless($self); # So we can call change_user if neceesary + bless($self); # So we can call change_user if necessary $self->{USERNAME} = shift || $env{'user.name'}; $self->{DOMAIN} = shift || $env{'user.domain'}; $self->{CODE} = shift; + $self->{NOHIDE} = shift; @@ -2025,10 +2046,14 @@ sub new { # We can only tie the nav hash as done below if the username/domain # match the env one. Otherwise change_user does everything we need...since we can't - # assume there are course hashes for the specific requested user@domamin: + # assume there are course hashes for the specific requested user:domain + # Note: change_user is also called if we need the nav hash when printing CODEd + # assignments or printing an exam, in which the enclosing folder for the items in + # the exam has hidden set. # - if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'}) && !$self->{CODE}) { + if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'}) && + !$self->{CODE} && !$self->{NOHIDE}) { # tie the nav hash @@ -2051,7 +2076,7 @@ sub new { $self->{PARM_HASH} = \%parmhash; $self->{PARM_CACHE} = {}; } else { - $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}); + $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}); } return $self; @@ -2072,6 +2097,7 @@ sub change_user { $self->{USERNAME} = shift; $self->{DOMAIN} = shift; $self->{CODE} = shift; + $self->{NOHIDE} = shift; # If the hashes are already tied make sure to break that bond: @@ -2087,7 +2113,7 @@ sub change_user { my ($cdom, $cnum) = split(/\_/, $env{'request.course.id'}); my %big_hash; - &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, \%big_hash); + &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}, \%big_hash); $self->{NAV_HASH} = \%big_hash; @@ -2098,7 +2124,7 @@ sub change_user { $self->{PARM_CACHE} = {}; my %parm_hash = {}; - foreach my $key (keys %big_hash) { + foreach my $key (keys(%big_hash)) { if ($key =~ /^param\./) { my $param_key = $key; $param_key =~ s/^param\.//; @@ -2108,9 +2134,7 @@ sub change_user { $self->{PARM_HASH} = \%parm_hash; - - -} +} sub generate_course_user_opt { my $self = shift; @@ -2173,7 +2197,7 @@ sub generate_email_discuss_status { my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss', $self->{DOMAIN},$self->{USERNAME},'lastread'); my %lastreadtime = (); - foreach my $key (keys %lastread) { + foreach my $key (keys(%lastread)) { my $shortkey = $key; $shortkey =~ s/_lastread$//; $lastreadtime{$shortkey} = $lastread{$key}; @@ -2910,7 +2934,7 @@ resource appears multiple times in the c will be returned (useful for maps), unless the multiple parameter has been included, in which case all instances are returned in an array. -=item * B(map, filterFunc, recursive, bailout, showall): +=item * B(map, filterFunc, recursive, bailout, showall, noblockcheck): 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 @@ -2919,13 +2943,18 @@ true if the resource should be included, 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. If showall is -true it will not hide maps that contain nothing but one other map. 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, -showall is false. The resources will be returned in a list containing -the resource objects for the corresponding resources, with B in the list; regardless of branching, -recursion, etc., it will be a flat list. +true it will not hide maps that contain nothing but one other map. The +noblockcheck arg is propagated to become the sixth arg in the call to +lonnet::allowed when checking a resource's availability during collection +of resources using the iterator. noblockcheck needs to be true if +retrieveResources() was called by a routine that itself was called by +lonnet::allowed, in order to avoid recursion. 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, showall is +false. The resources will be returned in a list 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 @@ -2992,6 +3021,7 @@ sub retrieveResources { my $bailout = shift; if (!defined($bailout)) { $bailout = 0; } my $showall = shift; + my $noblockcheck = shift; # Create the necessary iterator. if (!ref($map)) { # assume it's a url of a map. $map = $self->getResourceByUrl($map); @@ -3021,7 +3051,7 @@ sub retrieveResources { # Run down the iterator and collect the resources. my $curRes; - while ($curRes = $it->next()) { + while ($curRes = $it->next(undef,$noblockcheck)) { if (ref($curRes)) { if (!&$filterFunc($curRes)) { next; @@ -3172,7 +3202,14 @@ Note that inside of the loop, it's frequ resource objects will be references, and any non-references will be the tokens described above. -Also note there is some old code floating around that trys to track +The next() routine can take two (optional) arguments: +closeAllPages - if true will not recurse down a .page +noblockcheck - passed to browsePriv() for passing as sixth arg to +call to lonnet::allowed. This needs to be set if retrieveResources +was already called from another routine called within lonnet::allowed, +so as to prevent recursion. + +Also note there is some old code floating around that tries to track the depth of the iterator to see when it's done; do not copy that code. It is difficult to get right and harder to understand than this. They should be migrated to this new style. @@ -3319,15 +3356,11 @@ sub new { if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) { my $firstResource = $resource->map_start(); my $finishResource = $resource->map_finish(); - my $result; - $result = Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource, - $finishResource, $self->{FILTER}, - $self->{ALREADY_SEEN}, - $self->{CONDITION}, - $self->{FORCE_TOP}); - return $result; - - + return Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource, + $finishResource, $self->{FILTER}, + $self->{ALREADY_SEEN}, + $self->{CONDITION}, + $self->{FORCE_TOP}); } # Set up some bookkeeping information. @@ -3352,6 +3385,7 @@ sub new { sub next { my $self = shift; my $closeAllPages=shift; + my $noblockcheck = shift; if ($self->{FINISHED}) { return END_ITERATOR(); } @@ -3501,7 +3535,7 @@ sub next { # If this is a blank resource, don't actually return it. # Should you ever find you need it, make sure to add an option to the code # that you can use; other things depend on this behavior. - my $browsePriv = $self->{HERE}->browsePriv(); + my $browsePriv = $self->{HERE}->browsePriv($noblockcheck); if (!$self->{HERE}->src() || (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) { return $self->next($closeAllPages); @@ -3833,9 +3867,12 @@ sub new { # about this resource in. Not used by the resource object # directly. $self->{DATA} = {}; - + bless($self); + # This is a speed optimization, to avoid calling symb() too often. + $self->{SYMB} = $self->symb(); + return $self; } @@ -3947,8 +3984,8 @@ sub src { } sub shown_symb { my $self=shift; - if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->symb());} - return $self->symb(); + if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->{SYMB});} + return $self->{SYMB}; } sub id { my $self=shift; @@ -3969,7 +4006,7 @@ sub symb { } sub wrap_symb { my $self = shift; - return $self->{NAV_MAP}->wrap_symb($self->symb()); + return $self->{NAV_MAP}->wrap_symb($self->{SYMB}); } sub title { my $self=shift; @@ -4192,7 +4229,7 @@ sub parmval { if (!defined($part)) { $part = '0'; } - return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->symb()); + return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->{SYMB}); } =pod @@ -4225,7 +4262,7 @@ resource of the map. Returns a string with the type of the map in it. -=item *B: +=item * B: Returns a string with a comma-separated ordered list of map_pc IDs for the hierarchy of maps containing a map, with the top level @@ -4368,9 +4405,6 @@ sub printable { my ($self, $part) = @_; - &Apache::lonnet::logthis($self->symb()); - - # The following cases apply: # - If a start date is not set, it is replaced by the open date. # - Ditto for start/open replaced by content open. @@ -4448,25 +4482,25 @@ sub awarded { my $self = shift; my $part = shift; $self->{NAV_MAP}->get_user_data(); if (!defined($part)) { $part = '0'; } - return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.awarded'}; + return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.awarded'}; } sub taskversion { my $self = shift; my $part = shift; $self->{NAV_MAP}->get_user_data(); if (!defined($part)) { $part = '0'; } - return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.version'}; + return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.version'}; } sub taskstatus { my $self = shift; my $part = shift; $self->{NAV_MAP}->get_user_data(); if (!defined($part)) { $part = '0'; } - return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'}; + return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'}; } sub solved { my $self = shift; my $part = shift; $self->{NAV_MAP}->get_user_data(); if (!defined($part)) { $part = '0'; } - return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.solved'}; + return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.solved'}; } sub checkedin { my $self = shift; my $part = shift; @@ -4474,9 +4508,9 @@ sub checkedin { if (!defined($part)) { $part = '0'; } if ($self->is_task()) { my $version = $self->taskversion($part); - return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin.slot'}); + return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin.slot'}); } else { - return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin.slot'}); + return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin.slot'}); } } # this should work exactly like the copy in lonhomework.pm @@ -4568,7 +4602,7 @@ sub weight { my $self = shift; my $part = shift; if (!defined($part)) { $part = '0'; } my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight', - $self->symb(), $self->{DOMAIN}, + $self->{SYMB}, $self->{DOMAIN}, $self->{USERNAME}, $env{'request.course.sec'}); return $weight; @@ -4597,7 +4631,7 @@ sub getReturnHash { my $self = shift; if (!defined($self->{RETURN_HASH})) { - my %tmpHash = &Apache::lonnet::restore($self->symb(),undef,$self->{DOMAIN},$self->{USERNAME}); + my %tmpHash = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME}); $self->{RETURN_HASH} = \%tmpHash; } } @@ -4662,23 +4696,23 @@ and use the link as appropriate. sub hasDiscussion { my $self = shift; - return $self->{NAV_MAP}->hasDiscussion($self->symb()); + return $self->{NAV_MAP}->hasDiscussion($self->{SYMB}); } sub last_post_time { my $self = shift; - return $self->{NAV_MAP}->last_post_time($self->symb()); + return $self->{NAV_MAP}->last_post_time($self->{SYMB}); } sub discussion_info { my ($self,$filter) = @_; - return $self->{NAV_MAP}->discussion_info($self->symb(),$filter); + return $self->{NAV_MAP}->discussion_info($self->{SYMB},$filter); } sub getFeedback { my $self = shift; my $source = $self->src(); - my $symb = $self->symb(); + my $symb = $self->{SYMB}; if ($source =~ /^\/res\//) { $source = substr $source, 5; } return $self->{NAV_MAP}->getFeedback($symb,$source); } @@ -4686,7 +4720,7 @@ sub getFeedback { sub getErrors { my $self = shift; my $source = $self->src(); - my $symb = $self->symb(); + my $symb = $self->{SYMB}; if ($source =~ /^\/res\//) { $source = substr $source, 5; } return $self->{NAV_MAP}->getErrors($symb,$source); } @@ -4836,7 +4870,7 @@ sub extractParts { if ($partorder) { my @parts; for my $part (split (/,/,$partorder)) { - if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) { + if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) { push @parts, $part; $parts{$part} = 1; } @@ -4854,17 +4888,17 @@ sub extractParts { my $part = $1; # This floods the logs if it blows up if (defined($parts{$part})) { - &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->symb()); + &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->{SYMB}); } # check to see if part is turned off. - if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) { + if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) { $parts{$part} = 1; } } } - my @sortedParts = sort keys %parts; + my @sortedParts = sort(keys(%parts)); $self->{PARTS} = \@sortedParts; } @@ -4885,13 +4919,13 @@ sub extractParts { # So we have to use our knowlege of part names to figure out # where the part names begin and end, and even then, it is possible # to construct ambiguous situations. - foreach my $data (split /,/, $metadata) { + foreach my $data (split(/,/, $metadata)) { if ($data =~ /^([a-zA-Z]+)response_(.*)/ || $data =~ /^(Task)_(.*)/) { my $responseType = $1; my $partStuff = $2; my $partIdSoFar = ''; - my @partChunks = split /_/, $partStuff; + my @partChunks = split(/_/, $partStuff); my $i = 0; for ($i = 0; $i < scalar(@partChunks); $i++) { if ($partIdSoFar) { $partIdSoFar .= '_'; } @@ -5364,7 +5398,7 @@ sub status { sub check_for_slot { my $self = shift; my $part = shift; - my $symb = $self->symb(); + my $symb = $self->{SYMB}; my ($use_slots,$available,$availablestudent) = $self->slot_control($part); if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) { my @slots = (split(/:/,$availablestudent),split(/:/,$available)); @@ -5392,7 +5426,7 @@ sub check_for_slot { } else { if ($ip ne '') { if (!&Apache::loncommon::check_ip_acc($ip)) { - return (RESERVED_LOCATION,$ip,$slot_name); + return (RESERVED_LOCATION,$end,$slot_name); } } my @proctors; @@ -5438,18 +5472,61 @@ sub check_for_slot { my $reservable = &Apache::lonnet::get_reservable_slots($cnum,$cdom,$env{'user.name'}, $env{'user.domain'}); if (ref($reservable) eq 'HASH') { + my ($map) = &Apache::lonnet::decode_symb($symb); if ((ref($reservable->{'now_order'}) eq 'ARRAY') && (ref($reservable->{'now'}) eq 'HASH')) { foreach my $slot (reverse (@{$reservable->{'now_order'}})) { - if (($reservable->{'now'}{$slot}{'symb'} eq '') || - ($reservable->{'now'}{$slot}{'symb'} eq $symb)) { + my $canuse; + if ($reservable->{'now'}{$slot}{'symb'} eq '') { + $canuse = 1; + } else { + my %oksymbs; + my @slotsymbs = split(/\s*,\s*/,$reservable->{'now'}{$slot}{'symb'}); + map { $oksymbs{$_} = 1; } @slotsymbs; + if ($oksymbs{$symb}) { + $canuse = 1; + } else { + foreach my $item (@slotsymbs) { + if ($item =~ /\.(page|sequence)$/) { + (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item); + if (($map ne '') && ($map eq $sloturl)) { + $canuse = 1; + last; + } + } + } + } + } + if ($canuse) { return(RESERVABLE,$reservable->{'now'}{$slot}{'endreserve'}); } } } if ((ref($reservable->{'future_order'}) eq 'ARRAY') && (ref($reservable->{'future'}) eq 'HASH')) { foreach my $slot (@{$reservable->{'future_order'}}) { - if (($reservable->{'future'}{$slot}{'symb'} eq '') || - ($reservable->{'future'}{$slot}{'symb'} eq $symb)) { + my $canuse; + if ($reservable->{'future'}{$slot}{'symb'} eq '') { + $canuse = 1; + } elsif ($reservable->{'future'}{$slot}{'symb'} =~ /,/) { + my %oksymbs; + my @slotsymbs = split(/\s*,\s*/,$reservable->{'future'}{$slot}{'symb'}); + map { $oksymbs{$_} = 1; } @slotsymbs; + if ($oksymbs{$symb}) { + $canuse = 1; + } else { + foreach my $item (@slotsymbs) { + if ($item =~ /\.(page|sequence)$/) { + (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item); + if (($map ne '') && ($map eq $sloturl)) { + $canuse = 1; + last; + } + } + } + } + } elsif ($reservable->{'future'}{$slot}{'symb'} eq $symb) { + $canuse = 1; + } + if ($canuse) { return(RESERVABLE_LATER,$reservable->{'future'}{$slot}{'startreserve'}); } } @@ -5600,6 +5677,39 @@ sub completable { =pod +B + +The answerable method differs from the completable method in its handling of problem parts +for which feedback on correctness is suppressed, but the student still has tries left, and +the problem part is not past due, (i.e., the student could submit a different answer if +he/she so chose). For that case completable will return 0, whereas answerable will return 1. + +=cut + +sub answerable { + my $self = shift; + if (!$self->is_problem()) { return 0; } + my $partCount = $self->countParts(); + foreach my $part (@{$self->parts()}) { + if ($part eq '0' && $partCount != 1) { next; } + my $status = $self->status($part); + if ($self->getCompletionStatus($part) == ATTEMPTED() || + $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() || + $status == ANSWER_SUBMITTED() ) { + if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) { + return 1; + } + } + if ($status == OPEN() || $status == TRIES_LEFT() || $status == NETWORK_FAILURE()) { + return 1; + } + } + # None of the parts were answerable, so neither is this problem. + return 0; +} + +=pod + =head2 Resource/Nav Map Navigation =over 4 @@ -5635,7 +5745,7 @@ sub getPrevious { my $self = shift; my @branches; my $from = $self->from(); - foreach my $branch ( split /,/, $from) { + foreach my $branch ( split(/,/, $from)) { my $choice = $self->{NAV_MAP}->getById($branch); my $prev = $choice->comesfrom(); $prev = $self->{NAV_MAP}->getById($prev); @@ -5647,12 +5757,14 @@ sub getPrevious { sub browsePriv { my $self = shift; + my $noblockcheck = shift; if (defined($self->{BROWSE_PRIV})) { return $self->{BROWSE_PRIV}; } $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(), - $self->symb()); + $self->{SYMB},undef, + undef,$noblockcheck); } =pod