| 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 | Defaults to empty string. | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | 2 | unique_column file => { | |
| 37 | data_type => "varchar", | ||
| 38 | default_value => "", | ||
| 39 | size => 255 | ||
| 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_foreign_key => 1, 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", is_foreign_key => 1 }; | ||
| 133 | |||
| 134 | =head1 UNIQUE CONSTRAINTS | ||
| 135 | |||
| 136 | =head2 C<media_id_media_types_id_unique> | ||
| 137 | |||
| 138 | =over 4 | ||
| 139 | |||
| 140 | =item * L</media_id> | ||
| 141 | |||
| 142 | =item * L</media_types_id> | ||
| 143 | |||
| 144 | =back | ||
| 145 | |||
| 146 | =cut | ||
| 147 | |||
| 148 | 2 | unique_constraint media_id_media_types_id_unique => | |
| 149 | [ "media_id", "media_types_id" ]; | ||
| 150 | |||
| 151 | =head1 RELATIONS | ||
| 152 | |||
| 153 | =head2 author | ||
| 154 | |||
| 155 | Type: belongs_to | ||
| 156 | |||
| 157 | Related object: L<Interchange6::Schema::Result::User> | ||
| 158 | |||
| 159 | =cut | ||
| 160 | |||
| 161 | 2 | belongs_to | |
| 162 | author => "Interchange6::Schema::Result::User", | ||
| 163 | { "foreign.users_id" => "self.author_users_id" }, | ||
| 164 | { join_type => "left" }; | ||
| 165 | |||
| 166 | =head2 media_type | ||
| 167 | |||
| 168 | Type: belongs_to | ||
| 169 | |||
| 170 | Related object: L<Interchange6::Schema::Result::MediaType> | ||
| 171 | |||
| 172 | =cut | ||
| 173 | |||
| 174 | 2 | belongs_to | |
| 175 | media_type => "Interchange6::Schema::Result::MediaType", | ||
| 176 | "media_types_id", | ||
| 177 | { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }; | ||
| 178 | |||
| 179 | =head2 media_products | ||
| 180 | |||
| 181 | Type: has_many | ||
| 182 | |||
| 183 | Related object: L<Interchange6::Schema::Result::MediaProduct> | ||
| 184 | |||
| 185 | =cut | ||
| 186 | |||
| 187 | 2 | has_many | |
| 188 | media_products => "Interchange6::Schema::Result::MediaProduct", | ||
| 189 | "media_id", | ||
| 190 | { cascade_copy => 0, cascade_delete => 0 }; | ||
| 191 | |||
| 192 | =head2 products | ||
| 193 | |||
| 194 | Type: many_to_many with product. | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | 2 | many_to_many products => "media_products", "product"; | |
| 199 | |||
| 200 | =head2 displays | ||
| 201 | |||
| 202 | Type: many_to_many with media_displays | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | 2 | many_to_many displays => "media_type", "media_displays"; | |
| 207 | |||
| 208 | =head1 METHODS | ||
| 209 | |||
| 210 | =head2 type | ||
| 211 | |||
| 212 | Return the media type looking into MediaDisplay and MediaType. | ||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | sub type { | ||
| 217 | 6 | ▶ | my $self = shift; |
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||
| 218 | |||
| 219 | # here we return just the first result. UNCLEAR if more are | ||
| 220 | # needed, but has many... Either we | ||
| 221 | 6 | return $self->media_type->type; | |
| 222 | } | ||
| 223 | |||
| 224 | =head2 display_uris | ||
| 225 | |||
| 226 | Return an hashref with the media display type and the final uri. | ||
| 227 | |||
| 228 | =cut | ||
| 229 | |||
| 230 | sub display_uris { | ||
| 231 | 6 | ▶ | my $self = shift; |
|
Subroutine
display_uris: called CC=2 SCAR=6.9
Pod
documented
| |||
| 232 | 6 | my %uris; | |
| 233 | 6 | foreach my $d ( $self->displays ) { | |
| 234 | 14 | my $path = $d->path; | |
| 235 | 14 | $path =~ s!/$!!; # remove eventual trailing slash | |
| 236 | 14 | $uris{ $d->type } = $path . '/' . $self->uri; | |
| 237 | } | ||
| 238 | 6 | return \%uris; | |
| 239 | } | ||
| 240 | |||
| 241 | =head2 display_uri('display_type') | ||
| 242 | |||
| 243 | Return the uri for the display type (or undef if not found). | ||
| 244 | |||
| 245 | =cut | ||
| 246 | |||
| 247 | sub display_uri { | ||
| 248 | 3 | ▶ | my ( $self, $type ) = @_; |
|
Subroutine
display_uri: called CC=1 SCAR=0.0
Pod
documented
| |||
| 249 | 3 | return $self->display_uris->{$type}; | |
| 250 | } | ||
| 251 | |||
| 252 | 2 | 1; | |