1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
package Arh::Model::Picture; |
5 |
use Jifty::DBI::Schema; |
6 |
use File::Find; |
7 |
use Data::Dump qw/dump/; |
8 |
|
9 |
use Arh::Record schema { |
10 |
|
11 |
column filename => |
12 |
label is _("Picture filename"); |
13 |
# is immutable, |
14 |
# is indexed, |
15 |
# is unique; |
16 |
|
17 |
column content => |
18 |
label is _('Picture'), |
19 |
type is 'bytea', |
20 |
# render as 'Upload', |
21 |
render as 'Arh::Web::Form::Field::Upload', |
22 |
is mandatory; |
23 |
|
24 |
column campaign => |
25 |
label is _("Part of campaign"), |
26 |
refers_to Arh::Model::Campaign, |
27 |
is mandatory, |
28 |
is indexed, |
29 |
since '0.0.4'; |
30 |
|
31 |
column type => |
32 |
label is _("Type of picture"), |
33 |
refers_to Arh::Model::PictureType, |
34 |
is mandatory, |
35 |
is indexed, |
36 |
since '0.0.4'; |
37 |
|
38 |
column unit => |
39 |
label is _('Unit'), |
40 |
refers_to Arh::Model::Unit, |
41 |
is mandatory, |
42 |
is indexed; |
43 |
|
44 |
column thumbnail => |
45 |
label is _('Thumbnail name'), |
46 |
is indexed, |
47 |
since '0.0.12'; |
48 |
|
49 |
column width => |
50 |
label is _('Thumbnail width'), |
51 |
type is 'int', |
52 |
since '0.0.12'; |
53 |
|
54 |
column height => |
55 |
label is _('Thumbnail height'), |
56 |
type is 'int', |
57 |
since '0.0.12'; |
58 |
|
59 |
}; |
60 |
|
61 |
# Your model-specific methods go here. |
62 |
|
63 |
sub all_filenames { |
64 |
|
65 |
my @files; |
66 |
my $path = Jifty::Util->app_root . '/share/web/static/pics'; |
67 |
|
68 |
# warn "## path = $path"; |
69 |
|
70 |
find({ wanted => sub { |
71 |
my $f = $File::Find::name; |
72 |
return unless -f $f; |
73 |
push @files, $_; |
74 |
}, follow => 0 }, $path); |
75 |
|
76 |
# warn "## all_filenames = ",dump( @files ); |
77 |
|
78 |
return @files; |
79 |
} |
80 |
|
81 |
#use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on |
82 |
|
83 |
use Arh::DefaultACL; |
84 |
|
85 |
1; |
86 |
|