[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
raeburn
raeburn at source.lon-capa.org
Sat Jul 15 11:43:38 EDT 2017
raeburn Sat Jul 15 15:43:38 2017 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
- Bugs 4373 and 6131
- Text in "Parameter in effect" cell in table mode includes "recursive"
if the parameter in effect is recursive for a map/folder.
- A link to display/set the parameter is included if that item is not the
enclosing map/folder.
-------------- next part --------------
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.581 loncom/interface/lonparmset.pm:1.582
--- loncom/interface/lonparmset.pm:1.581 Sat Jul 15 04:58:17 2017
+++ loncom/interface/lonparmset.pm Sat Jul 15 15:43:38 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.581 2017/07/15 04:58:17 raeburn Exp $
+# $Id: lonparmset.pm,v 1.582 2017/07/15 15:43:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1426,14 +1426,19 @@
# @param {string} $cgroup - group name
# @param {array reference} $usersgroups - list of groups the user belongs to, if any
# @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
-# @param {boolean} $readonly - true if no editing allowed.
+# @param {boolean} $readonly - true if no editing allowed.
+# @param {array reference} - $recurseup - list of maps containing current one, ending at top-level.
+# @param {hash reference} - $maptitles - - hash map id or src -> map title
+# @param {hash reference} - $allmaps_inverted - hash map src -> map pc
+# @param {scalar reference} - $reclinks - number of "parameter in effect" cells with link to map where recursive param was set
sub print_row {
my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
$defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp,
- $readonly)=@_;
+ $readonly,$recurseup,$maptitles,$allmaps_inverted,$reclinks)=@_;
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
+ my $numlinks = 0;
# get the values for the parameter in cascading order
# empty levels will remain empty
@@ -1470,9 +1475,64 @@
my $thismarker=$which;
$thismarker=~s/^parameter\_//;
my $mprefix=$rid.'&'.$thismarker.'&';
- my $effective_parm = &valout($outpar[$result],$typeoutpar[$result],$thismarker);
- my ($othergrp,$grp_parm,$controlgrp,$effparm_rec);
- if ($result == 17 || $result == 11 || $result == 7 || $result == 3) {
+ my ($parmname)=($thismarker=~/\_([^\_]+)$/);
+ my ($othergrp,$grp_parm,$controlgrp,$effective_parm,$effparm_rec,$effparm_level,
+ $eff_groupparm,$recurse_check,$recursinfo);
+ if ((ref($recurseup) eq 'ARRAY') && (@{$recurseup} > 0)) {
+ if ($result eq '') {
+ $recurse_check = 1;
+ } elsif (($uname ne '') && ($result > 3)) {
+ $recurse_check = 1;
+ } elsif (($cgroup ne '') && ($result > 7)) {
+ $recurse_check = 1;
+ } elsif (($csec ne '') && ($result > 11)) {
+ $recurse_check = 1;
+ } elsif ($result > 17) {
+ $recurse_check = 1;
+ }
+ if ($recurse_check) {
+ my $what = $$part{$which}.'.'.$$name{$which};
+ my $prefix;
+ if (($uname ne '') && ($udom ne '')) {
+ my $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
+ $prefix = $env{'request.course.id'};
+ $recursinfo = &get_recursive($recurseup,$useropt,$what,$prefix);
+ if (ref($recursinfo) eq 'ARRAY') {
+ $effparm_rec = 1;
+ $effparm_level = &mt('user: [_1]',$uname);
+ }
+ }
+ if (($cgroup ne '') && (!$effparm_rec)) {
+ $prefix = $env{'request.course.id'}.'.['.$cgroup.']';
+ $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
+ if (ref($recursinfo) eq 'ARRAY') {
+ $effparm_rec = 1;
+ $effparm_level = &mt('group: [_1]',$cgroup);
+ }
+ }
+ if (($csec ne '') && (!$effparm_rec)) {
+ $prefix = $env{'request.course.id'}.'.['.$csec.']';
+ $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
+ if (ref($recursinfo) eq 'ARRAY') {
+ $effparm_rec = 1;
+ $effparm_level = &mt('section: [_1]',$csec);
+ }
+ }
+ if (!$effparm_rec) {
+ $prefix = $env{'request.course.id'};
+ $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
+ if (ref($recursinfo) eq 'ARRAY') {
+ $effparm_rec = 1;
+ }
+ }
+ }
+ }
+ if ((!$effparm_rec) && ($result == 17 || $result == 11 || $result == 7 || $result == 3)) {
+ $effparm_rec = 1;
+ }
+ if ((!$effparm_rec) &&
+ (($$name{$which} eq 'encrypturl') || ($$name{$which} eq 'hiddenresource')) &&
+ ($result == 16 || $result == 10 || $result == 6 || $result == 2)) {
$effparm_rec = 1;
}
if ($parmlev eq 'general') {
@@ -1498,15 +1558,18 @@
} else {
if ($uname) {
if (@{$usersgroups} > 1) {
- my ($coursereply,$grp_parm,$controlgrp);
- ($coursereply,$othergrp,$grp_parm,$controlgrp) =
+ (my $coursereply,$othergrp,$grp_parm,$controlgrp,my $grp_is_rec) =
&check_other_groups($$part{$which}.'.'.$$name{$which},
$rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
- if ($coursereply && $result > 4) {
+ if (($coursereply) && ($result > 4)) {
if (defined($controlgrp)) {
if ($cgroup ne $controlgrp) {
- $effective_parm = $grp_parm;
- $result = 0;
+ $eff_groupparm = $grp_parm;
+ undef($result);
+ undef($effparm_rec);
+ if ($grp_is_rec) {
+ $effparm_rec = 1;
+ }
}
}
}
@@ -1539,12 +1602,35 @@
&print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1);
&print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly);
}
-
} # end of $parmlev if/else
- $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
- ($effparm_rec?'<br /><span class="LC_parm_recursive">'.&mt('recursive').
- '</span>':'').'</td>');
-
+ if (ref($recursinfo) eq 'ARRAY') {
+ my $rectitle = &mt('recursive');
+ if ((ref($maptitles) eq 'HASH') && (exists($maptitles->{$recursinfo->[2]}))) {
+ if ((ref($allmaps_inverted) eq 'HASH') && (exists($allmaps_inverted->{$recursinfo->[2]}))) {
+ $rectitle = &mt('set in: [_1]','"'.
+ '<a href="javascript:pjumprec('."'".$allmaps_inverted->{$recursinfo->[2]}."',".
+ "'$parmname','$$part{$which}'".');">'.
+ $maptitles->{$recursinfo->[2]}.'</a>"');
+
+ $numlinks ++;
+ }
+ }
+ my ($parmname)=($thismarker=~/\_([^\_]+)$/);
+ $effective_parm = &valout($recursinfo->[0],$recursinfo->[1],$parmname);
+ $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
+ '<br /><span class="LC_parm_recursive">'.$rectitle.' '.
+ $effparm_level.'</span></td>');
+ } else {
+ if ($result) {
+ $effective_parm = &valout($outpar[$result],$typeoutpar[$result],$parmname);
+ }
+ if ($eff_groupparm) {
+ $effective_parm = $eff_groupparm;
+ }
+ $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
+ ($effparm_rec?'<br /><span class="LC_parm_recursive">'.&mt('recursive').
+ '</span>':'').'</td>');
+ }
if ($parmlev eq 'full') {
my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
'.'.$$name{$which},$$symbp{$rid});
@@ -1558,6 +1644,9 @@
}
$r->print('</tr>');
$r->print("\n");
+ if (($numlinks) && (ref($reclinks))) {
+ $$reclinks = $numlinks;
+ }
}
# Prints a cell for table mode.
@@ -1649,7 +1738,7 @@
# @param {array reference} $usersgroups - list of groups the user belongs to, if any
# @param {integer} $result - level
# @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
-# @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group)
+# @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group, true if recursive)
sub check_other_groups {
my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
my $courseid = $env{'request.course.id'};
@@ -1663,15 +1752,22 @@
&parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,
$recurseparm,$what,$courseopt);
my $bgcolor = $defbg;
- my $grp_parm;
+ my ($grp_parm,$grp_is_rec);
if (($coursereply) && ($cgroup ne $resultgroup)) {
+ my ($parmname) = ($what =~ /\.([^.]+)$/);
if ($result > 3) {
$bgcolor = '#AAFFAA';
}
- $grp_parm = &valout($coursereply,$resulttype,$what);
+ $grp_parm = &valout($coursereply,$resulttype,$parmname);
$output = '<td style="background-color:'.$bgcolor.';" align="center">';
if ($resultgroup && $resultlevel) {
- $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm;
+ if ($resultlevel eq 'recursive') {
+ $resultlevel = 'map/folder';
+ $grp_is_rec = 1;
+ }
+ $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm.
+ ($grp_is_rec?'<span class="LC_parm_recursive">'.&mt('recursive').'</span>':'');
+
} else {
$output .= ' ';
}
@@ -1679,7 +1775,7 @@
} else {
$output .= '<td style="background-color:'.$bgcolor.';"> </td>';
}
- return ($coursereply,$output,$grp_parm,$resultgroup);
+ return ($coursereply,$output,$grp_parm,$resultgroup,$grp_is_rec);
}
# Looks for a group with a defined parameter for given user and parameter.
@@ -1833,6 +1929,29 @@
}
}
+sub get_recursive {
+ my ($recurseup,$resdata,$what,$prefix) = @_;
+ if ((ref($resdata) eq 'HASH') && (ref($recurseup) eq 'ARRAY')) {
+ foreach my $item (@{$recurseup}) {
+ my $norecursechk=$prefix.'.'.$item.'___(all).'.$what;
+ if (defined($resdata->{$norecursechk})) {
+ if ($what =~ /\.(encrypturl|hiddenresource)$/) {
+ my $type = $resdata->{$norecursechk.'.type'};
+ return [$resdata->{$norecursechk},$type,$item];
+ } else {
+ last;
+ }
+ }
+ my $recursechk=$prefix.'.'.$item.'___(rec).'.$what;
+ if (defined($resdata->{$recursechk})) {
+ my $type = $resdata->{$recursechk.'.type'};
+ return [$resdata->{$recursechk},$type,$item];
+ }
+ }
+ }
+ return;
+}
+
# Tells if a parameter type is a date.
#
@@ -2708,6 +2827,7 @@
my %uris=(); # hash resource/map id -> resource src
my %maptitles=(); # hash map pc or src -> map title
my %allmaps=(); # hash map pc -> map src
+ my %allmaps_inverted=(); # hash map src -> map pc
my %alllevs=(); # hash English level title -> value
my $uname; # selected user name
@@ -2716,6 +2836,7 @@
my $csec; # selected section name
my $cgroup; # selected group name
my @usersgroups = (); # list of the user groups
+ my $numreclinks = 0;
my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
@@ -2863,6 +2984,8 @@
\%mapp, \%symbp,\%maptitles,\%uris,
\%keyorder);
+ %allmaps_inverted = reverse(%allmaps);
+
$mapp{'0.0'} = '';
$symbp{'0.0'} = '';
@@ -3252,7 +3375,6 @@
foreach my $rid (@ids) {
my ($inmapid)=($rid=~/\.(\d+)$/);
-
if ((!$pssymb &&
(($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
||
@@ -3315,6 +3437,11 @@
if ($totalparms>0) {
my $firstrow=1;
my $title=&Apache::lonnet::gettitle($symbp{$rid});
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my @recurseup;
+ if (ref($navmap) && $mapp{$rid}) {
+ @recurseup = $navmap->recurseup_maps($mapp{$rid});
+ }
$r->print('<tr><td style="background-color:'.$defbgone.';"'.
' rowspan='.$totalparms.
'><tt><font size="-1">'.
@@ -3346,7 +3473,9 @@
&print_row($r,$item,\%part,\%name,\%symbp,$rid,\%default,
\%type,\%display,$defbgone,$defbgtwo,
$defbgthree,$parmlev,$uname,$udom,$csec,
- $cgroup,\@usersgroups,$noeditgrp,$readonly);
+ $cgroup,\@usersgroups,$noeditgrp,$readonly,
+ \@recurseup,\%maptitles,\%allmaps_inverted,
+ \$numreclinks);
}
}
}
@@ -3392,6 +3521,7 @@
if ($map eq $mapid) {
my $uri=&Apache::lonnet::declutter($uris{$rid});
+
# $r->print("Keys: $keyp{$rid} <br />\n");
#--------------------------------------------------------------------
@@ -3464,12 +3594,23 @@
.&Apache::loncommon::end_data_table_header_row()
);
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my @recurseup;
+ if (ref($navmap)) {
+ my $mapres = $navmap->getByMapPc($mapid);
+ if (ref($mapres)) {
+ @recurseup = $navmap->recurseup_maps($mapres->src());
+ }
+ }
+
+
foreach my $item (&keysinorder(\%name,\%keyorder)) {
$r->print(&Apache::loncommon::start_data_table_row());
&print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
\%type,\%display,$defbgone,$defbgtwo,$defbgthree,
$parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
- $readonly);
+ $readonly,\@recurseup,\%maptitles,\%allmaps_inverted,
+ \$numreclinks);
}
$r->print(&Apache::loncommon::end_data_table().'</p>'
.'</div>'
@@ -3569,6 +3710,25 @@
} # end of $parmlev eq general
}
$r->print('</form>');
+ if ($numreclinks) {
+ $r->print(<<"END");
+<form name="recurseform" action="/adm/parmset?action=settable" method="post">
+<input type="hidden" name="pschp" />
+<input type="hidden" name="pscat" />
+<input type="hidden" name="psprt" />
+<input type="hidden" name="hideparmsel" value="hidden" />
+</form>
+<script type="text/javascript">
+function pjumprec(rid,name,part) {
+ document.forms.recurseform.pschp.value = rid;
+ document.forms.recurseform.pscat.value = name;
+ document.forms.recurseform.psprt.value = part;
+ document.forms.recurseform.submit();
+ return false;
+}
+</script>
+END
+ }
&endSettingsScreen($r);
$r->print(&Apache::loncommon::end_page());
} # end sub assessparms
More information about the LON-CAPA-cvs
mailing list