Schema/Result/Media.pm

filter: Statementstmt 100% 37 / 37 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 3 / 3 totaltotal 100% 45 / 45 CC 2 SCAR 2.9
CC
2
Cov
100%
display_uris
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Schema/ResultSet/Navigation.pm ↑ Summary Schema/Result/Address.pm »
1 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Interchange6::Schema::Result::Media;
4  
5 =head1 NAME
6  
7 Interchange6::Schema::Result::Media
8  
9 =cut
10  
11 2 use Interchange6::Schema::Candy -components =>
12 2 ▶ [qw(InflateColumn::DateTime TimeStamp)];
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 ACCESSORS
15  
16 =head2 media_id
17  
18 Primary key.
19  
20 =cut
21  
22 2 primary_column media_id => {
23 data_type => "integer",
24 is_auto_increment => 1,
25 sequence => "media_media_id_seq",
26 };
27  
28 =head2 file
29  
30 The image/video file.
31  
32 Is nullable.
33  
34 =cut
35  
36 2 unique_column file => {
37 data_type => "varchar",
38 size => 255,
39 is_nullable => 1,
40 };
41  
42 =head2 uri
43  
44 The image/video uri.
45  
46 Defaults to empty string.
47  
48 =cut
49  
50 2 column uri => {
51 data_type => "varchar",
52 default_value => "",
53 size => 255
54 };
55  
56 =head2 mime_type
57  
58 Mime type.
59  
60 Defaults to empty string.
61  
62 =cut
63  
64 2 column mime_type => {
65 data_type => "varchar",
66 default_value => "",
67 size => 255
68 };
69  
70 =head2 label
71  
72 Label.
73  
74 Defaults to empty string.
75  
76 =cut
77  
78 2 column label => {
79 data_type => "varchar",
80 default_value => "",
81 size => 255
82 };
83  
84 =head2 author_users_id
85  
86 FK on L<Interchange6::Schema::Result::User/users_id>.
87  
88 =cut
89  
90 2 column author_users_id =>
91 { data_type => "integer", is_nullable => 1 };
92  
93 =head2 created
94  
95 Date and time when this record was created returned as L<DateTime> object.
96 Value is auto-set on insert.
97  
98 =cut
99  
100 2 column created =>
101 { data_type => "datetime", set_on_create => 1 };
102  
103 =head2 last_modified
104  
105 Date and time when this record was last modified returned as L<DateTime> object.
106 Value is auto-set on insert and update.
107  
108 =cut
109  
110 2 column last_modified => {
111 data_type => "datetime",
112 set_on_create => 1,
113 set_on_update => 1,
114 };
115  
116 =head2 active
117  
118 Boolean whether media is active. Defaults to true (1).
119  
120 =cut
121  
122 2 column active =>
123 { data_type => "boolean", default_value => 1 };
124  
125 =head2 media_types_id
126  
127 FK on L<Interchange6::Schema::Result::MediaType/media_types_id>.
128  
129 =cut
130  
131 2 column media_types_id =>
132 { data_type => "integer" };
133  
134 =head2 priority
135  
136 Priority for display. Defaults to 0.
137  
138 =cut
139  
140 2 column priority => { data_type => "integer", default_value => 0 };
141  
142 =head1 UNIQUE CONSTRAINTS
143  
144 =head2 C<media_id_media_types_id_unique>
145  
146 =over 4
147  
148 =item * L</media_id>
149  
150 =item * L</media_types_id>
151  
152 =back
153  
154 =cut
155  
156 2 unique_constraint media_id_media_types_id_unique =>
157 [ "media_id", "media_types_id" ];
158  
159 =head1 RELATIONS
160  
161 =head2 author
162  
163 Type: belongs_to
164  
165 Related object: L<Interchange6::Schema::Result::User>
166  
167 =cut
168  
169 2 belongs_to
170 author => "Interchange6::Schema::Result::User",
171 { "foreign.users_id" => "self.author_users_id" },
172 { join_type => "left" };
173  
174 =head2 media_type
175  
176 Type: belongs_to
177  
178 Related object: L<Interchange6::Schema::Result::MediaType>
179  
180 =cut
181  
182 2 belongs_to
183 media_type => "Interchange6::Schema::Result::MediaType",
184 "media_types_id",
185 { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" };
186  
187 =head2 media_products
188  
189 Type: has_many
190  
191 Related object: L<Interchange6::Schema::Result::MediaProduct>
192  
193 =cut
194  
195 2 has_many
196 media_products => "Interchange6::Schema::Result::MediaProduct",
197 "media_id",
198 { cascade_copy => 0, cascade_delete => 0 };
199  
200 =head2 media_navigations
201  
202 Type: has_many
203  
204 Related object: L<Interchange6::Schema::Result::MediaNavigation>
205  
206 =cut
207  
208 2 has_many
209 media_navigations => "Interchange6::Schema::Result::MediaNavigation",
210 "media_id",
211 { cascade_copy => 0, cascade_delete => 0 };
212  
213 =head2 media_messages
214  
215 Type: has_many
216  
217 Related object: L<Interchange6::Schema::Result::MediaMessage>
218  
219 =cut
220  
221 2 has_many
222 media_messages => "Interchange6::Schema::Result::MediaMessage",
223 "media_id",
224 { cascade_copy => 0, cascade_delete => 0 };
225  
226 =head2 products
227  
228 Type: many_to_many with product.
229  
230 =cut
231  
232 2 many_to_many products => "media_products", "product";
233  
234 =head2 displays
235  
236 Type: many_to_many with media_displays
237  
238 =cut
239  
240 2 many_to_many displays => "media_type", "media_displays";
241  
242 =head1 METHODS
243  
244 =head2 type
245  
246 Return the media type looking into MediaDisplay and MediaType.
247  
248 =cut
249  
250 sub type {
251 6 ▶ my $self = shift;
Subroutine type: called CC=1 SCAR=0.0
Pod documented
252  
253 # here we return just the first result. UNCLEAR if more are
254 # needed, but has many... Either we
255 6 return $self->media_type->type;
256 }
257  
258 =head2 display_uris
259  
260 Return an hashref with the media display type and the final uri.
261  
262 =cut
263  
264 sub display_uris {
265 6 ▶ my $self = shift;
Subroutine display_uris: called CC=2 SCAR=6.9
Pod documented
266 6 my %uris;
267 6 foreach my $d ( $self->displays ) {
268 14 my $path = $d->path;
269 14 $path =~ s!/$!!; # remove eventual trailing slash
270 14 $uris{ $d->type } = $path . '/' . $self->uri;
271 }
272 6 return \%uris;
273 }
274  
275 =head2 display_uri('display_type')
276  
277 Return the uri for the display type (or undef if not found).
278  
279 =cut
280  
281 sub display_uri {
282 3 ▶ my ( $self, $type ) = @_;
Subroutine display_uri: called CC=1 SCAR=0.0
Pod documented
283 3 return $self->display_uris->{$type};
284 }
285  
286 2 1;
« Schema/ResultSet/Navigation.pm ↑ Summary Schema/Result/Address.pm »