| 1 | package Silki::Schema::UserImage; | ||
| 2 | { | ||
| 3 | $Silki::Schema::UserImage::VERSION = '0.29'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | use Silki::Types qw( Str ); | ||
| 11 | |||
| 12 | use Fey::ORM::Table; | ||
| 13 | |||
| 14 | with 'Silki::Role::Schema::URIMaker'; | ||
| 15 | |||
| 16 | my $Schema = Silki::Schema->Schema(); | ||
| 17 | |||
| 18 | has_policy 'Silki::Schema::Policy'; | ||
| 19 | |||
| 20 | has_table( $Schema->table('UserImage') ); | ||
| 21 | |||
| 22 | has_one( $Schema->table('User') ); | ||
| 23 | |||
| 24 | has filename => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => Str, | ||
| 27 | init_arg => undef, | ||
| 28 | lazy => 1, | ||
| 29 | builder => '_build_filename', | ||
| 30 | ); | ||
| 31 | |||
| 32 | with 'Silki::Role::Schema::File'; | ||
| 33 | |||
| 34 | sub _base_uri_path { | ||
| 35 | my $self = shift; | ||
| 36 | |||
| 37 | return '/user_image/' . $self->user_id(); | ||
| 38 | } | ||
| 39 | |||
| 40 | { | ||
| 41 | my %ext = ( | ||
| 42 | 'image/gif' => '.gif', | ||
| 43 | 'image/jpeg' => '.jpg', | ||
| 44 | 'image/png' => '.png', | ||
| 45 | ); | ||
| 46 | |||
| 47 | sub _build_filename { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | return 'user-image-' . $self->user_id() . $ext{ $self->mime_type() }; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | __PACKAGE__->meta()->make_immutable; | ||
| 55 | |||
| 56 | 1; |