[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Thu, 19 Jun 2003 19:28:52 -0000
bowersj2 Thu Jun 19 15:28:52 2003 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
"student" option now allows a parameter that allows you to select
course personnel as well, but this will have a problem with multiple
roles for the same person. Still, this is an improvement, if not a final
fix...
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.38 loncom/interface/lonhelper.pm:1.39
--- loncom/interface/lonhelper.pm:1.38 Tue Jun 17 10:21:22 2003
+++ loncom/interface/lonhelper.pm Thu Jun 19 15:28:52 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.38 2003/06/17 14:21:22 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.39 2003/06/19 19:28:52 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1775,9 +1775,10 @@
Student elements display a choice of students enrolled in the current
course. Currently it is primitive; this is expected to evolve later.
-Student elements take two attributes: "variable", which means what
-it usually does, and "multichoice", which if true allows the user
-to select multiple students.
+Student elements take three attributes: "variable", which means what
+it usually does, "multichoice", which if true allows the user
+to select multiple students, and "coursepersonnel" which if true
+adds the course personnel to the top of the student selection.
=cut
@@ -1807,6 +1808,7 @@
$paramHash->{'variable'} = $token->[2]{'variable'};
$helper->declareVar($paramHash->{'variable'});
$paramHash->{'multichoice'} = $token->[2]{'multichoice'};
+ $paramHash->{'coursepersonnel'} = $token->[2]{'coursepersonnel'};
if (defined($token->[2]{'nextstate'})) {
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};
}
@@ -1853,30 +1855,60 @@
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
}
- # Load up the students
- my $choices = &Apache::loncoursedata::get_classlist();
- my @keys = keys %{$choices};
+ my $choices = [];
+
+ # Load up the non-students, if necessary
+ if ($self->{'coursepersonnel'}) {
+ my %coursepersonnel = Apache::lonnet::get_course_adv_roles();
+ for (sort keys %coursepersonnel) {
+ for my $role (split /,/, $coursepersonnel{$_}) {
+ # extract the names so we can sort them
+ my @people;
+
+ for (split /,/, $role) {
+ push @people, [split /:/, $role];
+ }
+
+ @people = sort { $a->[0] cmp $b->[0] } @people;
+
+ for my $person (@people) {
+ push @$choices, [join(':', @$person), $person->[0], '', $_];
+ }
+ }
+ }
+ }
# Constants
my $section = Apache::loncoursedata::CL_SECTION();
my $fullname = Apache::loncoursedata::CL_FULLNAME();
+ # Load up the students
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ my @keys = keys %{$classlist};
# Sort by: Section, name
@keys = sort {
- if ($choices->{$a}->[$section] ne $choices->{$b}->[$section]) {
- return $choices->{$a}->[$section] cmp $choices->{$b}->[$section];
+ if ($classlist->{$a}->[$section] ne $classlist->{$b}->[$section]) {
+ return $classlist->{$a}->[$section] cmp $classlist->{$b}->[$section];
}
- return $choices->{$a}->[$fullname] cmp $choices->{$b}->[$fullname];
+ return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname];
} @keys;
+ # username, fullname, section, type
+ for (@keys) {
+ push @$choices, [$_, $classlist->{$_}->[$fullname],
+ $classlist->{$_}->[$section], 'Student'];
+ }
+
+ my $name = $self->{'coursepersonnel'} ? 'Name' : 'Student Name';
my $type = 'radio';
if ($self->{'multichoice'}) { $type = 'checkbox'; }
$result .= "<table cellspacing='2' cellpadding='2' border='0'>\n";
- $result .= "<tr><td></td><td align='center'><b>Student Name</b></td>".
- "<td align='center'><b>Section</b></td></tr>";
+ $result .= "<tr><td></td><td align='center'><b>$name</b></td>".
+ "<td align='center'><b>Section</b></td>" .
+ "<td align='center'><b>Role</b></td></tr>";
my $checked = 0;
- foreach (@keys) {
+ for my $choice (@$choices) {
$result .= "<tr><td><input type='$type' name='" .
$self->{'variable'} . '.forminput' . "'";
@@ -1885,12 +1917,13 @@
$checked = 1;
}
$result .=
- " value='" . HTML::Entities::encode($_ . ':' . $choices->{$_}->[$section])
+ " value='" . HTML::Entities::encode($choice->[0] . ':' . $choice->[2])
. "' /></td><td>"
- . HTML::Entities::encode($choices->{$_}->[$fullname])
+ . HTML::Entities::encode($choice->[1])
. "</td><td align='center'>"
- . HTML::Entities::encode($choices->{$_}->[$section])
- . "</td></tr>\n";
+ . HTML::Entities::encode($choice->[2])
+ . "</td>\n<td>"
+ . HTML::Entities::encode($choice->[3]) . "</td></tr>\n";
}
$result .= "</table>\n\n";