Changeset 11433


Ignore:
Timestamp:
2006-03-21T10:48:46+12:00 (18 years ago)
Author:
shaoqun
Message:

modified splitlist method to handle reverse_sort parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/classify/DateList.pm

    r10979 r11433  
    145145    print $outhandle "WARNING: DateList::classify called multiple times for $doc_OID\n";
    146146    }
    147 
     147   
     148     
    148149    $self->{'list'}->{$doc_OID} = "$date$sort_other";
    149    
     150
    150151}
    151152
     
    155156
    156157    my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};
     158
    157159    if ($self->{'reverse_sort'}) {
    158160    @classlist = reverse @classlist;
    159161    }
     162
    160163
    161164    return $self->splitlist (\@classlist);
     
    190193    if (scalar (@$classlistref) <= 39 &&
    191194    !$self->{'nogroup'}) {$childtype = "DateList";}
     195
    192196    my $classifyinfo = $self->get_entry ("Date", $childtype, "Invisible");
    193197    # don't need to do any splitting if there are less than 39 (max + min -1)
     
    228232        # create subclass if it doesn't already exist
    229233        $classhash->{$year} = () unless defined $classhash->{$year};
     234             
    230235        $classhash->{$year}->{$month} = []
    231236            unless defined $classhash->{$year}->{$month};
    232237        push (@{$classhash->{$year}->{$month}}, $classification);
     238
    233239        }
    234240        # create hlist of years containing hlists of months
    235241
    236         foreach my $subclass (sort {$a <=> $b} keys %$classhash) {
    237         my $yearclassify = $self->get_entry($subclass, "HList");
    238         foreach my $subsubclass (sort {$a <=> $b}
    239                      (keys %{$classhash->{$subclass}})) {
    240             my $monthname=$subsubclass;
    241             if ($monthname >= 1 && $monthname <= 12) {
    242             $monthname="_textmonth" . $monthname . "_";
    243             }
    244             my $monthclassify=$self->get_entry($monthname, "DateList");
    245             push (@{$yearclassify->{'contains'}}, $monthclassify);
     242       
     243        if ($self->{'reverse_sort'}){
     244               foreach my $subclass (sort {$b <=> $a}
     245                    (keys %$classhash)){
     246          my $yearclassify = $self->get_entry($subclass, "HList");
     247          foreach my $subsubclass (sort {$b <=> $a}
     248                       (keys %{$classhash->{$subclass}})) {
     249              my $monthname=$subsubclass;
     250              if ($monthname >= 1 && $monthname <= 12) {
     251              $monthname="_textmonth" . $monthname . "_";
     252              }
     253              my $monthclassify=$self->get_entry($monthname, "DateList");
     254              push (@{$yearclassify->{'contains'}}, $monthclassify);
     255             
     256              foreach my $subsubOID
     257              (@{$classhash->{$subclass}->{$subsubclass}}) {
     258                  push (@{$monthclassify->{'contains'}},
     259                  {'OID'=>$subsubOID});
     260              }
     261          }
     262          push (@{$classifyinfo->{'contains'}}, $yearclassify);
     263          }
     264        }
     265        else{
     266        foreach my $subclass (sort {$a <=> $b}
     267                    (keys %$classhash)){
     268            my $yearclassify = $self->get_entry($subclass, "HList");
     269            foreach my $subsubclass (sort {$a <=> $b}
     270                         (keys %{$classhash->{$subclass}})) {
     271              my $monthname=$subsubclass;
     272              if ($monthname >= 1 && $monthname <= 12) {
     273              $monthname="_textmonth" . $monthname . "_";
     274              }
     275              my $monthclassify=$self->get_entry($monthname, "DateList");
     276              push (@{$yearclassify->{'contains'}}, $monthclassify);
     277             
     278              foreach my $subsubOID
     279              (@{$classhash->{$subclass}->{$subsubclass}}) {
     280                  push (@{$monthclassify->{'contains'}},
     281                    {'OID'=>$subsubOID});
     282              }
     283          }
     284            push (@{$classifyinfo->{'contains'}}, $yearclassify);
     285        }
    246286       
    247             foreach my $subsubOID
    248             (@{$classhash->{$subclass}->{$subsubclass}}) {
    249                 push (@{$monthclassify->{'contains'}},
    250                   {'OID'=>$subsubOID});
    251             }
    252         }
    253         push (@{$classifyinfo->{'contains'}}, $yearclassify);
    254         }
     287       
     288        }
     289       
    255290        return $classifyinfo;
    256291    } # nogroup
    257     } else {
     292    }else {
    258293    # not by month
    259294    # first split up the list into separate year classifications
     
    264299        push (@{$classhash->{$date}}, $classification);
    265300    }
     301         
    266302    }
    267303   
     
    270306    $classhash = $self->compactlist ($classhash);
    271307    }
    272     foreach my $subclass (sort keys %$classhash) {
    273     my $tempclassify = $self->get_entry($subclass, "DateList");
    274     foreach my $subsubOID (@{$classhash->{$subclass}}) {
    275         push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
    276     }
    277     push (@{$classifyinfo->{'contains'}}, $tempclassify);
    278     }
    279 
     308
     309    if ($self->{'reverse_sort'} && $self->{'nogroup'} ) {
     310    foreach my $subclass (reverse sort keys %$classhash) {
     311        my $tempclassify = $self->get_entry($subclass, "DateList");
     312        foreach my $subsubOID (@{$classhash->{$subclass}}) {
     313        push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
     314        }
     315        push (@{$classifyinfo->{'contains'}}, $tempclassify);
     316    }
     317    }
     318    else{
     319    foreach my $subclass (sort keys %$classhash) {
     320        my $tempclassify = $self->get_entry($subclass, "DateList");
     321        foreach my $subsubOID (@{$classhash->{$subclass}}) {
     322        push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
     323        }
     324        push (@{$classifyinfo->{'contains'}}, $tempclassify);
     325    }
     326
     327    }
     328   
     329 
    280330    return $classifyinfo;
    281331}
Note: See TracChangeset for help on using the changeset viewer.