[LON-CAPA-cvs] cvs: loncom /interface groupsort.pm lonindexer.pm rat lonsequence.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 11 Jul 2007 23:51:19 -0000
albertel Wed Jul 11 19:51:19 2007 EDT
Modified files:
/rat lonsequence.pm
/loncom/interface groupsort.pm lonindexer.pm
Log:
- elimintate some copyied code
Index: rat/lonsequence.pm
diff -u rat/lonsequence.pm:1.30 rat/lonsequence.pm:1.31
--- rat/lonsequence.pm:1.30 Tue Jan 16 16:19:11 2007
+++ rat/lonsequence.pm Wed Jul 11 19:51:02 2007
@@ -2,7 +2,7 @@
#
# Sequence Handler
#
-# $Id: lonsequence.pm,v 1.30 2007/01/16 21:19:11 albertel Exp $
+# $Id: lonsequence.pm,v 1.31 2007/07/11 23:51:02 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@
use LONCAPA::map();
use Apache::lonpageflip();
use Apache::loncommon();
+use Apache::groupsort();
use Apache::lonlocal;
use HTML::Entities();
@@ -114,46 +115,9 @@
$successtied=1;
# - Evaluate actions from previous page (both cumulatively and chronologically)
- if ($env{'form.catalogmode'} eq 'import') {
- my $acts=$env{'form.acts'};
- my @Acts=split(/b/,$acts);
- my %ahash;
- my %achash;
- my $ac=0;
- # some initial hashes for working with data
- foreach (@Acts) {
- my ($state,$ref)=split(/a/);
- $ahash{$ref}=$state;
- $achash{$ref}=$ac;
- $ac++;
+ if ($env{'form.catalogmode'} eq 'import') {
+ &Apache::groupsort::update_actions_hash(\%selhash);
}
- # sorting through the actions and changing the tied database hash
- foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
- my $key=$_;
- if ($ahash{$key} eq '1') {
- $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}=
- $selhash{'pre_'.$key.'_title'};
- $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}=
- $selhash{'storectr'}+0;
- $selhash{'storectr'}++;
- }
- if ($ahash{$key} eq '0') {
- if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) {
- delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}};
- }
- }
- }
- # deleting the previously cached listing
- foreach (keys %selhash) {
- if ($_ =~ /^pre_/ && $_ =~/link$/) {
- my $key = $_;
- $key =~ s/^pre_//;
- $key =~ s/_[^_]*$//;
- delete $selhash{'pre_'.$key.'_title'};
- delete $selhash{'pre_'.$key.'_link'};
- }
- }
- }
# -
}
}
Index: loncom/interface/groupsort.pm
diff -u loncom/interface/groupsort.pm:1.54 loncom/interface/groupsort.pm:1.55
--- loncom/interface/groupsort.pm:1.54 Wed Jul 11 16:32:15 2007
+++ loncom/interface/groupsort.pm Wed Jul 11 19:51:19 2007
@@ -2,7 +2,7 @@
# The LON-CAPA group sort handler
# Allows for sorting prior to import into RAT.
#
-# $Id: groupsort.pm,v 1.54 2007/07/11 20:32:15 albertel Exp $
+# $Id: groupsort.pm,v 1.55 2007/07/11 23:51:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,6 +43,44 @@
my %hash; # variable to tie to user specific database
+sub update_actions_hash {
+ my ($hash) = @_;
+ my $acts=$env{'form.acts'};
+ my @Acts=split(/b/,$acts);
+ my %ahash;
+ my %achash;
+ my $ac=0;
+ # some initial hashes for working with data
+ foreach (@Acts) {
+ my ($state,$ref)=split(/a/);
+ $ahash{$ref}=$state;
+ $achash{$ref}=$ac;
+ $ac++;
+ }
+ # sorting through the actions and changing the global database hash
+ foreach my $key (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
+ if ($ahash{$key} eq '1') {
+ $hash->{'store_'.$hash{'pre_'.$key.'_link'}}=
+ $hash->{'pre_'.$key.'_title'};
+ $hash->{'storectr_'.$hash{'pre_'.$key.'_link'}}=
+ $hash->{'storectr'}+0;
+ $hash->{'storectr'}++;
+ }
+ if ($ahash{$key} eq '0') {
+ if ($hash->{'store_'.$hash{'pre_'.$key.'_link'}}) {
+ delete($hash->{'store_'.$hash{'pre_'.$key.'_link'}});
+ }
+ }
+ }
+ # deleting the previously cached listing
+ foreach my $key (keys(%{ $hash })) {
+ next if ($key !~ /^pre_(\d+)_link/);
+ my $which = $1;
+ delete($hash->{'pre_'.$which.'_title'});
+ delete($hash->{'pre_'.$which.'_link'});
+ }
+}
+
sub readfromdb {
my ($r,$shash,$thash)=@_;
@@ -51,35 +89,8 @@
# ----------------------------- diropendb is now the filename of the db to open
if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
- my $acts = $env{'form.acts'};
- my @Acts = split(/b/,$acts);
- my %ahash;
- my %achash;
- my $ac = 0;
- foreach (@Acts) {
- my ($state,$ref) = split(/a/);
- $ahash{$ref} = $state;
- $achash{$ref} = $ac;
- $ac++;
- }
- foreach (sort {$achash{$a} <=> $achash{$b}} (keys %ahash)) {
- my $key = $_;
- if ($ahash{$key} eq '1') {
- if ($hash{'pre_'.$key.'_title'} eq 'Not_retrieved') {
- $hash{'pre_'.$key.'_title'} = &Apache::lonnet::gettitle($hash{'pre_'.$key.'_link'});
- }
- $hash{'store_'.$hash{'pre_'.$key.'_link'}} =
- $hash{'pre_'.$key.'_title'};
- $hash{'storectr_'.$hash{'pre_'.$key.'_link'}} =
- $hash{'storectr'}+0;
- $hash{'storectr'}++;
- }
- if ($ahash{$key} eq '0') {
- if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
- delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
- }
- }
- }
+ &update_actions_hash(\%hash);
+
foreach (keys %hash) {
if ($_ =~ /^store_/) {
my $key = $_;
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.171 loncom/interface/lonindexer.pm:1.172
--- loncom/interface/lonindexer.pm:1.171 Wed Jul 11 16:40:28 2007
+++ loncom/interface/lonindexer.pm Wed Jul 11 19:51:19 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Directory Indexer
#
-# $Id: lonindexer.pm,v 1.171 2007/07/11 20:40:28 albertel Exp $
+# $Id: lonindexer.pm,v 1.172 2007/07/11 23:51:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -53,6 +53,7 @@
use Apache::File;
use Apache::lonlocal;
use Apache::lonsource();
+use Apache::groupsort();
use GDBM_File;
use LONCAPA qw(:match);
@@ -399,43 +400,7 @@
{'domain' => $headerdom,}));
# - Evaluate actions from previous page (both cumulatively and chronologically)
if ($env{'form.catalogmode'} eq 'import') {
- my $acts=$env{'form.acts'};
- my @Acts=split(/b/,$acts);
- my %ahash;
- my %achash;
- my $ac=0;
- # some initial hashes for working with data
- foreach (@Acts) {
- my ($state,$ref)=split(/a/);
- $ahash{$ref}=$state;
- $achash{$ref}=$ac;
- $ac++;
- }
- # sorting through the actions and changing the global database hash
- foreach my $key (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
- if ($ahash{$key} eq '1') {
- $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
- $hash{'pre_'.$key.'_title'};
- $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
- $hash{'storectr'}+0;
- $hash{'storectr'}++;
- }
- if ($ahash{$key} eq '0') {
- if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
- delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
- }
- }
- }
- # deleting the previously cached listing
- foreach (keys %hash) {
- if ($_ =~ /^pre_/ && $_ =~/link$/) {
- my $key = $_;
- $key =~ s/^pre_//;
- $key =~ s/_[^_]*$//;
- delete $hash{'pre_'.$key.'_title'};
- delete $hash{'pre_'.$key.'_link'};
- }
- }
+ &Apache::groupsort::update_actions_hash(\%hash);
}
# ---------------------------------- get state of file attributes to be showing