--- loncom/interface/lonnavmaps.pm 2015/10/05 01:52:10 1.510
+++ loncom/interface/lonnavmaps.pm 2016/04/04 00:34:37 1.519
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.510 2015/10/05 01:52:10 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.519 2016/04/04 00:34:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -914,6 +914,9 @@ sub render_resource {
my $nonLinkedText = ''; # stuff after resource title not in link
my $link = $params->{"resourceLink"};
+ if ($resource->ext()) {
+ $link =~ s/\#.+(\?)/$1/g;
+ }
# The URL part is not escaped at this point, but the symb is...
@@ -1002,10 +1005,13 @@ sub render_resource {
'';
}
}
- }
-
- if ($resource->randomout()) {
- $nonLinkedText .= ' ('.&mt('hidden').') ';
+ if ($params->{'mapHidden'} || $resource->randomout()) {
+ $nonLinkedText .= ' ('.&mt('hidden').') ';
+ }
+ } else {
+ if ($resource->randomout()) {
+ $nonLinkedText .= ' ('.&mt('hidden').') ';
+ }
}
if (!$resource->condval()) {
$nonLinkedText .= ' ('.&mt('conditionally hidden').') ';
@@ -1580,41 +1586,45 @@ END
$args->{'indentString'} = setDefault($args->{'indentString'}, "");
$args->{'displayedHereMarker'} = 0;
- # If we're suppressing empty sequences, look for them here. Use DFS for speed,
- # since structure actually doesn't matter, except what map has what resources.
- if ($args->{'suppressEmptySequences'}) {
- my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
- $it->{FIRST_RESOURCE},
- $it->{FINISH_RESOURCE},
- {}, undef, 1);
- my $depth = 0;
- $dfsit->next();
- my $curRes = $dfsit->next();
- while ($depth > -1) {
- if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
- if ($curRes == $dfsit->END_MAP()) { $depth--; }
-
- if (ref($curRes)) {
- # Parallel pre-processing: Do sequences have non-filtered-out children?
- if ($curRes->is_map()) {
- $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
- # Sequences themselves do not count as visible children,
- # unless those sequences also have visible children.
- # This means if a sequence appears, there's a "promise"
- # that there's something under it if you open it, somewhere.
- } else {
- # Not a sequence: if it's filtered, ignore it, otherwise
- # rise up the stack and mark the sequences as having children
- if (&$filterFunc($curRes)) {
- for my $sequence (@{$dfsit->getStack()}) {
- $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
- }
+ # If we're suppressing empty sequences, look for them here.
+ # We also do this even if $args->{'suppressEmptySequences'}
+ # is not true, so we can hide empty sequences for which the
+ # hiddenresource parameter is set to yes (at map level), or
+ # mark as hidden for users who have $userCanSeeHidden.
+ # Use DFS for speed, since structure actually doesn't matter,
+ # except what map has what resources.
+
+ my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
+ $it->{FIRST_RESOURCE},
+ $it->{FINISH_RESOURCE},
+ {}, undef, 1);
+ my $depth = 0;
+ $dfsit->next();
+ my $curRes = $dfsit->next();
+ while ($depth > -1) {
+ if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
+ if ($curRes == $dfsit->END_MAP()) { $depth--; }
+
+ if (ref($curRes)) {
+ # Parallel pre-processing: Do sequences have non-filtered-out children?
+ if ($curRes->is_map()) {
+ $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
+ # Sequences themselves do not count as visible children,
+ # unless those sequences also have visible children.
+ # This means if a sequence appears, there's a "promise"
+ # that there's something under it if you open it, somewhere.
+ } elsif ($curRes->src()) {
+ # Not a sequence: if it's filtered, ignore it, otherwise
+ # rise up the stack and mark the sequences as having children
+ if (&$filterFunc($curRes)) {
+ for my $sequence (@{$dfsit->getStack()}) {
+ $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
}
}
}
- } continue {
- $curRes = $dfsit->next();
}
+ } continue {
+ $curRes = $dfsit->next();
}
my $displayedJumpMarker = 0;
@@ -1707,9 +1717,21 @@ END
}
# If this is an empty sequence and we're filtering them, continue on
- if ($curRes->is_map() && $args->{'suppressEmptySequences'} &&
- !$curRes->{DATA}->{HAS_VISIBLE_CHILDREN}) {
- next;
+ $args->{'mapHidden'} = 0;
+ if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {
+ if ($args->{'suppressEmptySequences'}) {
+ next;
+ } else {
+ my $mapname = &Apache::lonnet::declutter($curRes->src());
+ $mapname = &Apache::lonnet::deversion($mapname);
+ if (lc($navmap->get_mapparam(undef,$mapname,"0.hiddenresource")) eq 'yes') {
+ if ($userCanSeeHidden) {
+ $args->{'mapHidden'} = 1;
+ } else {
+ next;
+ }
+ }
+ }
}
# If we're suppressing navmaps and this is a navmap, continue on
@@ -2118,7 +2140,7 @@ sub change_user {
- # Now clear the parm cache and reconstruct the parm hash fromt he big_hash
+ # Now clear the parm cache and reconstruct the parm hash from the big_hash
# param.xxxx keys.
$self->{PARM_CACHE} = {};
@@ -2583,6 +2605,7 @@ sub parmval {
return $self->{PARM_CACHE}->{$hashkey};
}
}
+
my $result = $self->parmval_real($what, $symb, $recurse);
$self->{PARM_CACHE}->{$hashkey} = $result;
if (wantarray) {
@@ -2616,29 +2639,35 @@ sub parmval_real {
my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
$mapname = &Apache::lonnet::deversion($mapname);
+ my ($recursed,@recurseup);
+
# ----------------------------------------------------- Cascading lookup scheme
my $rwhat=$what;
$what=~s/^parameter\_//;
$what=~s/\_/\./;
my $symbparm=$symb.'.'.$what;
+ my $recurseparm=$mapname.'___(rec).'.$what;
my $mapparm=$mapname.'___(all).'.$what;
my $usercourseprefix=$cid;
-
+
my $grplevel=$usercourseprefix.'.['.$cgroup.'].'.$what;
my $grplevelr=$usercourseprefix.'.['.$cgroup.'].'.$symbparm;
+ my $grpleveli=$usercourseprefix.'.['.$cgroup.'].'.$recurseparm;
my $grplevelm=$usercourseprefix.'.['.$cgroup.'].'.$mapparm;
my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
+ my $secleveli=$usercourseprefix.'.['.$csec.'].'.$recurseparm;
my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
my $courselevel= $usercourseprefix.'.'.$what;
my $courselevelr=$usercourseprefix.'.'.$symbparm;
+ my $courseleveli=$usercourseprefix.'.'.$recurseparm;
my $courselevelm=$usercourseprefix.'.'.$mapparm;
@@ -2650,6 +2679,17 @@ sub parmval_real {
if ($uname and defined($useropt)) {
if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; }
if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; }
+ if (defined($$useropt{$courseleveli})) { return [$$useropt{$courseleveli},'map']; }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
+ last if (defined($$useropt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
+ if (defined($$useropt{$recursechk})) { return [$$useropt{$recursechk},'map']; }
+ }
if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; }
}
@@ -2657,12 +2697,34 @@ sub parmval_real {
if ($cgroup ne '' and defined($courseopt)) {
if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; }
if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; }
+ if (defined($$courseopt{$grpleveli})) { return [$$courseopt{$grpleveli},'map']; }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }
+ }
if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; }
}
- if ($csec and defined($courseopt)) {
+ if ($csec ne '' and defined($courseopt)) {
if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; }
if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; }
+ if (defined($$courseopt{$secleveli})) { return [$$courseopt{$secleveli},'map']; }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }
+ }
if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; }
}
@@ -2686,6 +2748,19 @@ sub parmval_real {
# --------------------------------------------------- fifth, check more course
if (defined($courseopt)) {
if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; }
+ if (defined($$courseopt{$courseleveli})) { return [$$courseopt{$courseleveli},'map']; }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) {
+ return [$$courseopt{$recursechk},'map'];
+ }
+ }
if (defined($$courseopt{$courselevel})) {
my $ret = [$$courseopt{$courselevel},'course'];
return $ret;
@@ -2708,6 +2783,24 @@ sub parmval_real {
if (defined($pack_def)) { return [$pack_def,'resource']; }
return [''];
}
+
+sub recurseup_maps {
+ my ($self,$mapname) = @_;
+ my @recurseup;
+ if ($mapname) {
+ my $res = $self->getResourceByUrl($mapname);
+ if (ref($res)) {
+ my @pcs = split(/,/,$res->map_hierarchy());
+ shift(@pcs);
+ pop(@pcs);
+ if (@pcs) {
+ @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs);
+ }
+ }
+ }
+ return @recurseup;
+}
+
#
# Determines the open/close dates for printing a map that
# encloses a resource.
@@ -2719,15 +2812,15 @@ sub map_printdates {
- my $opendate = $self->get_mapparam($res->symb(), "$part.printstartdate");
- my $closedate= $self->get_mapparam($res->symb(), "$part.printenddate");
+ my $opendate = $self->get_mapparam($res->symb(),'',"$part.printstartdate");
+ my $closedate= $self->get_mapparam($res->symb(),'',"$part.printenddate");
return ($opendate, $closedate);
}
sub get_mapparam {
- my ($self, $symb, $what) = @_;
+ my ($self, $symb, $mapname, $what) = @_;
# Ensure the course option hash is populated:
@@ -2746,14 +2839,18 @@ sub get_mapparam {
my $uname=$self->{USERNAME};
my $udom=$self->{DOMAIN};
- unless ($symb) { return ['']; }
+ unless ($symb || $mapname) { return; }
my $result='';
+ my ($recursed,@recurseup);
# Figure out which map we are in.
- my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
- $mapname = &Apache::lonnet::deversion($mapname);
+ if ($symb && !$mapname) {
+ my ($id,$fn);
+ ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
+ $mapname = &Apache::lonnet::deversion($mapname);
+ }
my $rwhat=$what;
@@ -2762,15 +2859,18 @@ sub get_mapparam {
# Build the hash keys for the lookup:
- my $symbparm=$symb.'.'.$what;
my $mapparm=$mapname.'___(all).'.$what;
+ my $recurseparm=$mapname.'___(rec).'.$what;
my $usercourseprefix=$cid;
- my $grplevel = "$usercourseprefix.[$cgroup].$mapparm";
- my $seclevel = "$usercourseprefix.[$csec].$mapparm";
- my $courselevel = "$usercourseprefix.$mapparm";
-
+ my $grplevelm = "$usercourseprefix.[$cgroup].$mapparm";
+ my $seclevelm = "$usercourseprefix.[$csec].$mapparm";
+ my $courselevelm = "$usercourseprefix.$mapparm";
+
+ my $grpleveli = "$usercourseprefix.[$cgroup].$recurseparm";
+ my $secleveli = "$usercourseprefix.[$csec].$recurseparm";
+ my $courseleveli = "$usercourseprefix.$recurseparm";
# Get handy references to the hashes we need in $self:
@@ -2783,9 +2883,24 @@ sub get_mapparam {
if ($uname and defined($useropt)) {
- if (defined($$useropt{$courselevel})) {
- return $$useropt{$courselevel};
+ if (defined($$useropt{$courselevelm})) {
+ return $$useropt{$courselevelm};
}
+ if (defined($$useropt{$courseleveli})) {
+ return $$useropt{$courseleveli};
+ }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
+ last if (defined($$useropt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
+ if (defined($$useropt{$recursechk})) {
+ return $$useropt{$recursechk};
+ }
+ }
}
# Check course -- group
@@ -2793,38 +2908,82 @@ sub get_mapparam {
if ($cgroup ne '' and defined ($courseopt)) {
- if (defined($$courseopt{$grplevel})) {
- return $$courseopt{$grplevel};
+ if (defined($$courseopt{$grplevelm})) {
+ return $$courseopt{$grplevelm};
}
+ if (defined($$courseopt{$grpleveli})) {
+ return $$courseopt{$grpleveli};
+ }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) {
+ return $$courseopt{$recursechk};
+ }
+ }
}
# Check course -- section
-
-
-
- if ($csec and defined($courseopt)) {
- if (defined($$courseopt{$seclevel})) {
- return $$courseopt{$seclevel};
+ if ($csec ne '' and defined($courseopt)) {
+ if (defined($$courseopt{$seclevelm})) {
+ return $$courseopt{$seclevelm};
}
+ if (defined($$courseopt{$secleveli})) {
+ return $$courseopt{$secleveli};
+ }
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) {
+ return $$courseopt{$recursechk};
+ }
+ }
}
# Check the map parameters themselves:
- my $thisparm = $$parmhash{$symbparm};
- if (defined($thisparm)) {
- return $thisparm;
+ if ($symb) {
+ my $symbparm=$symb.'.'.$what;
+ my $thisparm = $$parmhash{$symbparm};
+ if (defined($thisparm)) {
+ return $thisparm;
+ }
}
# Additional course parameters:
if (defined($courseopt)) {
- if (defined($$courseopt{$courselevel})) {
- return $$courseopt{$courselevel};
+ if (defined($$courseopt{$courselevelm})) {
+ return $$courseopt{$courselevelm};
}
+ unless ($recursed) {
+ @recurseup = $self->recurseup_maps($mapname);
+ $recursed = 1;
+ }
+ if (@recurseup) {
+ foreach my $item (@recurseup) {
+ my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
+ last if (defined($$courseopt{$norecursechk}));
+ my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
+ if (defined($$courseopt{$recursechk})) {
+ return $$courseopt{$recursechk};
+ }
+ }
+ }
}
- return undef; # Unefined if we got here.
+ return undef; # Undefined if we got here.
}
sub course_printdates {
@@ -2866,10 +3025,6 @@ sub getcourseparam {
$what=~s/^parameter\_//;
$what=~s/\_/\./;
-
- my $symbparm = $symb . '.' . $what;
- my $mapparm=$mapname.'___(all).'.$what;
-
# Local refs to the hashes we're going to look at:
my $useropt = $self->{USER_OPT};
@@ -2878,7 +3033,7 @@ sub getcourseparam {
#
# We want the course level stuff from the way
# parmval_real operates
- # TODO: Fator some of this stuff out of
+ # TODO: Factor some of this stuff out of
# both parmval_real and here
#
my $courselevel = $cid . '.' . $what;
@@ -2895,7 +3050,7 @@ sub getcourseparam {
}
# Try for the group's course level option:
- if ($uname ne '' and defined($courseopt)) {
+ if ($cgroup ne '' and defined($courseopt)) {
if (defined($$courseopt{$grplevel})) {
return $$courseopt{$grplevel};
}
@@ -2903,12 +3058,12 @@ sub getcourseparam {
# Try for section level parameters:
- if ($csec and defined($courseopt)) {
+ if ($csec ne '' and defined($courseopt)) {
if (defined($$courseopt{$seclevel})) {
return $$courseopt{$seclevel};
}
}
- # Try for 'additional' course parameterse:
+ # Try for 'additional' course parameters:
if (defined($courseopt)) {
if (defined($$courseopt{$courselevel})) {
@@ -3872,7 +4027,7 @@ sub new {
# This is a speed optimization, to avoid calling symb() too often.
$self->{SYMB} = $self->symb();
-
+
return $self;
}
@@ -4529,7 +4684,7 @@ sub duedate {
my $due_date=$self->parmval("duedate", $part);
if ($interval[0] =~ /\d+/) {
my $first_access=&Apache::lonnet::get_first_access($interval[1],
- $self->symb);
+ $self->{SYMB});
if (defined($first_access)) {
my $interval = $first_access+$interval[0];
$date = (!$due_date || $interval < $due_date) ? $interval
@@ -4611,7 +4766,7 @@ sub part_display {
my $self= shift(); my $partID = shift();
if (! defined($partID)) { $partID = '0'; }
my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
- $self->symb);
+ $self->{SYMB});
if (! defined($display) || $display eq '') {
$display = $partID;
}
@@ -5414,7 +5569,6 @@ sub check_for_slot {
}
my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
my ($checkedin,$checkedinslot);
- my ($map) = &Apache::lonnet::decode_symb($symb);
foreach my $slot_name (@sorted_slots) {
next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name}));
my $end = $slots{$slot_name}->{'endtime'};
@@ -5473,6 +5627,7 @@ 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'}})) {
my $canuse;