--- loncom/interface/lonnavmaps.pm 2007/08/29 00:55:37 1.400 +++ loncom/interface/lonnavmaps.pm 2007/10/18 21:08:08 1.403 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.400 2007/08/29 00:55:37 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.403 2007/10/18 21:08:08 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,9 +36,9 @@ use Apache::lonenc(); use Apache::lonlocal; use Apache::lonnet; use POSIX qw (floor strftime); -use Data::Dumper; # for debugging, not always use Time::HiRes qw( gettimeofday tv_interval ); use LONCAPA; +use DateTime(); # symbolic constants sub SYMB { return 1; } @@ -170,7 +170,10 @@ sub getLinkForResource { if (defined($item)) { $res = $item; } } - return ($res->link(),$res->shown_symb()); + if ($res) { + return ($res->link(),$res->shown_symb()); + } + return; } # Convenience function: This separates the logic of how to create @@ -195,7 +198,11 @@ sub getDescription { } if ($status == $res->OPEN) { if ($res->duedate($part)) { - return &mt("Due")." " .timeToHumanString($res->duedate($part),'end'); + if ($res->is_practice()) { + return &mt("Closes ")." " .timeToHumanString($res->duedate($part),'start'); + } else { + return &mt("Due")." " .timeToHumanString($res->duedate($part),'end'); + } } else { return &mt("Open, no due date"); } @@ -204,7 +211,11 @@ sub getDescription { return &mt("Answer open")." " . timeToHumanString($res->answerdate($part),'start'); } if ($status == $res->PAST_DUE_NO_ANSWER) { - return &mt("Was due")." " . timeToHumanString($res->duedate($part),'end'); + if ($res->is_practice()) { + return &mt("Closed")." " . timeToHumanString($res->duedate($part),'start'); + } else { + return &mt("Was due")." " . timeToHumanString($res->duedate($part),'end'); + } } if (($status == $res->ANSWER_OPEN || $status == $res->PARTIALLY_CORRECT) && $res->handgrade($part) ne 'yes') { @@ -294,9 +305,6 @@ sub timeToHumanString { } my $now = time(); - my @time = localtime($time); - my @now = localtime($now); - # Positive = future my $delta = $time - $now; @@ -355,22 +363,25 @@ sub timeToHumanString { return "$prefix$hourString$minuteString$tense"; } + my $dt = DateTime->from_epoch(epoch => $time) + ->set_time_zone(&Apache::lonlocal::gettimezone()); + # If there's a caller supplied format, use it. - if($format ne '') { - my $timeStr = strftime($format, localtime($time)); - return $timeStr.&Apache::lonlocal::gettimezone($time); + if ($format ne '') { + my $timeStr = $dt->strftime($format); + return $timeStr.' ('.$dt->time_zone_short_name().')'; } # Less than 5 days away, display day of the week and # HH:MM if ( $delta < $day * 5 ) { - my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time)); + my $timeStr = $dt->strftime("%A, %b %e at %I:%M %P (%Z)"); $timeStr =~ s/12:00 am/00:00/; $timeStr =~ s/12:00 pm/noon/; return ($inPast ? "last " : "this ") . - $timeStr.&Apache::lonlocal::gettimezone($time); + $timeStr; } my $conjunction='on'; @@ -380,19 +391,22 @@ sub timeToHumanString { $conjunction='by'; } # Is it this year? - if ( $time[5] == $now[5]) { + my $dt_now = DateTime->from_epoch(epoch => $now) + ->set_time_zone(&Apache::lonlocal::gettimezone()); + if ( $dt->year() == $dt_now->year()) { # Return on Month Day, HH:MM meridian - my $timeStr = strftime("$conjunction %A, %b %e at %I:%M %P", localtime($time)); + my $timeStr = $dt->strftime("$conjunction %A, %b %e at %I:%M %P (%Z)"); $timeStr =~ s/12:00 am/00:00/; $timeStr =~ s/12:00 pm/noon/; - return $timeStr.&Apache::lonlocal::gettimezone($time); + return $timeStr; } # Not this year, so show the year - my $timeStr = strftime("$conjunction %A, %b %e %Y at %I:%M %P", localtime($time)); + my $timeStr = + $dt->strftime("$conjunction %A, %b %e %Y at %I:%M %P (%Z)"); $timeStr =~ s/12:00 am/00:00/; $timeStr =~ s/12:00 pm/noon/; - return $timeStr.&Apache::lonlocal::gettimezone($time); + return $timeStr; } } @@ -604,6 +618,11 @@ instruct the renderer to render only a p the source of the map you want to process, like '/res/103/jerf/navmap.course.sequence'. +=item * B: default: false + +If you need to include the top level map (meaning the course) in the +rendered output set this to true + =item * B: default: constructs one from %env A reference to a navmap, used only if an iterator is not passed in. If @@ -974,7 +993,7 @@ sub render_long_status { $params->{'multipart'} && $part eq "0"; my $color; - if ($resource->is_problem()) { + if ($resource->is_problem() || $resource->is_practice()) { $color = $colormap{$resource->status}; if (dueInLessThan24Hours($resource, $part) || @@ -984,13 +1003,13 @@ sub render_long_status { } if ($resource->kind() eq "res" && - $resource->is_problem() && + ($resource->is_problem() || $resource->is_practice()) && !$firstDisplayed) { if ($color) {$result .= ""; } $result .= getDescription($resource, $part); if ($color) {$result .= ""; } } - if ($resource->is_map() && advancedUser() && $resource->randompick()) { + if ($resource->is_map() && &advancedUser() && $resource->randompick()) { $result .= &mt('(randomly select [_1])', $resource->randompick()); } if ($resource->is_map() && &advancedUser() && $resource->randomorder()) { @@ -1029,7 +1048,6 @@ my %statusStrings = ); my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR); -use Data::Dumper; sub render_parts_summary_status { my ($resource, $part, $params) = @_; if (!$resource->is_problem() && !$resource->contains_problem) { return ''; } @@ -1236,7 +1254,7 @@ sub render { $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition); } else { - $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition); + $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'}); } } @@ -1273,7 +1291,6 @@ sub render { # Print key? if ($printKey) { $result .= ''; - my $date=localtime; $result.=''; my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc"); if ($navmap->{LAST_CHECK}) { @@ -2858,6 +2875,10 @@ sub next { $self->{HAVE_RETURNED_0} = 1; return $self->{NAV_MAP}->getById('0.0'); } + if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0_BEGIN_MAP}) { + $self->{HAVE_RETURNED_0_BEGIN_MAP} = 1; + return $self->BEGIN_MAP(); + } if ($self->{RECURSIVE_ITERATOR_FLAG}) { # grab the next from the recursive iterator @@ -3576,6 +3597,15 @@ sub contains_problem { } return 0; } +sub map_contains_problem { + my $self=shift; + if ($self->is_map()) { + my $has_problem= + $self->hasResource($self,sub { $_[0]->is_problem() },1); + return $has_problem; + } + return 0; +} sub is_sequence { my $self=shift; return $self->navHash("is_map_", 1) &&
Key: