]>
Commit | Line | Data |
---|---|---|
6430ee52 TC |
1 | package BSE::TB::ArticleFiles; |
2 | use strict; | |
3 | use Squirrel::Table; | |
4 | use vars qw(@ISA $VERSION); | |
5 | @ISA = qw(Squirrel::Table); | |
6 | use BSE::TB::ArticleFile; | |
7 | use Carp qw(confess); | |
8 | ||
9 | sub rowClass { | |
10 | return 'BSE::TB::ArticleFile'; | |
11 | } | |
12 | ||
13 | sub file_storages { | |
14 | my $self = shift; | |
15 | return map [ $_->{filename}, $_->{storage}, $_ ], $self->all; | |
16 | } | |
17 | ||
18 | sub categories { | |
19 | my ($class, $cfg) = @_; | |
20 | ||
21 | my @cat_ids = split /,/, $cfg->entry("article file categories", "ids", ""); | |
22 | grep $_ eq "", @cat_ids | |
23 | or unshift @cat_ids, ""; | |
24 | ||
25 | my @cats; | |
26 | for my $id (@cat_ids) { | |
27 | my $section = length $id ? "file category $id" : "file category empty"; | |
28 | my $def_name = length $id ? ucfirst $id : "(None)"; | |
29 | my $name = $cfg->entry($section, "name", $def_name); | |
30 | push @cats, +{ id => $id, name => $name }; | |
31 | } | |
32 | ||
33 | return @cats; | |
34 | } | |
35 | ||
36 | sub file_handlers { | |
37 | my ($self, $cfg) = @_; | |
38 | ||
39 | $cfg or confess "Missing cfg option"; | |
40 | ||
41 | my @handlers = split /[;,]/, $cfg->entry('basic', 'file_handlers'); | |
42 | push @handlers, ""; | |
43 | ||
44 | return map [ $_, $self->handler($_, $cfg) ], @handlers; | |
45 | } | |
46 | ||
47 | sub handler { | |
48 | my ($self, $id, $cfg) = @_; | |
49 | ||
50 | my $key = $id || "default"; | |
51 | my $class = $id ? $cfg->entry("file handlers", $id) : "BSE::FileHandler::Default"; | |
52 | ||
53 | (my $file = $class . ".pm") =~ s(::)(/)g; | |
54 | require $file; | |
55 | return $class->new($cfg); | |
56 | } | |
57 | ||
58 | sub download_path { | |
59 | my ($class, $cfg) = @_; | |
60 | ||
61 | return $cfg->entryVar('paths', 'downloads'); | |
62 | } | |
63 | ||
7646d96e TC |
64 | sub file_manager { |
65 | my ($self, $cfg) = @_; | |
66 | ||
67 | require BSE::StorageMgr::Files; | |
68 | ||
69 | return BSE::StorageMgr::Files->new(cfg => $cfg); | |
70 | } | |
71 | ||
36e373a9 TC |
72 | sub all_metametadata { |
73 | my ($self, $cfg) = @_; | |
74 | ||
75 | $cfg | |
76 | or confess "Missing cfg parameter"; | |
77 | ||
78 | require BSE::FileMetaMeta; | |
79 | my @metafields; | |
80 | my @keys = $cfg->orderCS("global file metadata"); | |
81 | for my $name (@keys) { | |
82 | my %opts = ( name => $name ); | |
83 | my $section = "file metadata $name"; | |
84 | for my $key (BSE::FileMetaMeta->keys) { | |
85 | my $value = $cfg->entry($section, $key); | |
86 | if (defined $value) { | |
87 | $opts{$key} = $value; | |
88 | } | |
89 | } | |
90 | push @metafields, BSE::FileMetaMeta->new(%opts, cfg => $cfg); | |
91 | } | |
92 | ||
93 | return @metafields; | |
94 | } | |
95 | ||
6430ee52 | 96 | 1; |