[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm lonhelper.pm lonnavmaps.pm lonquickgrades.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Thu, 07 Aug 2003 17:26:45 -0000
This is a MIME encoded message
--bowersj21060277205
Content-Type: text/plain
bowersj2 Thu Aug 7 13:26:45 2003 EDT
Modified files:
/loncom/interface loncoursedata.pm lonhelper.pm lonnavmaps.pm
lonquickgrades.pm
Log:
lonnavmaps are now maximally lazy; no processing is performed until it
is needed, except in cases where it makes sense to grab all data for the
course at a time.
As a result, the Apache::lonnavmaps::navmap->new() call no longer needs
any arguments; it assumes you're using the current user's navmaps and
generates the other data as needed.
--bowersj21060277205
Content-Type: text/plain
Content-Disposition: attachment; filename="bowersj2-20030807132645.txt"
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.82 loncom/interface/loncoursedata.pm:1.83
--- loncom/interface/loncoursedata.pm:1.82 Thu Aug 7 10:29:43 2003
+++ loncom/interface/loncoursedata.pm Thu Aug 7 13:26:44 2003
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: loncoursedata.pm,v 1.82 2003/08/07 14:29:43 bowersj2 Exp $
+# $Id: loncoursedata.pm,v 1.83 2003/08/07 17:26:44 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -104,7 +104,7 @@
my $fn=$ENV{'request.course.fn'};
##
## use navmaps
- my $navmap = Apache::lonnavmaps::navmap->new(1,0);
+ my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
return 'Can not open Coursemap';
}
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.40 loncom/interface/lonhelper.pm:1.41
--- loncom/interface/lonhelper.pm:1.40 Mon Jun 23 16:39:18 2003
+++ loncom/interface/lonhelper.pm Thu Aug 7 13:26:44 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.40 2003/06/23 20:39:18 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.41 2003/08/07 17:26:44 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2755,9 +2755,7 @@
$symb = 'a';
$paramlevel = 'general';
} elsif ($vars->{GRANULARITY} eq 'map') {
- my $navmap = Apache::lonnavmaps::navmap->new(
- $ENV{"request.course.fn"}.".db",
- $ENV{"request.course.fn"}."_parms.db", 0, 0);
+ my $navmap = Apache::lonnavmaps::navmap->new();
my $res = $navmap->getByMapPc($vars->{RESOURCE_ID});
my $title = $res->compTitle();
$symb = $res->symb();
@@ -2767,9 +2765,7 @@
$affectedResourceId = $vars->{RESOURCE_ID};
$paramlevel = 'map';
} else {
- my $navmap = Apache::lonnavmaps::navmap->new(
- $ENV{"request.course.fn"}.".db",
- $ENV{"request.course.fn"}."_parms.db", 0, 0);
+ my $navmap = Apache::lonnavmaps::navmap->new();
my $res = $navmap->getById($vars->{RESOURCE_ID});
$symb = $res->symb();
my $title = $res->compTitle();
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.220 loncom/interface/lonnavmaps.pm:1.221
--- loncom/interface/lonnavmaps.pm:1.220 Thu Aug 7 10:29:43 2003
+++ loncom/interface/lonnavmaps.pm Thu Aug 7 13:26:44 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.220 2003/08/07 14:29:43 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.221 2003/08/07 17:26:44 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -129,7 +129,7 @@
$r->send_http_header;
# Create the nav map
- my $navmap = Apache::lonnavmaps::navmap->new(1, 1);
+ my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
@@ -159,11 +159,6 @@
$r->rflush();
- # Now that we've displayed some stuff to the user, init the navmap
- $navmap->init();
-
- $r->rflush();
-
# Check that it's defined
if (!($navmap->courseMapDefined())) {
$r->print('<font size="+2" color="red">Coursemap undefined.</font>' .
@@ -1170,10 +1165,9 @@
if (!$ENV{'form.folderManip'} && !defined($args->{'iterator'})) {
# Step 1: Check to see if we have a navmap
if (!defined($navmap)) {
- $navmap = Apache::lonnavmaps::navmap->new(1, 1);
+ $navmap = Apache::lonnavmaps::navmap->new();
$mustCloseNavMap = 1;
}
- $navmap->init();
# Step two: Locate what kind of here marker is necessary
# Determine where the "here" marker is and where the screen jumps to.
@@ -1234,11 +1228,9 @@
# Step 1: Check to see if we have a navmap
if (!defined($navmap)) {
- $navmap = Apache::lonnavmaps::navmap->new(1, 1);
+ $navmap = Apache::lonnavmaps::navmap->new();
$mustCloseNavMap = 1;
}
- # Paranoia: Make sure it's ready
- $navmap->init();
# See if we're being passed a specific map
if ($args->{'iterator_map'}) {
@@ -1640,28 +1632,13 @@
=over 4
-=item * B<Apache::lonnavmaps::navmap-E<gt>new>(
- genCourseAndUserOptions, genMailDiscussStatus, getUserData):
+=item * B<Apache::lonnavmaps::navmap-E<gt>new>():
-Creates a new navmap object. genCourseAndUserOptions is a flag saying whether
-the course options and user options hash should be generated. This is
-for when you are using the parameters of the resources that require
-them; see documentation in resource object
-documentation. genMailDiscussStatus causes the nav map to retreive
-information about the email and discussion status of
-resources. Returns the navmap object if this is successful, or
-B<undef> if not. You must check for undef; errors will occur when you
-try to use the other methods otherwise. getUserData, if true, will
-retreive the user's performance data for various problems.
+Creates a new navmap object. Returns the navmap object if this is
+successful, or B<undef> if not.
=back
-Once you have the $navmap object, call ->init() on it when you are ready
-to use it. This allows you to check if the course map is defined (see
-B<courseMapDefined> below) before engaging in potentially expensive
-initialization routines for the genCourseAndUserOptions and
-genMailDiscussStatus option.
-
When you are done with the $navmap object, you I<must> call
$navmap->untieHashes(), or you'll prevent the current user from using that
course until the web server is restarted. (!)
@@ -1685,10 +1662,6 @@
my $class = ref($proto) || $proto;
my $self = {};
- $self->{GENERATE_COURSE_USER_OPT} = shift;
- $self->{GENERATE_EMAIL_DISCUSS_STATUS} = shift;
- $self->{GET_USER_DATA} = shift;
-
# Resource cache stores navmap resources as we reference them. We generate
# them on-demand so we don't pay for creating resources unless we use them.
$self->{RESOURCE_CACHE} = {};
@@ -1716,128 +1689,134 @@
$self->{NAV_HASH} = \%navmaphash;
$self->{PARM_HASH} = \%parmhash;
- $self->{INITED} = 0;
+ $self->{PARM_CACHE} = {};
bless($self);
return $self;
}
-sub init {
+sub generate_course_user_opt {
my $self = shift;
- if ($self->{INITED}) { return; }
+ if ($self->{COURSE_USER_OPT_GENERATED}) { return; }
- # If the course opt hash and the user opt hash should be generated,
- # generate them
- if ($self->{GENERATE_COURSE_USER_OPT}) {
- my $uname=$ENV{'user.name'};
- my $udom=$ENV{'user.domain'};
- my $uhome=$ENV{'user.home'};
- my $cid=$ENV{'request.course.id'};
- my $chome=$ENV{'course.'.$cid.'.home'};
- my ($cdom,$cnum)=split(/\_/,$cid);
-
- my $userprefix=$uname.'_'.$udom.'_';
-
- my %courserdatas; my %useropt; my %courseopt; my %userrdatas;
- unless ($uhome eq 'no_host') {
+ my $uname=$ENV{'user.name'};
+ my $udom=$ENV{'user.domain'};
+ my $uhome=$ENV{'user.home'};
+ my $cid=$ENV{'request.course.id'};
+ my $chome=$ENV{'course.'.$cid.'.home'};
+ my ($cdom,$cnum)=split(/\_/,$cid);
+
+ my $userprefix=$uname.'_'.$udom.'_';
+
+ my %courserdatas; my %useropt; my %courseopt; my %userrdatas;
+ unless ($uhome eq 'no_host') {
# ------------------------------------------------- Get coursedata (if present)
- unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
- my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
- ':resourcedata',$chome);
- # Check for network failure
- if ( $reply =~ /no.such.host/i || $reply =~ /con_lost/i) {
- $self->{NETWORK_FAILURE} = 1;
- } elsif ($reply!~/^error\:/) {
- $courserdatas{$cid}=$reply;
- $courserdatas{$cid.'.last_cache'}=time;
- }
- }
- foreach (split(/\&/,$courserdatas{$cid})) {
- my ($name,$value)=split(/\=/,$_);
- $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
+ unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
+ my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
+ ':resourcedata',$chome);
+ # Check for network failure
+ if ( $reply =~ /no.such.host/i || $reply =~ /con_lost/i) {
+ $self->{NETWORK_FAILURE} = 1;
+ } elsif ($reply!~/^error\:/) {
+ $courserdatas{$cid}=$reply;
+ $courserdatas{$cid.'.last_cache'}=time;
+ }
+ }
+ foreach (split(/\&/,$courserdatas{$cid})) {
+ my ($name,$value)=split(/\=/,$_);
+ $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
+ &Apache::lonnet::unescape($value);
+ }
# --------------------------------------------------- Get userdata (if present)
- unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
- my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
- if ($reply!~/^error\:/) {
- $userrdatas{$uname.'___'.$udom}=$reply;
- $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
- }
- # check to see if network failed
- elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
- {
- $self->{NETWORK_FAILURE} = 1;
- }
- }
- foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
- my ($name,$value)=split(/\=/,$_);
- $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
- $self->{COURSE_OPT} = \%courseopt;
- $self->{USER_OPT} = \%useropt;
- }
- }
-
- if ($self->{GENERATE_EMAIL_DISCUSS_STATUS}) {
- my $cid=$ENV{'request.course.id'};
- my ($cdom,$cnum)=split(/\_/,$cid);
-
- my %emailstatus = &Apache::lonnet::dump('email_status');
- my $logoutTime = $emailstatus{'logout'};
- my $courseLeaveTime = $emailstatus{'logout_'.$ENV{'request.course.id'}};
- $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
- $courseLeaveTime : $logoutTime);
- my %discussiontime = &Apache::lonnet::dump('discussiontimes',
- $cdom, $cnum);
- my %feedback=();
- my %error=();
- my $keys = &Apache::lonnet::reply('keys:'.
- $ENV{'user.domain'}.':'.
- $ENV{'user.name'}.':nohist_email',
- $ENV{'user.home'});
-
- foreach my $msgid (split(/\&/, $keys)) {
- $msgid=&Apache::lonnet::unescape($msgid);
- my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
- if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
- my ($what,$url)=($1,$2);
- my %status=
- &Apache::lonnet::get('email_status',[$msgid]);
- if ($status{$msgid}=~/^error\:/) {
- $status{$msgid}='';
- }
-
- if (($status{$msgid} eq 'new') ||
- (!$status{$msgid})) {
- if ($what eq 'Error') {
- $error{$url}.=','.$msgid;
- } else {
- $feedback{$url}.=','.$msgid;
- }
- }
- }
- }
-
- $self->{FEEDBACK} = \%feedback;
- $self->{ERROR_MSG} = \%error; # what is this? JB
- $self->{DISCUSSION_TIME} = \%discussiontime;
- $self->{EMAIL_STATUS} = \%emailstatus;
-
+ unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
+ my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
+ if ($reply!~/^error\:/) {
+ $userrdatas{$uname.'___'.$udom}=$reply;
+ $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
+ }
+ # check to see if network failed
+ elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
+ {
+ $self->{NETWORK_FAILURE} = 1;
+ }
+ }
+ foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
+ my ($name,$value)=split(/\=/,$_);
+ $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
+ &Apache::lonnet::unescape($value);
+ }
+ $self->{COURSE_OPT} = \%courseopt;
+ $self->{USER_OPT} = \%useropt;
}
- if ($self->{GET_USER_DATA}) {
- # Retreive performance data on problems
- my %student_data = Apache::lonnet::currentdump($ENV{'request.course.id'},
- $ENV{'user.domain'},
- $ENV{'user.name'});
- $self->{STUDENT_DATA} = \%student_data;
+ $self->{COURSE_USER_OPT_GENERATED} = 1;
+
+ return;
+}
+
+sub generate_email_discuss_status {
+ my $self = shift;
+ if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
+
+ my $cid=$ENV{'request.course.id'};
+ my ($cdom,$cnum)=split(/\_/,$cid);
+
+ my %emailstatus = &Apache::lonnet::dump('email_status');
+ my $logoutTime = $emailstatus{'logout'};
+ my $courseLeaveTime = $emailstatus{'logout_'.$ENV{'request.course.id'}};
+ $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
+ $courseLeaveTime : $logoutTime);
+ my %discussiontime = &Apache::lonnet::dump('discussiontimes',
+ $cdom, $cnum);
+ my %feedback=();
+ my %error=();
+ my $keys = &Apache::lonnet::reply('keys:'.
+ $ENV{'user.domain'}.':'.
+ $ENV{'user.name'}.':nohist_email',
+ $ENV{'user.home'});
+
+ foreach my $msgid (split(/\&/, $keys)) {
+ $msgid=&Apache::lonnet::unescape($msgid);
+ my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
+ if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
+ my ($what,$url)=($1,$2);
+ my %status=
+ &Apache::lonnet::get('email_status',[$msgid]);
+ if ($status{$msgid}=~/^error\:/) {
+ $status{$msgid}='';
+ }
+
+ if (($status{$msgid} eq 'new') ||
+ (!$status{$msgid})) {
+ if ($what eq 'Error') {
+ $error{$url}.=','.$msgid;
+ } else {
+ $feedback{$url}.=','.$msgid;
+ }
+ }
+ }
}
+
+ $self->{FEEDBACK} = \%feedback;
+ $self->{ERROR_MSG} = \%error; # what is this? JB
+ $self->{DISCUSSION_TIME} = \%discussiontime;
+ $self->{EMAIL_STATUS} = \%emailstatus;
+
+ $self->{EMAIL_DISCUSS_GENERATED} = 1;
+}
- $self->{PARM_CACHE} = {};
- $self->{INITED} = 1;
+sub get_user_data {
+ my $self = shift;
+ if ($self->{RETRIEVED_USER_DATA}) { return; }
+
+ # Retrieve performance data on problems
+ my %student_data = Apache::lonnet::currentdump($ENV{'request.course.id'},
+ $ENV{'user.domain'},
+ $ENV{'user.name'});
+ $self->{STUDENT_DATA} = \%student_data;
+
+ $self->{RETRIEVED_USER_DATA} = 1;
}
# Internal function: Takes a key to look up in the nav hash and implements internal
@@ -1885,6 +1864,9 @@
sub hasDiscussion {
my $self = shift;
my $symb = shift;
+
+ $self->generate_email_discuss_status();
+
if (!defined($self->{DISCUSSION_TIME})) { return 0; }
#return defined($self->{DISCUSSION_TIME}->{$symb});
@@ -1899,6 +1881,8 @@
my $self = shift;
my $symb = shift;
+ $self->generate_email_discuss_status();
+
if (!defined($self->{FEEDBACK})) { return ""; }
return $self->{FEEDBACK}->{$symb};
@@ -1908,7 +1892,9 @@
sub getErrors {
my $self = shift;
my $src = shift;
-
+
+ $self->generate_email_discuss_status();
+
if (!defined($self->{ERROR_MSG})) { return ""; }
return $self->{ERROR_MSG}->{$src};
}
@@ -2021,6 +2007,9 @@
my $self = shift;
my ($what,$symb,$recurse) = @_;
+ # Make sure the {USER_OPT} and {COURSE_OPT} hashes are populated
+ $self->generate_course_user_opt();
+
my $cid=$ENV{'request.course.id'};
my $csec=$ENV{'request.course.sec'};
my $uname=$ENV{'user.name'};
@@ -3299,6 +3288,7 @@
}
sub awarded {
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.'.awarded'};
}
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.23 loncom/interface/lonquickgrades.pm:1.24
--- loncom/interface/lonquickgrades.pm:1.23 Thu Aug 7 10:29:43 2003
+++ loncom/interface/lonquickgrades.pm Thu Aug 7 13:26:45 2003
@@ -67,7 +67,7 @@
$ENV{'course.'.$ENV{'request.course.id'}.'.grading'} eq 'standard';
# Create the nav map
- my $navmap = Apache::lonnavmaps::navmap->new(1, 0, 1);
+ my $navmap = Apache::lonnavmaps::navmap->new();
if (!defined($navmap)) {
my $requrl = $r->uri;
@@ -94,8 +94,6 @@
$r->print("This may take a few moments to display.");
$r->rflush();
-
- $navmap->init();
# End navmap using boilerplate
--bowersj21060277205--