source: trunk/niupepa/perllib/classify/NPepaList.pm@ 13309

Last change on this file since 13309 was 13309, checked in by nzdl, 17 years ago

add an empty mathod into NPepaList.pm

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1###########################################################################
2#
3# NpepaList.pm -- website plugin
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 1999 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26
27# There should probably be a general classifier to do this kind of stuff
28
29package NPepaList;
30
31sub new {
32 my ($class, @options) = @_;
33
34 return bless {
35 'list'=>{},
36 'metaname' => 'Series',
37 'sortname' => 'Date'
38 }, $class;
39}
40
41sub init {
42 my $self = shift (@_);
43
44 $self->{'list'} = {};
45}
46
47
48sub classify {
49 my $self = shift (@_);
50 my ($doc_obj) = @_;
51
52 my $doc_OID = $doc_obj->get_OID();
53
54 # want to ignore abstracts
55 my $doctype = $doc_obj->get_metadata_element($doc_obj->get_top_section(), 'doctype');
56 return if (defined $doctype && $doctype eq 'Description');
57
58 my $date = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
59 $self->{'sortname'});
60 # commentaries have no date but we want them to sort to the top
61 $date = '00000000' unless defined $date;
62
63 my $series = $doc_obj->get_metadata_element ($doc_obj->get_top_section(),
64 $self->{'metaname'});
65
66 if (defined $series) {
67 if (!defined $self->{'list'}->{$series}) {
68 $self->{'list'}->{$series} = {};
69 }
70 if (defined $self->{'list'}->{$series}->{$doc_OID}) {
71 print STDERR "WARNING: NPepaList::classify called multiple times for $doc_OID\n";
72 }
73 $self->{'list'}->{$series}->{$doc_OID} = $date;
74 } else {
75 print STDERR "WARNING: NpepaList::classify $doc_OID has no Series metadata\n";
76 }
77}
78
79
80sub bydate {
81 # series names are expected to end with their date
82 my ($adate) = $a =~ /([\d-]+)$/;
83 my ($bdate) = $b =~ /([\d-]+)$/;
84 $adate =~ s/-\d+$//;
85 $bdate =~ s/-\d+$//;
86 return $adate <=> $bdate;
87}
88
89sub get_classify_info {
90 my $self = shift (@_);
91
92 my $classifyinfo = $self->get_entry ('Series', 'VList', 'Invisible');
93
94 foreach $series (sort bydate keys %{$self->{'list'}}) {
95 my $cinfo = $self->get_entry ($series, 'VList');
96 foreach $OID (sort {$self->{'list'}->{$series}->{$a}
97 cmp $self->{'list'}->{$series}->{$b};} keys %{$self->{'list'}->{$series}}) {
98 push (@{$cinfo->{'contains'}}, {'OID'=>$OID});
99 }
100 push (@{$classifyinfo->{'contains'}}, $cinfo);
101 }
102
103 return $classifyinfo;
104}
105
106sub get_entry {
107 my $self = shift (@_);
108 my ($title, $childtype, $thistype) = @_;
109
110 # organise into classification structure
111 my %classifyinfo = ('childtype'=>$childtype,
112 'Title'=>$title,
113 'contains'=>[]);
114 $classifyinfo{'thistype'} = $thistype
115 if defined $thistype && $thistype =~ /\w/;
116
117 return \%classifyinfo;
118}
119
120sub set_number{
121 return;
122}
123
1241;
Note: See TracBrowser for help on using the repository browser.