line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::MetadataDB; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
3
|
|
|
|
|
|
|
require Exporter; |
4
|
|
|
|
|
|
|
require CGI::Application; |
5
|
1
|
|
|
1
|
|
901
|
use LEOCHARRE::DEBUG; |
|
1
|
|
|
|
|
1851
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
111
|
use vars qw(@ISA $VERSION @EXPORT_OK @EXPORT); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
67
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# what modules does this code need |
9
|
1
|
|
|
1
|
|
940
|
use HTML::Template::Default 'get_tmpl'; |
|
1
|
|
|
|
|
22648
|
|
|
1
|
|
|
|
|
76
|
|
10
|
1
|
|
|
1
|
|
976
|
use CGI::Application::Plugin::Feedback; |
|
1
|
|
|
|
|
11734
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
226
|
use CGI::Application::Plugin::Session; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
89
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2260
|
|
15
|
|
|
|
|
|
|
# this sets default |
16
|
|
|
|
|
|
|
__PACKAGE__->_set_class_defaults( |
17
|
|
|
|
|
|
|
mdw_per_page_limit => 100, |
18
|
|
|
|
|
|
|
mdw_result_code => ' |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
id |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
', |
24
|
|
|
|
|
|
|
mdw_search_results_tmpl_name => 'mdw.search_results.html', |
25
|
|
|
|
|
|
|
mdw_search_tmpl_name => 'mdw.search.html', |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# export... |
30
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
31
|
|
|
|
|
|
|
@EXPORT_OK = qw(mds_object |
32
|
|
|
|
|
|
|
mdw_per_page_limit |
33
|
|
|
|
|
|
|
mdw_process_search |
34
|
|
|
|
|
|
|
mdw_record_params |
35
|
|
|
|
|
|
|
mdw_records_loop |
36
|
|
|
|
|
|
|
mdw_result_code |
37
|
|
|
|
|
|
|
mdw_results_loop_detailed |
38
|
|
|
|
|
|
|
mdw_search_args_submitted |
39
|
|
|
|
|
|
|
mdw_search_results_tmpl |
40
|
|
|
|
|
|
|
mdw_search_results_tmpl_name |
41
|
|
|
|
|
|
|
mdw_search_results_tmpl_code |
42
|
|
|
|
|
|
|
mdw_search_tmpl |
43
|
|
|
|
|
|
|
mdw_search_tmpl_name); |
44
|
|
|
|
|
|
|
@EXPORT = @EXPORT_OK; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _set_class_defaults { |
49
|
1
|
|
|
1
|
|
3
|
my $class = shift; |
50
|
1
|
|
|
|
|
5
|
my %arg = @_; |
51
|
1
|
|
|
|
|
7
|
while( my($k,$v) = each %arg ){ |
52
|
4
|
|
|
|
|
5
|
${"$class\::$k"} = $v; |
|
4
|
|
|
|
|
19
|
|
53
|
4
|
|
|
|
|
8
|
_make_class_accessor_setget($class,$k); |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
3
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _make_class_accessor_setget { |
59
|
4
|
|
|
4
|
|
6
|
my($class,$name)= @_; |
60
|
4
|
50
|
|
|
|
7
|
defined $class or die; |
61
|
4
|
50
|
|
|
|
11
|
defined $name or die; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
25
|
*{"$class\::$name"} = |
64
|
|
|
|
|
|
|
sub { |
65
|
0
|
|
|
0
|
|
|
my ($self,$val) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if( defined $val ){ |
68
|
|
|
|
|
|
|
# store it in object only |
69
|
0
|
|
|
|
|
|
$self->{$name} = $val; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
unless( defined $self->{$name} ){ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# check if it's defined in the class default |
75
|
0
|
0
|
|
|
|
|
if( defined ${"$class\::$name"} ){ |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->{$name} = ${"$class\::$name"}; |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return $self->{$name}; |
80
|
4
|
|
|
|
|
15
|
}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub mdw_search_tmpl { |
87
|
0
|
|
|
0
|
1
|
|
my ($self,$tmpl) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if(defined $tmpl){ |
90
|
0
|
|
|
|
|
|
$self->{_mdw_search_tmpl} =$tmpl; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
unless( $self->{_mdw_search_tmpl} ){ |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
$ENV{HTML_TEMPLATE_ROOT} or die('$ENV{HTML_TEMPLATE_ROOT} is not set'); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $filename = $self->mdw_search_tmpl_name; |
98
|
0
|
0
|
|
|
|
|
$self->feedback("trying for tmpl '$filename'") if DEBUG; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $abs = "$ENV{HTML_TEMPLATE_ROOT}/$filename"; |
101
|
0
|
0
|
|
|
|
|
-f $abs or die("$abs not on disk, missing $filename |
102
|
|
|
|
|
|
|
in HTML_TEMPLATE_ROOT, please see Metadata::DB::WUI"); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
debug("found '$abs'"); |
105
|
0
|
|
|
|
|
|
require HTML::Template::Default; |
106
|
0
|
|
|
|
|
|
my $tmpl = HTML::Template::Default::get_tmpl($filename); |
107
|
0
|
|
|
|
|
|
$self->{_mdw_search_tmpl} = $tmpl; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
return $self->{_mdw_search_tmpl}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub mdw_search_results_tmpl { |
113
|
0
|
|
|
0
|
1
|
|
my($self,$tmpl) = @_; |
114
|
0
|
0
|
|
|
|
|
if(defined $tmpl){ |
115
|
0
|
|
|
|
|
|
$self->{_mdw_search_results_tmpl} = $tmpl; |
116
|
|
|
|
|
|
|
} |
117
|
0
|
0
|
|
|
|
|
unless( $self->{_mdw_search_results_tmpl} ){ |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $filename = $self->mdw_search_results_tmpl_name; |
120
|
0
|
|
|
|
|
|
my $default_code = $self->mdw_search_results_tmpl_code; |
121
|
0
|
0
|
|
|
|
|
$self->feedback("trying for tmpl '$filename'") if DEBUG; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
require HTML::Template::Default; |
124
|
0
|
|
|
|
|
|
my $tmpl = HTML::Template::Default::get_tmpl($filename,\$default_code); |
125
|
0
|
|
|
|
|
|
$self->{_mdw_search_results_tmpl} = $tmpl; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return $self->{_mdw_search_results_tmpl}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# TEMPLATES ............................... |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub mdw_search_results_tmpl_code { |
140
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $rc = $self->mdw_result_code; |
142
|
0
|
|
|
|
|
|
my $default_code = qq{ |
143
|
|
|
|
|
|
|
$rc |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
}; |
146
|
0
|
|
|
|
|
|
return $default_code; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# end templates -------------------------------------------------------------------- |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# START GET ARGS ////////////////////////////////////////// ////////////////////////// |
162
|
|
|
|
|
|
|
# the output of this is fed to Metadata::DB::Search::search() |
163
|
|
|
|
|
|
|
sub mdw_search_args_submitted { |
164
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
165
|
0
|
|
|
|
|
|
my %h=(); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# the form needs to list what the attribute params are.. |
168
|
|
|
|
|
|
|
# this means though, that we cannot reload a search without posting |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# DONT MESS WITH THIS |
171
|
0
|
|
|
|
|
|
require Metadata::DB::Search::InterfaceHTML; |
172
|
0
|
|
|
|
|
|
my $PREPEND_FIELD_NAME = $Metadata::DB::Search::InterfaceHTML::PREPEND_FIELD_NAME; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $prepend = $self->query->param($PREPEND_FIELD_NAME); |
175
|
0
|
0
|
0
|
|
|
|
$prepend |
176
|
|
|
|
|
|
|
or warn("missing ($PREPEND_FIELD_NAME:$prepend) in post data") |
177
|
|
|
|
|
|
|
and return; |
178
|
0
|
|
|
|
|
|
debug("prepend $PREPEND_FIELD_NAME = $prepend"); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
0
|
|
|
|
my @a = $self->query->param( "$prepend\_attribute") |
182
|
|
|
|
|
|
|
or debug("No search params requested. Missing [$prepend\_attribute] in form.") |
183
|
|
|
|
|
|
|
and return; |
184
|
|
|
|
|
|
|
|
185
|
0
|
0
|
0
|
|
|
|
unless ( defined @a and scalar @a ){ |
186
|
0
|
|
|
|
|
|
debug('no search params requested'); |
187
|
0
|
|
|
|
|
|
$self->feedback('No search params requested.'); |
188
|
0
|
|
|
|
|
|
return; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my $message; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
ATT: for my $key (@a){ |
194
|
0
|
|
|
|
|
|
my $val = $self->query->param("$prepend\_$key"); |
195
|
0
|
0
|
0
|
|
|
|
defined $val and $val=~/\w/ or next ATT; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $type = $self->query->param("$prepend\_$key\_match_type"); |
198
|
0
|
0
|
|
|
|
|
$type or warn("no type in $type"); |
199
|
0
|
|
0
|
|
|
|
$type ||='like'; |
200
|
|
|
|
|
|
|
#TODO this is not working |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
$h{"$key:$type"} = $val; |
203
|
0
|
|
|
|
|
|
debug("search param: $key ($type) $val"); |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$self->feedback("You searched for '$key' ($type) '$val'"); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
0
|
0
|
0
|
|
|
|
%h or $self->feedback('No search params requested and resolved.') and return; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
return \%h; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# END GeT ARGS ///////////////////////////////////////////// /////////////// |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#*mdw_results_loop_detailed = \&mdw_results_loop; |
217
|
|
|
|
|
|
|
sub mdw_results_loop_detailed { |
218
|
0
|
|
|
0
|
1
|
|
my ($self,$mds) = @_; |
219
|
0
|
|
0
|
|
|
|
$mds ||= $self->mds_object; |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
my @ids = @{$mds->ids}; |
|
0
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $count = $mds->ids_count; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my $limit = $self->mdw_per_page_limit; |
225
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
$self->feedback("Found $count results."); |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
if( $count > $limit ){ |
229
|
0
|
|
|
|
|
|
$#ids = ($limit - 1); |
230
|
0
|
|
|
|
|
|
debug("results count $count is more then limit $limit, will prune down"); |
231
|
0
|
|
|
|
|
|
$self->feedback("Showing $limit results."); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
my $loop = $self->mdw_records_loop( \@ids ); |
235
|
0
|
|
|
|
|
|
return $loop; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# returns vars for html template in a hashref |
239
|
|
|
|
|
|
|
sub mdw_record_params { |
240
|
0
|
|
|
0
|
1
|
|
my ($self,$id) = @_; |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
my $mds = $self->mds_object; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
my $meta={ |
245
|
|
|
|
|
|
|
id => $id, |
246
|
|
|
|
|
|
|
}; |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $hash = $mds->_record_entries_hashref($id); |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $ul = "\t |
251
|
0
|
|
|
|
|
|
for ( sort keys %$hash ){ |
252
|
0
|
0
|
|
|
|
|
unless( $_=~/_path$/ ){ # maybe have a regex for this |
253
|
0
|
|
|
|
|
|
$ul.="\t\t".$_ .' : '. $hash->{$_}->[0] ."\n"; |
254
|
|
|
|
|
|
|
} |
255
|
0
|
|
|
|
|
|
$meta->{'meta_'.$_} = $hash->{$_}->[0]; |
256
|
|
|
|
|
|
|
} |
257
|
0
|
|
|
|
|
|
$ul.="\t\n"; |
258
|
0
|
|
|
|
|
|
$meta->{meta_as_ul_html} = $ul; |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
return $meta; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub mdw_records_loop { |
265
|
0
|
|
|
0
|
1
|
|
my($self,$ids) = @_; #search object |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
my $mds = $self->mds_object; |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
my @results_loop = (); |
270
|
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
|
my $i; |
272
|
0
|
|
|
|
|
|
for my $id ( @{$ids} ){ |
|
0
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
my $record_meta = $self->mdw_record_params($id); |
274
|
0
|
|
|
|
|
|
$record_meta->{list_index} = ++$i; |
275
|
0
|
|
|
|
|
|
push @results_loop, $record_meta; |
276
|
|
|
|
|
|
|
} |
277
|
0
|
|
|
|
|
|
return \@results_loop; |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# get a Metadata::DB::Search object, cached |
284
|
|
|
|
|
|
|
sub mds_object { |
285
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
0
|
0
|
|
|
|
|
unless( $self->{_mdsearch_object} ){ |
290
|
0
|
|
|
|
|
|
require Metadata::DB::Search; |
291
|
0
|
|
|
|
|
|
my $dbh = $self->param('DBH'); |
292
|
0
|
0
|
|
|
|
|
$dbh or die('missing DBH in param'); |
293
|
0
|
|
|
|
|
|
debug('DBH has '. ref $dbh); |
294
|
|
|
|
|
|
|
|
295
|
0
|
0
|
|
|
|
|
$self->{_mdsearch_object} = Metadata::DB::Search->new({ DBH => $self->param('DBH') }) |
296
|
|
|
|
|
|
|
or die; |
297
|
|
|
|
|
|
|
} |
298
|
0
|
|
|
|
|
|
return $self->{_mdsearch_object}; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub mdw_process_search { |
303
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# get search params |
306
|
0
|
0
|
|
|
|
|
my $search_args = $self->mdw_search_args_submitted |
307
|
|
|
|
|
|
|
or return 0; |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
#get the search object |
310
|
0
|
0
|
|
|
|
|
my $mds = $self->mds_object |
311
|
|
|
|
|
|
|
or return; |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
# feed it |
314
|
0
|
0
|
|
|
|
|
unless( $mds->search($search_args) ) { |
315
|
0
|
|
|
|
|
|
$self->feedback('Something went wrong with the search.'); |
316
|
0
|
|
|
|
|
|
$self->feedback('Please wait and try again, or contact the system administrator.'); |
317
|
0
|
|
|
|
|
|
return; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
return 1; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
1; |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
__END__ |