diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/Result')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 43 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Nearby.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 89 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 20 |
7 files changed, 102 insertions, 67 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 35cce8368..2a52a7bca 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -70,7 +70,7 @@ __PACKAGE__->belongs_to( # You can replace this text with custom code or comments, and it will be preserved on regeneration -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; @@ -113,7 +113,4 @@ sub disable { return 1; } -# need the inline_constuctor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 0caaa8968..5734ff8d5 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -96,8 +96,7 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use Image::Size; -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; @@ -148,15 +147,44 @@ sub confirm { $self->confirmed( \'current_timestamp' ); } -=head2 get_photo_params +=head2 get_photoset -Returns a hashref of details of any attached photo for use in templates. +Return a PhotoSet object for all photos attached to this field + + my $photoset = $obj->get_photoset; + print $photoset->num_images; + return $photoset->get_image_data(num => 0, size => 'full'); =cut -sub get_photo_params { +sub get_photoset { + my ($self) = @_; + my $class = 'FixMyStreet::App::Model::PhotoSet'; + eval "use $class"; + return $class->new({ + db_data => $self->photo, + object => $self, + }); +} + +sub photos { my $self = shift; - return FixMyStreet::App::get_photo_params($self, 'c'); + my $photoset = $self->get_photoset; + my $i = 0; + my $id = $self->id; + my @photos = map { + my $format = 'jpeg'; + my $cachebust = substr($_, 0, 8); + { + id => $_, + url_temp => "/photo/$_.temp.$format", + url_temp_full => "/photo/$_.fulltemp.$format", + url => "/photo/c/$id.$i.$format?$cachebust", + url_full => "/photo/c/$id.$i.full.$format?$cachebust", + idx => $i++, + } + } $photoset->all_ids; + return \@photos; } =head2 meta_problem_state @@ -214,7 +242,4 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 1 }, ); -# we need the inline_constructor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index 2fbb0716d..dab5432c6 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -63,12 +63,9 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Extra'; -# we need the inline_constructor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; diff --git a/perllib/FixMyStreet/DB/Result/Nearby.pm b/perllib/FixMyStreet/DB/Result/Nearby.pm index d3d228788..adeba703a 100644 --- a/perllib/FixMyStreet/DB/Result/Nearby.pm +++ b/perllib/FixMyStreet/DB/Result/Nearby.pm @@ -6,7 +6,7 @@ use strict; use warnings; use base 'DBIx::Class::Core'; -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; __PACKAGE__->table( 'NONE' ); @@ -27,7 +27,4 @@ __PACKAGE__->belongs_to( __PACKAGE__->result_source_instance ->name( \'problem_find_nearby(?,?,?)' ); -# we need the inline_constructor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 3b7f8bcfd..2a90d0bec 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -157,8 +157,7 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); __PACKAGE__->rabx_column('geocode'); -use Image::Size; -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; use Utils; @@ -363,7 +362,8 @@ around lastupdate => $stz; around service => sub { my ( $orig, $self ) = ( shift, shift ); - my $s = $self->$orig(@_); + # service might be undef if e.g. unsaved code report + my $s = $self->$orig(@_) || ""; $s =~ s/_/ /g; return $s; }; @@ -462,7 +462,7 @@ sub bodies($) { my $self = shift; return {} unless $self->bodies_str; my $bodies = $self->bodies_str_ids; - my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all; + my @bodies = $self->result_source->schema->resultset('Body')->search({ id => $bodies })->all; return { map { $_->id => $_ } @bodies }; } @@ -477,21 +477,9 @@ sub url { return "/report/" . $self->id; } -=head2 get_photo_params - -Returns a hashref of details of the attached photo, if any, for use in templates. - -NB: this method doesn't currently support multiple photos gracefully. - -Use get_photoset($c) instead to do the right thing with reports with 0, 1, or more photos. - -=cut - -sub get_photo_params { - # use Carp 'cluck'; - # cluck "get_photo_params called"; # TEMPORARY die to make sure I've done right thing with Zurich templates - my $self = shift; - return FixMyStreet::App::get_photo_params($self, 'id'); +sub admin_url { + my ($self, $cobrand) = @_; + return $cobrand->admin_base_url . '/report_edit/' . $self->id; } =head2 is_open @@ -628,7 +616,7 @@ sub body { $body = join( _(' and '), map { my $name = $_->name; - if ($c and mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS')) { + if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) { '<a href="' . $_->url($c) . '">' . $name . '</a>'; } else { $name; @@ -648,7 +636,7 @@ order of title. sub response_templates { my $problem = shift; - return FixMyStreet::App->model('DB::ResponseTemplate')->search( + return $problem->result_source->schema->resultset('ResponseTemplate')->search( { body_id => $problem->bodies_str_ids }, @@ -754,20 +742,17 @@ sub update_from_open311_service_request { $status_notes = $request->{status_notes}; } - my $update = FixMyStreet::App->model('DB::Comment')->new( - { - problem_id => $self->id, - state => 'confirmed', - created => $updated || \'current_timestamp', - confirmed => \'current_timestamp', - text => $status_notes, - mark_open => 0, - mark_fixed => 0, - user => $system_user, - anonymous => 0, - name => $body->name, - } - ); + my $update = $self->new_related(comments => { + state => 'confirmed', + created => $updated || \'current_timestamp', + confirmed => \'current_timestamp', + text => $status_notes, + mark_open => 0, + mark_fixed => 0, + user => $system_user, + anonymous => 0, + name => $body->name, + }); my $w3c = DateTime::Format::W3CDTF->new; my $req_time = $w3c->parse_datetime( $request->{updated_datetime} ); @@ -833,7 +818,7 @@ sub as_hashref { state_t => _( $self->state ), used_map => $self->used_map, is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0, - photo => $self->get_photo_params, + photos => [ map { $_->{url} } @{$self->photos} ], meta => $self->confirmed ? $self->meta_line( $c ) : '', confirmed_pp => $self->confirmed ? $c->cobrand->prettify_dt( $self->confirmed ): '', created_pp => $c->cobrand->prettify_dt( $self->created ), @@ -855,23 +840,44 @@ sub latest_moderation_log_entry { Return a PhotoSet object for all photos attached to this field - my $photoset = $obj->get_photoset( $c ); + my $photoset = $obj->get_photoset; print $photoset->num_images; return $photoset->get_image_data(num => 0, size => 'full'); =cut sub get_photoset { - my ($self, $c) = @_; + my ($self) = @_; my $class = 'FixMyStreet::App::Model::PhotoSet'; eval "use $class"; return $class->new({ - c => $c, - data => $self->photo, + db_data => $self->photo, object => $self, }); } +sub photos { + my $self = shift; + my $photoset = $self->get_photoset; + my $i = 0; + my $id = $self->id; + my @photos = map { + my $format = 'jpeg'; + my $cachebust = substr($_, 0, 8); + { + id => $_, + url_temp => "/photo/$_.temp.$format", + url_temp_full => "/photo/$_.fulltemp.$format", + url => "/photo/$id.$i.$format?$cachebust", + url_full => "/photo/$id.$i.full.$format?$cachebust", + url_tn => "/photo/$id.$i.tn.$format?$cachebust", + url_fp => "/photo/$id.$i.fp.$format?$cachebust", + idx => $i++, + } + } $photoset->all_ids; + return \@photos; +} + __PACKAGE__->has_many( "admin_log_entries", "FixMyStreet::DB::Result::AdminLog", @@ -894,7 +900,4 @@ sub get_time_spent { return $admin_logs ? $admin_logs->get_column('sum_time_spent') : 0; } -# we need the inline_constructor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index 6f2941546..30f2ab7ce 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -43,7 +43,7 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oL1Hk4/bNG14CY74GA75SA -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; my $stz = sub { diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index f08b666c8..6bce415a6 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -32,9 +32,15 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "title", { data_type => "text", is_nullable => 1 }, + "twitter_id", + { data_type => "bigint", is_nullable => 1 }, + "facebook_id", + { data_type => "bigint", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("users_email_key", ["email"]); +__PACKAGE__->add_unique_constraint("users_facebook_id_key", ["facebook_id"]); +__PACKAGE__->add_unique_constraint("users_twitter_id_key", ["twitter_id"]); __PACKAGE__->has_many( "admin_logs", "FixMyStreet::DB::Result::AdminLog", @@ -84,8 +90,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-29 13:54:07 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Y41/jGp93IxSpyJ/o6Q1gQ +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-12-09 16:02:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hCq6ZDZfV/6iiu3HFhPPOg __PACKAGE__->add_columns( "password" => { @@ -98,6 +104,16 @@ __PACKAGE__->add_columns( use mySociety::EmailUtil; +sub latest_anonymity { + my $self = shift; + my $p = $self->problems->search(undef, { order_by => { -desc => 'id' } } )->first; + my $c = $self->comments->search(undef, { order_by => { -desc => 'id' } } )->first; + my $p_created = $p ? $p->created->epoch : 0; + my $c_created = $c ? $c->created->epoch : 0; + my $obj = $p_created >= $c_created ? $p : $c; + return $obj ? $obj->anonymous : 0; +} + =head2 check_for_errors $error_hashref = $user->check_for_errors(); |