Changeset 6081


Ignore:
Timestamp:
2003-12-02T15:05:23+13:00 (20 years ago)
Author:
jrm21
Message:

rename "nogroupyear" option to "nogroup" as it can now be used with the
"bymonth" option... bymonth by itself will group year+month entries in the
hlist, and combined will create an hlist of years then a separate hlist of
months.

File:
1 edited

Legend:

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

    r6065 r6081  
    3737# 23/09/03 Added some more options -kjdon.
    3838# these include:
    39 # -nogroupyears, which makes each year an individual entry in
     39# -nogroup, which makes each year (or year+month) an individual entry in
    4040# the horizontal list and prevents compaction
    4141# -datemeta, use a different metadata for the date (instead of Date), still expects yyyymmdd format. this affects display cos greenstone displays Date metadata as dd month yyyy, whereas any other date metadata is displayed as yyyymmdd - this needs fixing
     
    5757    'reqd' => "no" },
    5858
    59       { 'name' => "nogroupyears",
    60     'desc' => "{DateList.nogroupyears}",
     59      { 'name' => "nogroup",
     60    'desc' => "{DateList.nogroup}",
    6161    'type' => "flag",
    6262    'reqd' => "no" },
     
    9090
    9191    my ($datemeta, $sortmeta);
    92     $self->{'nogroupyears'}=0;
     92    $self->{'nogroup'}=0;
    9393    if (!parsargv::parse(\@_,
    9494                         q^bymonth^, \$self->{'bymonth'},
    95              q^nogroupyears^, \$self->{'nogroupyears'},
     95             q^nogroup^, \$self->{'nogroup'},
    9696             q^datemeta/.*/^, \$datemeta,
    9797             q^sortmeta/.*/^, \$sortmeta,
     
    177177
    178178    if (scalar (@$classlistref) <= 39 &&
    179     !$self->{'nogroupyears'}) {$childtype = "DateList";}
     179    !$self->{'nogroup'}) {$childtype = "DateList";}
    180180    my $classifyinfo = $self->get_entry ("Date", $childtype, "Invisible");
    181181
    182182    # don't need to do any splitting if there are less than 39 (max + min -1)
    183     # classifications, unless nogroupyears is specified
    184     if ((scalar @$classlistref) <= 39 && !$self->{'nogroupyears'}) {
     183    # classifications, unless nogroup is specified
     184    if ((scalar @$classlistref) <= 39 && !$self->{'nogroup'}) {
    185185    foreach $subOID (@$classlistref) {
    186186        push (@{$classifyinfo->{'contains'}}, {'OID'=>$subOID});
     
    192192    if ($self->{'bymonth'}) {
    193193    # first split up the list into separate year+month classifications
    194     foreach $classification (@$classlistref) {
    195         my $date = $self->{'list'}->{$classification};
    196         $date =~ s/^(\d\d\d\d)(\d\d).*$/$1&nbsp;_textmonth$2_/;
    197         # sanity check if month is zero
    198         if ($date =~ /00_$/) {
    199         $date =~ s/^(\d\d\d\d).*$/$1/g;
     194
     195    if (!$self->{'nogroup'}) { # hlist of year+month pairs
     196        # single level of classifications
     197        foreach $classification (@$classlistref) {
     198        my $date = $self->{'list'}->{$classification};
     199        $date =~ s/^(\d\d\d\d)(\d\d).*$/$1&nbsp;_textmonth$2_/;
     200        # sanity check if month is zero
     201        if ($date =~ /00_$/) {
     202            $date =~ s/^(\d\d\d\d).*$/$1/g;
     203        }
     204        $classhash->{$date} = [] unless defined $classhash->{$date};
     205        push (@{$classhash->{$date}}, $classification);
    200206        }
    201         $classhash->{$date} = [] unless defined $classhash->{$date};
    202         push (@{$classhash->{$date}}, $classification);
    203     }
     207       
     208    } else { # don't group - individual years and months
     209        foreach $classification (@$classlistref) {
     210        my $date = $self->{'list'}->{$classification};
     211        $date =~ s/^(\d\d\d\d)(\d\d).*$/$1&nbsp;_textmonth$2_/;
     212        my ($year, $month)=($1,$2);
     213        # sanity check if month is zero
     214        if ($date =~ /00_$/) {
     215            $date =~ s/^(\d\d\d\d).*$/$1/g;
     216        }
     217        # create subclass if it doesn't already exist
     218        $classhash->{$year} = () unless defined $classhash->{$year};
     219        $classhash->{$year}->{$month} = []
     220            unless defined $classhash->{$year}->{$month};
     221        push (@{$classhash->{$year}->{$month}}, $classification);
     222        }
     223        # create hlist of years containing hlists of months
     224
     225        foreach my $subclass (sort {$a <=> $b} keys %$classhash) {
     226        my $yearclassify = $self->get_entry($subclass, "HList");
     227        foreach my $subsubclass (sort {$a <=> $b}
     228                     (keys %{$classhash->{$subclass}})) {
     229            my $monthname=$subsubclass;
     230            if ($monthname >= 1 && $monthname <= 12) {
     231            $monthname="_textmonth" . $monthname . "_";
     232            }
     233            my $monthclassify=$self->get_entry($monthname, "DateList");
     234            push (@{$yearclassify->{'contains'}}, $monthclassify);
     235       
     236            foreach $subsubOID
     237            (@{$classhash->{$subclass}->{$subsubclass}}) {
     238                push (@{$monthclassify->{'contains'}},
     239                  {'OID'=>$subsubOID});
     240            }
     241        }
     242        push (@{$classifyinfo->{'contains'}}, $yearclassify);
     243        }
     244        # not sure if this is needed... AZCompactList has it :p
     245        $classifyinfo->{'mdtype'}=$self->{'datemeta'};
     246        return $classifyinfo;
     247    } # nogroup
    204248    } else {
     249    # not by month
    205250    # first split up the list into separate year classifications
    206251    foreach $classification (@$classlistref) {
     
    211256    }
    212257    }
    213 
    214     # only compact the list if nogroupyears not specified
    215     if (!$self->{'nogroupyears'}) {
     258   
     259    # only compact the list if nogroup not specified
     260    if (!$self->{'nogroup'}) {
    216261    $classhash = $self->compactlist ($classhash);
    217262    }
Note: See TracChangeset for help on using the changeset viewer.