[LON-CAPA-cvs] cvs: loncom /interface slotrequest.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 30 Mar 2006 04:34:33 -0000
albertel Wed Mar 29 23:34:33 2006 EDT
Modified files:
/loncom/interface slotrequest.pm
Log:
- filter which slots to show based on name
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.53 loncom/interface/slotrequest.pm:1.54
--- loncom/interface/slotrequest.pm:1.53 Tue Mar 21 11:03:19 2006
+++ loncom/interface/slotrequest.pm Wed Mar 29 23:34:32 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for requesting to have slots added to a students record
#
-# $Id: slotrequest.pm,v 1.53 2006/03/21 16:03:19 albertel Exp $
+# $Id: slotrequest.pm,v 1.54 2006/03/30 04:34:32 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -678,12 +678,27 @@
}
sub to_show {
- my ($slot,$when,$deleted) = @_;
+ my ($slotname,$slot,$when,$deleted,$name) = @_;
my $time=time;
my $week=60*60*24*7;
+
if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
return 0;
}
+
+ if ($name && $name->{'value'} =~ /\w/) {
+ if ($name->{'type'} eq 'substring') {
+ if ($slotname !~ /\Q$name->{'value'}\E/) {
+ return 0;
+ }
+ }
+ if ($name->{'type'} eq 'exact') {
+ if ($slotname eq $name->{'value'}) {
+ return 0;
+ }
+ }
+ }
+
if ($when eq 'any') {
return 1;
} elsif ($when eq 'now') {
@@ -764,10 +779,12 @@
$r->print('</div>');
}
- my %Saveable_Parameters = ('show' => 'array',
- 'when' => 'scalar',
- 'order' => 'scalar',
- 'deleted' => 'scalar',
+ my %Saveable_Parameters = ('show' => 'array',
+ 'when' => 'scalar',
+ 'order' => 'scalar',
+ 'deleted' => 'scalar',
+ 'name_filter_type' => 'scalar',
+ 'name_filter_value' => 'scalar',
);
&Apache::loncommon::store_course_settings('slotrequest',
\%Saveable_Parameters);
@@ -777,6 +794,7 @@
my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
&Apache::grades::reset_perm();
+ # what to display filtering
my %show_fields=&Apache::lonlocal::texthash(
'name' => 'Slot Name',
'description' => 'Description',
@@ -802,6 +820,7 @@
: keys(%show_fields);
my %show = map { $_ => 1 } (@show);
+ #when filtering setup
my %when_fields=&Apache::lonlocal::texthash(
'now' => 'Open now',
'nextweek' => 'Open within the next week',
@@ -815,6 +834,7 @@
my $when = (exists($env{'form.when'})) ? $env{'form.when'}
: 'now';
+ #display of students setup
my %stu_display_fields=
&Apache::lonlocal::texthash('username' => 'User name',
'fullname' => 'Full name',
@@ -825,6 +845,22 @@
: keys(%stu_display_fields);
my %stu_display = map { $_ => 1 } (@stu_display);
+ #name filtering setup
+ my %name_filter_type_fields=
+ &Apache::lonlocal::texthash('substring' => 'Substring',
+ 'exact' => 'Exact',
+ #'reg' => 'Regular Expression',
+ );
+ my @name_filter_type_order=('substring','exact');
+
+ $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
+ my $name_filter_type =
+ (exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
+ : 'substring';
+ my $name_filter = {'type' => $name_filter_type,
+ 'value' => $env{'form.name_filter_value'},};
+
+ #deleted slot filtering
my $hide_radio =
&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
my $show_radio =
@@ -837,6 +873,7 @@
<tr><th>'.&mt('Show').'</th>
<th>'.&mt('Student Display').'</th>
<th>'.&mt('Open').'</th>
+ <th>'.&mt('Slot Name Filter').'</th>
<th>'.&mt('Options').'</th>
</tr>
<tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
@@ -848,6 +885,14 @@
</td>
<td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
'</td>
+ <td>'.&Apache::loncommon::select_form($name_filter_type,
+ 'name_filter_type',
+ %name_filter_type_fields).
+ '<br />'.
+ &Apache::lonhtmlcommon::textbox('name_filter_value',
+ $env{'form.name_filter_value'},
+ 15).
+ '</td>
<td>
<table>
<tr>
@@ -901,7 +946,8 @@
return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
};
foreach my $slot (sort $slotsort (keys(%slots))) {
- if (!&to_show($slots{$slot},$when,$env{'form.deleted'})) { next; }
+ if (!&to_show($slot,$slots{$slot},$when,
+ $env{'form.deleted'},$name_filter)) { next; }
if (defined($slots{$slot}->{'type'})
&& $slots{$slot}->{'type'} ne 'schedulable_student') {
#next;
@@ -913,7 +959,9 @@
"^$slot\0");
my ($tmp)=%consumed;
if ($tmp !~ /^error: /) {
- foreach my $entry (sort(keys(%consumed))) {
+ foreach my $entry (sort { $consumed{$a}{name} cmp
+ $consumed{$b}{name} }
+ (keys(%consumed))) {
my (undef,$id)=split("\0",$entry);
my ($uname,$udom) = split('@',$consumed{$entry}{'name'});
$ids.= '<nobr>';