diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 26 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 51 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 18 |
9 files changed, 191 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index af4cdd5aa..7b630d36f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -124,12 +124,16 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $category = $c->render_fragment( 'report/new/category.html'); my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); my $has_open311 = keys %{ $c->stash->{category_extras} }; + my $extra_name_info = $c->stash->{extra_name_info} + ? $c->render_fragment('report/new/extra_name.html') + : ''; my $body = JSON->new->utf8(1)->encode( { councils_text => $councils_text, category => $category, has_open311 => $has_open311, + extra_name_info => $extra_name_info, } ); @@ -394,6 +398,13 @@ sub initialize_report : Private { } + if ( $c->req->param('first_name') && $c->req->param('last_name') ) { + $c->stash->{first_name} = $c->req->param('first_name'); + $c->stash->{last_name} = $c->req->param('last_name'); + + $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) ); + } + # Capture whether the map was used $report->used_map( $c->req->param('skipped') ? 0 : 1 ); @@ -542,14 +553,14 @@ sub setup_categories_and_councils : Private { ); $category_label = _('Property type:'); - } elsif ($first_council->{type} eq 'LBO') { + } elsif ($first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { $area_ids_to_list{ $first_council->{id} } = 1; @category_options = ( _('-- Pick a category --'), sort keys %{ Utils::london_categories() } ); - $category_label = _('Category:'); + $category_label = _('Category'); } else { @@ -579,7 +590,7 @@ sub setup_categories_and_councils : Private { if (@category_options) { @category_options = ( _('-- Pick a category --'), @category_options, _('Other') ); - $category_label = _('Category:'); + $category_label = _('Category'); } } @@ -589,6 +600,7 @@ sub setup_categories_and_councils : Private { $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{category_extras_json} = encode_json \%category_extras; + $c->stash->{extra_name_info} = $first_council->{id} == 2482 ? 1 : 0; my @missing_details_councils = grep { !$area_ids_to_list{$_} } # @@ -733,7 +745,7 @@ sub process_report : Private { $councils = join( ',', @{ $c->stash->{area_ids_to_list} } ) || -1; $report->council( $councils ); - } elsif ( $first_council->{type} eq 'LBO') { + } elsif ( $first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); @@ -785,6 +797,8 @@ sub process_report : Private { }; } + $c->cobrand->process_extras( $c, \@contacts, \@extra ); + if ( @extra ) { $c->stash->{report_meta} = \@extra; $report->extra( \@extra ); @@ -916,6 +930,8 @@ sub check_for_errors : Private { %{ $c->stash->{report}->check_for_errors }, ); + # FIXME: need to check for required bromley fields here + # if they're got the login details wrong when signing in then # we don't care about the name field even though it's validated # by the user object diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 15444f556..114c86c28 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -153,6 +153,15 @@ want to move adding these elsewhere sub process_update : Private { my ( $self, $c ) = @_; + if ( $c->req->param('first_name' ) && $c->req->param('last_name' ) ) { + my $first_name = $c->req->param('first_name'); + my $last_name = $c->req->param('last_name'); + $c->req->param('name', sprintf( '%s %s', $first_name, $last_name ) ); + + $c->stash->{first_name} = $first_name; + $c->stash->{last_name} = $last_name; + } + my %params = map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); @@ -185,6 +194,24 @@ sub process_update : Private { $update->problem_state( $params{state} ); } + if ( $c->req->param('fms_extra_title') ) { + my %extras = (); + $extras{title} = $c->req->param('fms_extra_title'); + $extras{email_alerts_required} = $c->req->param('add_alert'); + $update->extra( \%extras ); + + $c->stash->{fms_extra_title} = $c->req->param('fms_extra_title'); + } + + if ( $c->stash->{ first_name } && $c->stash->{ last_name } ) { + my $extra = $update->extra || {}; + $extra->{first_name} = $c->stash->{ first_name }; + $extra->{last_name} = $c->stash->{ last_name }; + $update->extra( $extra ); + } + + $c->log->debug( 'name is ' . $c->req->param('name') ); + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 75174b638..90661c0c3 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -31,5 +31,33 @@ sub example_places { return ( 'BR1 3UH', 'Glebe Rd, Bromley' ); } +sub process_extras { + my $self = shift; + my $ctx = shift; + my $contacts = shift; + my $extra = shift; + + for my $field (qw/ fms_extra_title first_name last_name /) { + my $value = $ctx->request->param($field); + + if ( !$value ) { + $ctx->stash->{field_errors}->{$field} = + _('This information is required'); + } + push @$extra, + { + name => $field, + description => uc($field), + value => $value || '', + }; + } + + if ( $ctx->request->param('fms_extra_title') ) { + $ctx->stash->{fms_extra_title} = + $ctx->request->param('fms_extra_title'); + $ctx->stash->{extra_name_info} = 1; + } +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 47038f25c..cee320cca 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -922,5 +922,7 @@ sub example_places { return [ 'B2 4QA', 'Tib St, Manchester' ]; } +sub process_extras {} + 1; diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index 80d57400d..6c0089d26 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -45,5 +45,31 @@ sub generate_problem_banner { return $banner; } +sub process_extras { + my $self = shift; + my $ctx = shift; + my $contacts = shift; + my $extra = shift; + + if ( $contacts->[0]->area_id == 2482 ) { + for my $field ( qw/ fms_extra_title / ) { + my $value = $ctx->request->param( $field ); + + if ( !$value ) { + $ctx->stash->{field_errors}->{ $field } = _('This information is required'); + } + push @$extra, { + name => $field, + description => uc( $field), + value => $value || '', + }; + } + + if ( $ctx->request->param('fms_extra_title') ) { + $ctx->stash->{fms_extra_title} = $ctx->request->param('fms_extra_title'); + $ctx->stash->{extra_name_info} = 1; + } + } +} 1; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 195fe4019..d31bf5510 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Comment; # Created by DBIx::Class::Schema::Loader @@ -7,7 +8,6 @@ use strict; use warnings; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("comment"); __PACKAGE__->add_columns( @@ -54,29 +54,62 @@ __PACKAGE__->add_columns( { data_type => "boolean", is_nullable => 0 }, "problem_state", { data_type => "text", is_nullable => 1 }, + "external_id", + { data_type => "text", is_nullable => 1 }, + "extra", + { data_type => "text", is_nullable => 1 }, + "send_fail_count", + { data_type => "integer", default_value => 0, is_nullable => 0 }, + "send_fail_reason", + { data_type => "text", is_nullable => 1 }, + "send_fail_timestamp", + { data_type => "timestamp", is_nullable => 1 }, + "whensent", + { data_type => "timestamp", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( - "user", - "FixMyStreet::DB::Result::User", - { id => "user_id" }, - { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, -); -__PACKAGE__->belongs_to( "problem", "FixMyStreet::DB::Result::Problem", { id => "problem_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +__PACKAGE__->belongs_to( + "user", + "FixMyStreet::DB::Result::User", + { id => "user_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:07:32 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ilLn3dlagg5COdpZDmzrVQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 15:44:18 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nvkElEgSU6XcLd9znSqhmQ + +__PACKAGE__->filter_column( + extra => { + filter_from_storage => sub { + my $self = shift; + my $ser = shift; + return undef unless defined $ser; + my $h = new IO::String($ser); + return RABX::wire_rd($h); + }, + filter_to_storage => sub { + my $self = shift; + my $data = shift; + my $ser = ''; + my $h = new IO::String($ser); + RABX::wire_wr( $data, $h ); + return $ser; + }, + } +); use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; +use RABX; with 'FixMyStreet::Roles::Abuser'; diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index 0a5784560..b9cd432ee 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Open311conf; # Created by DBIx::Class::Schema::Loader @@ -7,7 +8,6 @@ use strict; use warnings; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("open311conf"); __PACKAGE__->add_columns( @@ -26,13 +26,30 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "api_key", { data_type => "text", is_nullable => 1 }, + "send_method", + { data_type => "text", is_nullable => 1 }, + "send_comments", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "comment_user_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); +__PACKAGE__->belongs_to( + "comment_user", + "FixMyStreet::DB::Result::User", + { id => "comment_user_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-07-29 18:09:25 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ryqCpvwjNtQrZm4I3s0hxg +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 17:03:34 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fC6Ws8p/pXyjgqfm2LRKsw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index ce7488703..8c479953b 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -84,6 +84,12 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "geocode", { data_type => "bytea", is_nullable => 1 }, + "send_fail_count", + { data_type => "integer", is_nullable => 1 }, + "send_fail_reason", + { data_type => "text", is_nullable => 1 }, + "send_fail_timestamp", + { data_type => "timestamp", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -106,8 +112,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-09-19 14:38:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nq8Ufn/SEoDGSrrGlHIxag +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-16 10:08:56 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VODeZlWk8l/+IzBBlRNV0A # Add fake relationship to stored procedure table __PACKAGE__->has_one( diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 56d726a8d..7b0ffca73 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -172,4 +172,22 @@ sub belongs_to_council { return 0; } +=head2 split_name + + $name = $user->split_name; + printf( 'Welcome %s %s', $name->{first}, $name->{last} ); + +Returns a hashref with first and last keys with first name(s) and last name. +NB: the spliting algorithm is extremely basic. + +=cut + +sub split_name { + my $self = shift; + + my ($first, $last) = $self->name =~ /^(\S*)(?: (.*))?$/; + + return { first => $first, last => $last }; +} + 1; |