Changeset 27308

Show
Ignore:
Timestamp:
07.05.2013 14:22:32 (6 years ago)
Author:
kjdon
Message:

fixed up DateList? so that reverse sort works properly when years are grouped together.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/classify/DateList.pm

    r23116 r27308  
    144144    }  
    145145     
    146     #my $date = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), $self->{'metadata'}); 
    147146    if (!defined $date || $date eq "") { 
    148147    # if this document doesn't contain Date element we won't  
     
    150149    return; 
    151150    } 
    152      
     151 
    153152    my $sort_other = ""; 
    154153    if (defined $self->{'sort'} && $self->{'sort'} ne "") { 
     
    161160    print $outhandle "WARNING: DateList::classify called multiple times for $doc_OID\n"; 
    162161    }  
    163     
    164       
     162         
    165163    $self->{'list'}->{$doc_OID} = "$date$sort_other"; 
    166164 
     
    237235        } 
    238236         
    239     } else { # don't group - individual years and months 
     237    } else { # -nogroup - individual years and months 
    240238        foreach my $classification (@$classlistref) { 
    241239        my $date = $self->{'list'}->{$classification}; 
     
    256254        # create hlist of years containing hlists of months 
    257255 
     256        my @subclasslist = sort {$a <=> $b} (keys %$classhash); 
     257        if ($self->{'reverse_sort'}) { 
     258        @subclasslist = reverse @subclasslist; 
     259        } 
    258260         
    259         if ($self->{'reverse_sort'}){ 
    260                foreach my $subclass (sort {$b <=> $a}  
    261                     (keys %$classhash)){ 
     261        foreach my $subclass (@subclasslist) { 
    262262          my $yearclassify = $self->get_entry($subclass, "HList"); 
    263           foreach my $subsubclass (sort {$b <=> $a}  
    264                        (keys %{$classhash->{$subclass}})) { 
     263          my @subsubclasslist = sort {$a <=> $b} (keys %{$classhash->{$subclass}}); 
     264          if ($self->{'reverse_sort'}) { 
     265              @subsubclasslist = reverse @subsubclasslist; 
     266          } 
     267 
     268          foreach my $subsubclass (@subsubclasslist) { 
    265269              my $monthname=$subsubclass; 
    266270              if ($monthname >= 1 && $monthname <= 12) { 
     
    277281          } 
    278282          push (@{$classifyinfo->{'contains'}}, $yearclassify); 
    279           } 
    280         } 
    281         else{ 
    282         foreach my $subclass (sort {$a <=> $b}  
    283                     (keys %$classhash)){ 
    284             my $yearclassify = $self->get_entry($subclass, "HList"); 
    285             foreach my $subsubclass (sort {$a <=> $b}  
    286                          (keys %{$classhash->{$subclass}})) { 
    287               my $monthname=$subsubclass; 
    288               if ($monthname >= 1 && $monthname <= 12) { 
    289               $monthname="_textmonth" . $monthname . "_"; 
    290               } 
    291               my $monthclassify=$self->get_entry($monthname, $self->{'childtype'}); 
    292               push (@{$yearclassify->{'contains'}}, $monthclassify); 
    293                
    294               foreach my $subsubOID  
    295               (@{$classhash->{$subclass}->{$subsubclass}}) { 
    296                   push (@{$monthclassify->{'contains'}}, 
    297                     {'OID'=>$subsubOID}); 
    298               } 
    299           } 
    300             push (@{$classifyinfo->{'contains'}}, $yearclassify); 
    301         } 
    302          
    303          
    304283        } 
    305284         
    306285        return $classifyinfo; 
    307286    } # nogroup 
    308     }else { 
     287    } else { 
    309288    # not by month 
    310289    # first split up the list into separate year classifications 
     
    322301    $classhash = $self->compactlist ($classhash); 
    323302    } 
    324  
    325     if ($self->{'reverse_sort'} && $self->{'nogroup'} ) { 
    326     foreach my $subclass (reverse sort keys %$classhash) { 
    327         my $tempclassify = $self->get_entry($subclass, $self->{'childtype'}); 
    328         foreach my $subsubOID (@{$classhash->{$subclass}}) { 
    329         push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID}); 
    330         } 
    331         push (@{$classifyinfo->{'contains'}}, $tempclassify); 
    332     } 
    333     } 
    334     else{ 
    335     foreach my $subclass (sort keys %$classhash) { 
    336         my $tempclassify = $self->get_entry($subclass, $self->{'childtype'}); 
    337         foreach my $subsubOID (@{$classhash->{$subclass}}) { 
    338         push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID}); 
    339         } 
    340         push (@{$classifyinfo->{'contains'}}, $tempclassify); 
    341     } 
    342  
    343     } 
    344      
     303    my @subclasslist = sort keys %$classhash; 
     304    if ($self->{'reverse_sort'}) { 
     305    @subclasslist = reverse @subclasslist; 
     306    } 
     307    foreach my $subclass (@subclasslist) { 
     308    my $tempclassify = $self->get_entry($subclass, $self->{'childtype'}); 
     309    foreach my $subsubOID (@{$classhash->{$subclass}}) { 
     310        push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID}); 
     311    } 
     312    push (@{$classifyinfo->{'contains'}}, $tempclassify); 
     313    } 
    345314   
    346315    return $classifyinfo; 
     
    363332    my $min = 10;  
    364333    my $max = 30; 
    365     foreach my $subsection (sort keys %$classhashref) { 
     334    my @subsectionlist = sort keys %$classhashref; 
     335    if ($self->{'reverse_sort'}) { 
     336    @subsectionlist = reverse @subsectionlist; 
     337    }  
     338    foreach my $subsection (@subsectionlist) { 
    366339    $currentfirstdate = $subsection if $currentfirstdate eq ""; 
    367340    if ((scalar (@currentOIDs) < $min) ||