[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm
raeburn
raeburn@source.lon-capa.org
Fri, 27 Mar 2009 02:40:00 -0000
This is a MIME encoded message
--raeburn1238121600
Content-Type: text/plain
raeburn Fri Mar 27 02:40:00 2009 EDT
Modified files:
/loncom/interface lonnavmaps.pm
Log:
- Resource availability in "Navigate Contents" now considers slot status where
a resource uses slots.
- If current user doesn't have mgr priv, availability messages will be displayed in Contents table if simpleStatus of resource is "OPEN".
- New methods for resource objects:
- taskversion(): returns the current version, where the resource is a task.
- taskstatus(): returns the status of the current version of a task.
- solved(): returns the "solved" state of the resource
- checkedin(): returns an array contained value of checkedin, and checkedin.slot for a resource with slot control.
- slot_control(): returns array of parameters: useslots, availablestudent, available.
- New numerical status values for a resource using slots:
RESERVED_LATER 30
RESERVED 31
RESERVED_LOCATION 32
RESERVABLE 33
RESERVABLE_LATER 34
NOTRESERVABLE 35
NOT_IN_A_SLOT 36
NEEDS_CHECKIN 37
WAITING_FOR_GRADE 38
UNKNOWN 39
&check_for_slot()
- New method for a resource object, which will return one of these status values where useslots applies.
&get_future_slots()
- Helper method to check if there are any slots in the course which might be reservable if the user doesn't currently have any slots associated with a resource using slots.
- New navmap package variables:
$future_slots_checked - true if check has been made for any slots with future start times.
$future_slots - count of slots with future start times.
--raeburn1238121600
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090327024000.txt"
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.431 loncom/interface/lonnavmaps.pm:1.432
--- loncom/interface/lonnavmaps.pm:1.431 Mon Mar 16 15:25:40 2009
+++ loncom/interface/lonnavmaps.pm Fri Mar 27 02:39:59 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.431 2009/03/16 15:25:40 schulted Exp $
+# $Id: lonnavmaps.pm,v 1.432 2009/03/27 02:39:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -530,6 +530,9 @@
# is not yet done and due in less than 24 hours
my $hurryUpColor = "#FF0000";
+my $future_slots_checked = 0;
+my $future_slots = 0;
+
sub close {
if ($env{'environment.remotenavmap'} ne 'on') { return ''; }
return(<<ENDCLOSE);
@@ -634,6 +637,35 @@
if ($status == $res->OPEN_LATER) {
return &mt("Open ") .timeToHumanString($open,'start');
}
+ if ($res->simpleStatus($part) == $res->OPEN) {
+ unless (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
+ my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
+ if ($slot_status == $res->UNKNOWN) {
+ return &mt('Reservation status unknown');
+ } elsif ($slot_status == $res->RESERVED) {
+ return &mt('Reserved - ends').' '.
+ timeToHumanString($slot_time,'end');
+ } elsif ($slot_status == $res->RESERVED_LOCATION) {
+ return &mt('Reserved - specific location(s) - ends').' '.
+ timeToHumanString($slot_time,'end');
+ } elsif ($slot_status == $res->RESERVED_LATER) {
+ return &mt('Reserved - next open').' '.
+ timeToHumanString($slot_time,'start');
+ } elsif ($slot_status == $res->RESERVABLE) {
+ return &mt('Reservable ending').' '.
+ timeToHumanString($slot_time,'end');
+ } elsif ($slot_status == $res->RESERVABLE_LATER) {
+ return &mt('Reservable starting').' '.
+ timeToHumanString($slot_time,'start');
+ } elsif ($slot_status == $res->NOT_IN_A_SLOT) {
+ return &mt('Reserve a time/place to work');
+ } elsif ($slot_status == $res->NOTRESERVABLE) {
+ return &mt('Reservation not available');
+ } elsif ($slot_status == $res->WAITING_FOR_GRADE) {
+ return &mt('Submission in grading queue');
+ }
+ }
+ }
if ($status == $res->OPEN) {
if ($due) {
if ($res->is_practice()) {
@@ -3977,6 +4009,35 @@
if (!defined($part)) { $part = '0'; }
return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.awarded'};
}
+sub taskversion {
+ my $self = shift; my $part = shift;
+ $self->{NAV_MAP}->get_user_data();
+ if (!defined($part)) { $part = '0'; }
+ return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.version'};
+}
+sub taskstatus {
+ my $self = shift; my $part = shift;
+ $self->{NAV_MAP}->get_user_data();
+ if (!defined($part)) { $part = '0'; }
+ return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'};
+}
+sub solved {
+ my $self = shift; my $part = shift;
+ $self->{NAV_MAP}->get_user_data();
+ if (!defined($part)) { $part = '0'; }
+ return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.solved'};
+}
+sub checkedin {
+ my $self = shift; my $part = shift;
+ $self->{NAV_MAP}->get_user_data();
+ if (!defined($part)) { $part = '0'; }
+ if ($self->is_task()) {
+ my $version = $self->taskversion($part);
+ return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin.slot'});
+ } else {
+ return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin.slot'});
+ }
+}
# this should work exactly like the copy in lonhomework.pm
sub duedate {
(my $self, my $part) = @_;
@@ -4072,6 +4133,14 @@
}
return $display;
}
+sub slot_control {
+ my $self=shift(); my $part = shift();
+ if (!defined($part)) { $part = '0'; }
+ my $useslots = $self->parmval("useslots", $part);
+ my $availablestudent = $self->parmval("availablestudent", $part);
+ my $available = $self->parmval("available", $part);
+ return ($useslots,$availablestudent,$available);
+}
# Multiple things need this
sub getReturnHash {
@@ -4504,7 +4573,7 @@
sub PAST_DUE_NO_ANSWER { return 2; }
sub PAST_DUE_ANSWER_LATER { return 3; }
sub ANSWER_OPEN { return 4; }
-sub NOTHING_SET { return 5; }
+sub NOTHING_SET { return 5; }
sub NETWORK_FAILURE { return 100; }
# getDateStatus gets the date status for a given problem part.
@@ -4716,9 +4785,20 @@
=cut
-sub TRIES_LEFT { return 20; }
-sub ANSWER_SUBMITTED { return 21; }
-sub PARTIALLY_CORRECT{ return 22; }
+sub TRIES_LEFT { return 20; }
+sub ANSWER_SUBMITTED { return 21; }
+sub PARTIALLY_CORRECT { return 22; }
+
+sub RESERVED_LATER { return 30; }
+sub RESERVED { return 31; }
+sub RESERVED_LOCATION { return 32; }
+sub RESERVABLE { return 33; }
+sub RESERVABLE_LATER { return 34; }
+sub NOTRESERVABLE { return 35; }
+sub NOT_IN_A_SLOT { return 36; }
+sub NEEDS_CHECKIN { return 37; }
+sub WAITING_FOR_GRADE { return 38; }
+sub UNKNOWN { return 39; }
sub status {
my $self = shift;
@@ -4811,6 +4891,108 @@
return OPEN;
}
+sub check_for_slot {
+ my $self = shift;
+ my $part = shift;
+ my ($use_slots,$available,$availablestudent) = $self->slot_control($part);
+ if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) {
+ my @slots = (split(/:/,$availablestudent),split(/:/,$available));
+ my $cid=$env{'request.course.id'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $now = time;
+ if (@slots > 0) {
+ my %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
+ if (&Apache::lonnet::error(%slots)) {
+ return (UNKNOWN);
+ }
+ my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots);
+ my ($checkedin,$checkedinslot);
+ foreach my $slot_name (@sorted_slots) {
+ next if (!defined($slots{$slot_name}) ||
+ !ref($slots{$slot_name}));
+ my $end = $slots{$slot_name}->{'endtime'};
+ my $start = $slots{$slot_name}->{'starttime'};
+ my $ip = $slots{$slot_name}->{'ip'};
+ if ($self->simpleStatus() == OPEN) {
+ my $startreserve = $slots{$slot_name}->{'startreserve'};
+ my @proctors;
+ if ($slots{$slot_name}->{'proctor'} ne '') {
+ @proctors = split(',',$slots{$slot_name}->{'proctor'});
+ }
+ if ($end > $now) {
+ ($checkedin,$checkedinslot) = $self->checkedin();
+ if ($startreserve < $now) {
+ if ($start > $now) {
+ return (RESERVED_LATER,$start,$slot_name);
+ } else {
+ if ($ip ne '') {
+ if (!&Apache::loncommon::check_ip_acc($ip)) {
+ return (RESERVED_LOCATION,$ip,$slot_name);
+ }
+ }
+ if (@proctors > 0) {
+ unless ((grep(/^\Q$checkedin\E/,@proctors)) &&
+ ($checkedinslot eq $slot_name)) {
+ return (NEEDS_CHECKIN,undef,$slot_name);
+ }
+ }
+ return (RESERVED,$end,$slot_name);
+ }
+ } else {
+ if ($start > $now) {
+ return (RESERVABLE,$startreserve,$slot_name);
+ }
+ }
+ }
+ }
+ }
+ my ($is_correct,$got_grade);
+ if ($self->is_task()) {
+ my $taskstatus = $self->taskstatus();
+ $is_correct = (($taskstatus eq 'pass') ||
+ ($self->solved() =~ /^correct_/));
+ $got_grade = ($self->solved() =~ /^(?:pass|fail)$/);
+ } else {
+ $got_grade = 1;
+ $is_correct = ($self->solved() =~ /^correct_/);
+ }
+ ($checkedin,$checkedinslot) = $self->checkedin();
+ if ($checkedin) {
+ if (!$got_grade) {
+ return (WAITING_FOR_GRADE);
+ } elsif ($is_correct) {
+ return (CORRECT);
+ }
+ }
+ return(NOT_IN_A_SLOT);
+ } else {
+ if (!$future_slots_checked) {
+ $future_slots = &get_future_slots($cdom,$cnum,$now);
+ $future_slots_checked = 1;
+ }
+ if ($future_slots) {
+ return(NOT_IN_A_SLOT);
+ }
+ return(NOTRESERVABLE);
+ }
+ }
+ return;
+}
+
+sub get_future_slots {
+ my ($cdom,$cnum,$now) = @_;
+ my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
+ my $future_slots = 0;
+ foreach my $slot (keys(%slots)) {
+ if (($slots{$slot}->{'starttime'} > $now) &&
+ ($slots{$slot}->{'endtime'} > $now)) {
+ $future_slots ++;
+ }
+ }
+ return $future_slots;
+}
+
sub CLOSED { return 23; }
sub ERROR { return 24; }
--raeburn1238121600--