Changeset 3639


Ignore:
Timestamp:
2003-01-03T10:03:31+13:00 (21 years ago)
Author:
kjdon
Message:

modified the default sorting element, and fixed a bug.

File:
1 edited

Legend:

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

    r3540 r3639  
    9393
    9494   -metadata X    Metadata field used for classification,
    95                   list will be sorted by this element.
     95                  list will be sorted by this element,
     96                  unless -sort is used.
    9697
    9798   -hfile X       The classification structure file
    9899
    99    -sort X        Metadata field to sort by (defaults to none)
     100   -sort X        Metadata field to sort by (defaults to -metadata)
     101                  use '-sort nosort' for no sorting.
    100102
    101103   -hlist_at_top  Display the first level of the classification
     
    109111    my $self = new BasClas($class, @_);
    110112 
    111     # 14-05-02 To allow for proper inheritance of arguments - John Thompson
    112     my $option_list = $self->{'option_list'};
    113     push( @{$option_list}, $options );
     113    # 14-05-02 To allow for proper inheritance of arguments - John Thompson
     114    my $option_list = $self->{'option_list'};
     115    push( @{$option_list}, $options );
    114116   
    115     my $sortname = "Title";
    116     my ($hfile, $metadata, $title, $hlist_at_top);
    117 
     117    my ($hfile, $metadata, $sortname, $title, $hlist_at_top);
     118   
    118119    if (!parsargv::parse(\@_,
    119120             q^buttonname/.*/^, \$title,
    120              q^sort/.*/nosort^, \$sortname,
     121             q^sort/.*/^, \$sortname,
    121122             q^hfile/.*/^, \$hfile,
    122123             q^metadata/.*/^, \$metadata,
     
    124125             "allow_extra_options")) {
    125126   
    126           $self->{'construction_error'} = "Incorrect options passed to $class, check your collect.cfg file.";
     127    $self->{'construction_error'} = "Incorrect options passed to $class, check your collect.cfg file.";
    127128    }
    128129
    129130    if (!$metadata) {
    130           $self->{'construction_error'} = "Hierarchy error: no metadata supplied.";
    131     }
    132 
     131    $self->{'construction_error'} = "Hierarchy error: no metadata supplied.";
     132    }
     133   
    133134    $title = $metadata unless ($title);
    134 
     135    # if no sortname specified, it defaults to metadata
     136    $sortname = $metadata unless ($sortname);
    135137    $sortname = undef if $sortname =~ /^nosort$/;
    136 
    137      my $subjectfile;
     138    my $subjectfile;
    138139
    139140    if (!$hfile) {
    140           $self->{'construction_error'} = "Hierarchy error: No -hfile supplied.";
     141    $self->{'construction_error'} = "Hierarchy error: No -hfile supplied.";
    141142    }
    142143    else
    143     {
    144           $subjectfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"etc", $hfile);
    145           if (!-e $subjectfile) {
    146                 my $collfile = $subjectfile;
    147                 $subjectfile = &util::filename_cat($ENV{'GSDLHOME'},"etc", $hfile);
    148                 if (!-e $subjectfile) {
    149                      my $outhandle = $self->{'outhandle'};
    150                      &print_usage;
    151                      print STDERR "\nHierarchy Error: Can't locate subject file $hfile\n";
    152                      print STDERR "This file should be in $collfile or $subjectfile\n";
    153                      die "\n";
    154                 }
    155           }
    156     }
    157 
     144    {
     145    $subjectfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"etc", $hfile);
     146    if (!-e $subjectfile) {
     147        my $collfile = $subjectfile;
     148        $subjectfile = &util::filename_cat($ENV{'GSDLHOME'},"etc", $hfile);
     149        if (!-e $subjectfile) {
     150        my $outhandle = $self->{'outhandle'};
     151        &print_usage;
     152        print STDERR "\nHierarchy Error: Can't locate subject file $hfile\n";
     153        print STDERR "This file should be in $collfile or $subjectfile\n";
     154        die "\n";
     155        }
     156    }
     157    }
     158   
    158159    $self->{'descriptorlist'} = {}; # first field in subject file
    159160    $self->{'locatorlist'} = {}; # second field in subject file
     
    169170sub init {
    170171    my $self = shift (@_);
    171 
    172     if(defined $self->{'construction_error'} || !defined $self->{'metaname'} || !defined $self->{'subjectfile'}) {
    173           print STDERR "Error: " , $self->{'construction_error'} , "\n";
    174           &print_usage;
    175           die "\n";
    176     }
    177 
     172   
     173    if(defined $self->{'construction_error'} || !defined $self->{'metaname'} || !defined $self->{'subjectfile'}) {
     174    print STDERR "Error: " , $self->{'construction_error'} , "\n";
     175    &print_usage;
     176    die "\n";
     177    }
     178   
    178179    # read in the subject file
    179180    my $list = &cfgread::read_cfg_file ($self->{'subjectfile'}, undef, '^[^#]?\w');
     
    194195    my $self = shift (@_);
    195196    my ($doc_obj) = @_;
    196 
     197   
    197198    my $doc_OID = $doc_obj->get_OID();
    198 
     199   
    199200    my $metadata = $doc_obj->get_metadata ($doc_obj->get_top_section(),
    200201                       $self->{'metaname'});
    201 
     202   
    202203    my $sortmeta = "";
    203204    if (defined $self->{'sortname'}) {
     
    217218    $sortmeta = "" unless defined $sortmeta;
    218219    }
    219 
     220   
    220221    foreach $metaelement (@$metadata) {
    221222    if ((defined $self->{'descriptorlist'}->{$metaelement}) &&
     
    231232   
    232233    my $list = $self->{'locatorlist'};
    233 
     234   
    234235    my ($classifyinfo);
    235236    if ($self->{'hlist_at_top'}) {
     
    238239    $classifyinfo = $self->get_entry ($self->{'title'}, "VList", "Invisible");
    239240    }
    240 
    241     foreach $OID (keys (%$list)) {
    242 
     241    # sorted the keys - otherwise funny things happen - kjdon 03/01/03
     242    foreach $OID (sort keys (%$list)) {
    243243    my $tempinfo = $self->get_OID_entry ($OID, $classifyinfo, $list->{$OID}->{'title'}, "VList");
    244 
     244   
    245245    if (defined $self->{'sortname'}) {
    246246        foreach $subOID (sort {$a->[1] cmp $b->[1];} @{$list->{$OID}->{'contents'}}) {
Note: See TracChangeset for help on using the changeset viewer.