--- loncom/interface/lonnavmaps.pm 2017/07/10 13:01:39 1.532
+++ loncom/interface/lonnavmaps.pm 2017/12/18 23:13:53 1.537
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.532 2017/07/10 13:01:39 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.537 2017/12/18 23:13:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -501,7 +501,7 @@ use Apache::lonlocal;
use Apache::lonnet;
use Apache::lonmap;
-use POSIX qw (floor strftime);
+use POSIX qw (ceil floor strftime);
use Time::HiRes qw( gettimeofday tv_interval );
use LONCAPA;
use DateTime();
@@ -1007,9 +1007,12 @@ sub render_resource {
# Don't allow users to manipulate folder
$icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
$icon = "
"."
";
-
- $linkopen = "";
- $linkclose = "";
+ if ($params->{'caller'} eq 'sequence') {
+ $linkopen = "";
+ } else {
+ $linkopen = "";
+ $linkclose = "";
+ }
}
if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
(&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&
@@ -1143,7 +1146,7 @@ sub render_quick_status {
my $linkclose = "";
$result .= '
';
- if ($resource->is_problem() &&
+ if ($resource->is_gradable() &&
!$firstDisplayed) {
my $icon = $statusIconMap{$resource->simpleStatus($part)};
my $alt = $iconAltTags{$icon};
@@ -1168,7 +1171,7 @@ sub render_long_status {
my $color;
my $info = '';
- if ($resource->is_problem() || $resource->is_practice()) {
+ if ($resource->is_gradable() || $resource->is_practice()) {
$color = $colormap{$resource->status};
if (dueInLessThan24Hours($resource, $part)) {
@@ -1182,9 +1185,9 @@ sub render_long_status {
}
}
}
-
- if ($resource->kind() eq "res" &&
- $resource->is_raw_problem() &&
+
+ if (($resource->kind() eq "res") &&
+ ($resource->is_raw_problem() || $resource->is_gradable()) &&
!$firstDisplayed) {
if ($color) {$result .= ''; }
$result .= getDescription($resource, $part);
@@ -1231,7 +1234,7 @@ my @statuses = ($resObj->CORRECT, $resOb
sub render_parts_summary_status {
my ($resource, $part, $params) = @_;
- if (!$resource->is_problem() && !$resource->contains_problem) { return ' | | '; }
+ if (!$resource->is_gradable() && !$resource->contains_problem) { return ' | '; }
if ($params->{showParts}) {
return ' | ';
}
@@ -1372,10 +1375,11 @@ sub render {
my $currenturl = $env{'form.postdata'};
#$currenturl=~s/^http\:\/\///;
#$currenturl=~s/^[^\/]+//;
-
- $here = $jump = &Apache::lonnet::symbread($currenturl);
+ unless ($args->{'caller'} eq 'sequence') {
+ $here = $jump = &Apache::lonnet::symbread($currenturl);
+ }
}
- if ($here eq '') {
+ if (($here eq '') && ($args->{'caller'} ne 'sequence')) {
my $last;
if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
&GDBM_READER(),0640)) {
@@ -1866,9 +1870,13 @@ END
}
}
if (defined($anchor)) { $anchor='#'.$anchor; }
- $args->{"resourceLink"} = $src.
- ($srcHasQuestion?'&':'?') .
- 'symb=' . &escape($symb).$anchor;
+ if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) {
+ $args->{"resourceLink"} = $src.($srcHasQuestion?'&':'?') .'navmap=1';
+ } else {
+ $args->{"resourceLink"} = $src.
+ ($srcHasQuestion?'&':'?') .
+ 'symb=' . &escape($symb).$anchor;
+ }
}
# Now, we've decided what parts to show. Loop through them and
# show them.
@@ -2282,7 +2290,7 @@ sub generate_email_discuss_status {
foreach my $msgid (@keys) {
if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
- $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
+ $symb,$error) = &Apache::lonmsg::unpackmsgid(&LONCAPA::escape($msgid));
&Apache::lonenc::check_decrypt(\$symb);
if (($fromcid ne '') && ($fromcid ne $cid)) {
next;
@@ -2688,6 +2696,10 @@ sub parmval_real {
my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
$mapname = &Apache::lonnet::deversion($mapname);
+ my $toolsymb = '';
+ if ($fn =~ /ext\.tool$/) {
+ $toolsymb = $symb;
+ }
my ($recursed,@recurseup);
# ----------------------------------------------------- Cascading lookup scheme
@@ -2808,9 +2820,9 @@ sub parmval_real {
my $meta_rwhat=$rwhat;
$meta_rwhat=~s/\./_/g;
- my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
+ my $default=&Apache::lonnet::metadata($fn,$meta_rwhat,$toolsymb);
if (defined($default)) { return [$default,'resource']}
- $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
+ $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat,$toolsymb);
if (defined($default)) { return [$default,'resource']}
# --------------------------------------------------- fifth, check more course
if (defined($courseopt)) {
@@ -2852,7 +2864,7 @@ sub parmval_real {
if (defined($partgeneral[0])) { return \@partgeneral; }
}
if ($recurse) { return []; }
- my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat);
+ my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat,$toolsymb);
if (defined($pack_def)) { return [$pack_def,'resource']; }
return [''];
}
@@ -2873,6 +2885,91 @@ sub recurseup_maps {
return @recurseup;
}
+sub recursed_crumbs {
+ my ($self,$mapurl,$restitle) = @_;
+ my (@revmapinfo,@revmapres);
+ my $mapres = $self->getResourceByUrl($mapurl);
+ if (ref($mapres)) {
+ @revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs());
+ shift(@revmapres);
+ }
+ my $allowedlength = 60;
+ my $minlength = 5;
+ my $allowedtitle = 30;
+ if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) {
+ $allowedlength = 100;
+ $allowedtitle = 70;
+ }
+ if (length($restitle) > $allowedtitle) {
+ $restitle = &truncate_crumb_text($restitle,$allowedtitle);
+ }
+ my $totallength = length($restitle);
+ my @links;
+
+ foreach my $map (@revmapres) {
+ my $pc = $map->map_pc();
+ next if ((!$pc) || ($pc == 1));
+ push(@links,$map);
+ push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});
+ $totallength += length($map->title());
+ }
+ my $numlinks = scalar(@links);
+ if ($numlinks) {
+ if ($totallength - $allowedlength > 0) {
+ my $available = $allowedlength - length($restitle);
+ my $avg = POSIX::ceil($available/$numlinks);
+ if ($avg < $minlength) {
+ $avg = $minlength;
+ }
+ @revmapinfo = ();
+ foreach my $map (@links) {
+ my $showntitle = &truncate_crumb_text($map->title(),$avg);
+ if ($showntitle ne '') {
+ push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});
+ }
+ }
+ }
+ }
+ if ($restitle ne '') {
+ push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1});
+ }
+ return @revmapinfo;
+}
+
+sub truncate_crumb_text {
+ my ($title,$limit) = @_;
+ my $showntitle = '';
+ if (length($title) > $limit) {
+ my @words = split(/\b\s*/,$title);
+ if (@words == 1) {
+ $showntitle = substr($title,0,$limit).' ...';
+ } else {
+ my $linklength = 0;
+ my $num = 0;
+ foreach my $word (@words) {
+ $linklength += 1+length($word);
+ if ($word eq '-') {
+ $showntitle =~ s/ $//;
+ $showntitle .= $word;
+ } elsif ($linklength > $limit) {
+ if ($num < @words) {
+ $showntitle .= $word.' ...';
+ last;
+ } else {
+ $showntitle .= $word;
+ }
+ } else {
+ $showntitle .= $word.' ';
+ }
+ }
+ $showntitle =~ s/ $//;
+ }
+ return $showntitle;
+ } else {
+ return $title;
+ }
+}
+
#
# Determines the open/close dates for printing a map that
# encloses a resource.
@@ -4382,6 +4479,19 @@ sub is_problem {
}
return 0;
}
+sub is_tool {
+ my $self=shift;
+ my $src = $self->src();
+ return ($src =~ /ext\.tool$/);
+}
+sub is_gradable {
+ my $self=shift;
+ my $src = $self->src();
+ if (($src =~ /$LONCAPA::assess_re/) ||
+ (($self->is_tool()) && ($self->parmval('gradable',0) =~ /^yes$/i))) {
+ return !($self->is_practice());
+ }
+}
#
# The has below is the set of status that are considered 'incomplete'
#
@@ -4520,6 +4630,12 @@ Returns a string with a comma-separated
for the hierarchy of maps containing a map, with the top level
map first, then descending to deeper levels, with the enclosing map last.
+=item * B:
+
+Same as map_hierarchy, except maps containing only a single itemm if
+it's a map, or containing no items are omitted, unless it's the top
+level map (map_pc = 1), which is always included.
+
=back
=cut
@@ -4555,6 +4671,11 @@ sub map_hierarchy {
my $pc = $self->map_pc();
return $self->navHash("map_hierarchy_$pc", 0);
}
+sub map_breadcrumbs {
+ my $self = shift;
+ my $pc = $self->map_pc();
+ return $self->navHash("map_breadcrumbs_$pc", 0);
+}
#####
# Property queries
@@ -5032,6 +5153,8 @@ sub parts {
my $self = shift;
if ($self->ext) { return []; }
+ if (($self->is_tool()) &&
+ ($self->is_gradable())) { return ['0']; }
$self->extractParts();
return $self->{PARTS};
@@ -5406,6 +5529,14 @@ Attempted, and not yet graded.
Attempted, and credit received for attempt (survey and anonymous survey only).
+=item * B:
+
+Attempted, but wrong for LTI Tool Provider by passback of grade
+
+=item * B:
+
+Correct for LTI Tool Provider by passback of grade
+
=back
=cut
@@ -5418,6 +5549,8 @@ sub CORRECT_BY_OVERRIDE { return 14; }
sub EXCUSED { return 15; }
sub ATTEMPTED { return 16; }
sub CREDIT_ATTEMPTED { return 17; }
+sub INCORRECT_BY_PASSBACK { return 18; }
+sub CORRECT_BY_PASSBACK { return 19; }
sub getCompletionStatus {
my $self = shift;
@@ -5432,8 +5565,12 @@ sub getCompletionStatus {
if ($status eq 'correct_by_override') {
return $self->CORRECT_BY_OVERRIDE;
}
+ if ($status eq 'correct_by_passback') {
+ return $self->CORRECT_BY_PASSBACK;
+ }
if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
+ if ($status eq 'incorrect_by_passback') {return $self->INCORRECT_BY_PASSBACK; }
if ($status eq 'excused') {return $self->EXCUSED; }
if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
if ($status eq 'credit_attempted') {
@@ -5587,7 +5724,8 @@ sub status {
# There are a few whole rows we can dispose of:
if ($completionStatus == CORRECT ||
- $completionStatus == CORRECT_BY_OVERRIDE ) {
+ $completionStatus == CORRECT_BY_OVERRIDE ||
+ $completionStatus == CORRECT_BY_PASSBACK ) {
if ( $suppressFeedback ) { return ANSWER_SUBMITTED }
my $awarded=$self->awarded($part);
if ($awarded < 1 && $awarded > 0) {
@@ -5600,7 +5738,8 @@ sub status {
# If it's WRONG... and not open
if ( ($completionStatus == INCORRECT ||
- $completionStatus == INCORRECT_BY_OVERRIDE)
+ $completionStatus == INCORRECT_BY_OVERRIDE ||
+ $completionStatus == INCORRECT_BY_PASSBACK)
&& (!$self->opendate($part) || $self->opendate($part) > time()) ) {
return INCORRECT;
}
@@ -5642,7 +5781,8 @@ sub status {
}
# If it's WRONG...
- if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE) {
+ if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE ||
+ $completionStatus == INCORRECT_BY_PASSBACK) {
# and there are TRIES LEFT:
if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
return $suppressFeedback ? ANSWER_SUBMITTED : TRIES_LEFT;