[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmsg.pm lonpreferences.pm

raeburn raeburn@source.lon-capa.org
Tue, 23 Dec 2008 19:22:14 -0000


raeburn		Tue Dec 23 19:22:14 2008 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm loncommon.pm lonpreferences.pm 
  Log:
  - Cache a user's language preference. Used when creating e-mail notifications to send to a user.  
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.218 loncom/interface/lonmsg.pm:1.219
--- loncom/interface/lonmsg.pm:1.218	Fri Dec 19 02:43:52 2008
+++ loncom/interface/lonmsg.pm	Tue Dec 23 19:22:13 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.218 2008/12/19 02:43:52 raeburn Exp $
+# $Id: lonmsg.pm,v 1.219 2008/12/23 19:22:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1005,7 +1005,7 @@
         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                     $env{'course.'.$fromcid.'.languages'}));
     } else {
-        my %langhash = &Apache::lonnet::get('environment',['languages'],$toudom,$touname);
+        my %langhash = &Apache::loncommon::getlangs($toudom,$touname);
         if ($langhash{'languages'} ne '') {
             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});  
         } else {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.727 loncom/interface/loncommon.pm:1.728
--- loncom/interface/loncommon.pm:1.727	Sun Dec 21 22:02:39 2008
+++ loncom/interface/loncommon.pm	Tue Dec 23 19:22:13 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.727 2008/12/21 22:02:39 riegler Exp $
+# $Id: loncommon.pm,v 1.728 2008/12/23 19:22:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2717,6 +2717,43 @@
     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
 }
 
+# -------------------------------------------------------------------- getlangs
+
+=pod
+
+=item * &getlangs($uname,$udom)
+
+Gets a user's language preference and returns it as a hash with key:
+language.
+
+=cut
+
+
+sub getlangs {
+    my ($uname,$udom) = @_;
+    if (!$udom)  { $udom =$env{'user.domain'}; }
+    if (!$uname) { $uname=$env{'user.name'};   }
+    my $id=$uname.':'.$udom;
+    my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
+    if ($cached) {
+        return %{$langs};
+    } else {
+        my %loadlangs=&Apache::lonnet::get('environment',['languages'],
+                                           $udom,$uname);
+        &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
+        return %loadlangs;
+    }
+}
+
+sub flush_langs_cache {
+    my ($uname,$udom)=@_;
+    if (!$udom)  { $udom =$env{'user.domain'}; }
+    if (!$uname) { $uname=$env{'user.name'};   }
+    return if ($udom eq 'public' && $uname eq 'public');
+    my $id=$uname.':'.$udom;
+    &Apache::lonnet::devalidate_cache_new('userlangs',$id);
+}
+
 # ------------------------------------------------------------------ Screenname
 
 =pod
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.131 loncom/interface/lonpreferences.pm:1.132
--- loncom/interface/lonpreferences.pm:1.131	Mon Dec  8 23:09:26 2008
+++ loncom/interface/lonpreferences.pm	Tue Dec 23 19:22:13 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.131 2008/12/08 23:09:26 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.132 2008/12/23 19:22:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -193,6 +193,7 @@
         &Apache::lonnet::delenv('environment\.languages');
         $message=&mt('Reset preferred language.');
     }
+    &Apache::loncommon::flush_langs_cache($user,$domain);
     print_main_menu($r, $message);
 #    $r->print(<<ENDVCSCREEN);
 #$message