diff options
author | Struan Donald <struan@exo.org.uk> | 2012-05-23 17:39:00 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-05-23 17:39:00 +0100 |
commit | 7cb6bb21f713bc07a06ece5f4109cd6bd5a7f0b0 (patch) | |
tree | eaff3aa286d8e1910b33c204c79b6837e109a216 /perllib/FixMyStreet | |
parent | 9019fda388f9232181387e8cce1d28e8b89de1ee (diff) | |
parent | 3b0e39a4c89e4c184f30c6131936dc63845d6a1f (diff) |
Merge remote-tracking branch 'origin/master' into phonegap
Diffstat (limited to 'perllib/FixMyStreet')
38 files changed, 507 insertions, 219 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 83f77f401..198acade6 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; } use POSIX qw(strftime strcoll); use Digest::MD5 qw(md5_hex); +use mySociety::EmailUtil qw(is_valid_email); =head1 NAME @@ -473,17 +474,33 @@ sub search_reports : Path('search_reports') { $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); $c->model('DB')->schema->storage->sql_maker->name_sep( '.' ); + my $query; + if (is_valid_email($search)) { + $query = [ + 'user.email' => { ilike => $like_search }, + ]; + } elsif ($search =~ /^id:(\d+)$/) { + $query = [ + 'me.id' => int($1), + ]; + } elsif ($search =~ /^area:(\d+)$/) { + $query = [ + 'me.areas' => { like => "%,$1,%" } + ]; + } else { + $query = [ + 'me.id' => $search_n, + 'user.email' => { ilike => $like_search }, + 'me.name' => { ilike => $like_search }, + title => { ilike => $like_search }, + detail => { ilike => $like_search }, + council => { like => $like_search }, + cobrand_data => { like => $like_search }, + ]; + } my $problems = $c->cobrand->problems->search( { - -or => [ - 'me.id' => $search_n, - 'user.email' => { ilike => $like_search }, - 'me.name' => { ilike => $like_search }, - title => { ilike => $like_search }, - detail => { ilike => $like_search }, - council => { like => $like_search }, - cobrand_data => { like => $like_search }, - ] + -or => $query, }, { prefetch => 'user', @@ -499,26 +516,44 @@ sub search_reports : Path('search_reports') { $c->stash->{edit_council_contacts} = 1 if ( grep {$_ eq 'councilcontacts'} keys %{$c->stash->{allowed_pages}}); - my $updates = $c->model('DB::Comment')->search( - { - -or => [ - 'me.id' => $search_n, - 'problem.id' => $search_n, - 'user.email' => { ilike => $like_search }, - 'me.name' => { ilike => $like_search }, - text => { ilike => $like_search }, - 'me.cobrand_data' => { ilike => $like_search }, - %{ $site_restriction }, - ] - }, - { - -select => [ 'me.*', qw/problem.council problem.state/ ], - prefetch => [qw/user problem/], - order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] - } - ); + if (is_valid_email($search)) { + $query = [ + 'user.email' => { ilike => $like_search }, + %{ $site_restriction }, + ]; + } elsif ($search =~ /^id:(\d+)$/) { + $query = [ + 'me.id' => int($1), + 'problem.id' => int($1), + %{ $site_restriction }, + ]; + } elsif ($search =~ /^area:(\d+)$/) { + $query = []; + } else { + $query = [ + 'me.id' => $search_n, + 'problem.id' => $search_n, + 'user.email' => { ilike => $like_search }, + 'me.name' => { ilike => $like_search }, + text => { ilike => $like_search }, + 'me.cobrand_data' => { ilike => $like_search }, + %{ $site_restriction }, + ]; + } - $c->stash->{updates} = [ $updates->all ]; + if (@$query) { + my $updates = $c->model('DB::Comment')->search( + { + -or => $query, + }, + { + -select => [ 'me.*', qw/problem.council problem.state/ ], + prefetch => [qw/user problem/], + order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] + } + ); + $c->stash->{updates} = [ $updates->all ]; + } # Switch quoting back off. See above for explanation of this. $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); diff --git a/perllib/FixMyStreet/App/Controller/JS.pm b/perllib/FixMyStreet/App/Controller/JS.pm new file mode 100755 index 000000000..ae2f06605 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/JS.pm @@ -0,0 +1,30 @@ +package FixMyStreet::App::Controller::JS; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::JS - Catalyst Controller + +=head1 DESCRIPTION + +JS Catalyst Controller. To return a language-dependent list +of validation strings. + +=head1 METHODS + +=cut + +sub validation_strings : LocalRegex('^validation_strings\.(.*?)\.js$') : Args(0) { + my ( $self, $c ) = @_; + my $lang = $c->req->captures->[0]; + $c->cobrand->set_lang_and_domain( $lang, 1 ); + $c->res->content_type( 'application/javascript' ); +} + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 60e9dd09f..3de83b265 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -30,9 +30,16 @@ sub my : Path : Args(0) { my $pins = []; my $problems = {}; - my $rs = $c->user->problems->search( { + + my $params = { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], - }, { + }; + $params = { + %{ $c->cobrand->problems_clause }, + %$params + } if $c->cobrand->problems_clause; + + my $rs = $c->user->problems->search( $params, { order_by => { -desc => 'confirmed' }, rows => 50 } )->page( $p_page ); diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 8711b19e9..a84c538cc 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN {extends 'Catalyst::Controller'; } use DateTime::Format::HTTP; +use Digest::SHA1 qw(sha1_hex); use Path::Class; =head1 NAME @@ -36,7 +37,7 @@ sub during :LocalRegex('^([0-9a-f]{40})\.temp\.jpeg$') { if ( $c->cobrand->default_photo_resize ) { $photo = _shrink( $photo, $c->cobrand->default_photo_resize ); } else { - $photo = _shrink( $photo, 'x250' ); + $photo = _shrink( $photo, '250x250' ); } $c->forward( 'output', [ $photo ] ); @@ -85,7 +86,7 @@ sub index :LocalRegex('^(c/)?(\d+)(?:\.(full|tn|fp))?\.jpeg$') { } elsif ( $c->cobrand->default_photo_resize ) { $photo = _shrink( $photo, $c->cobrand->default_photo_resize ); } else { - $photo = _shrink( $photo, 'x250' ); + $photo = _shrink( $photo, '250x250' ); } $c->forward( 'output', [ $photo ] ); @@ -114,6 +115,7 @@ sub _shrink { $image->BlobToImage($photo); my $err = $image->Scale(geometry => "$size>"); throw Error::Simple("resize failed: $err") if "$err"; + $image->Strip(); my @blobs = $image->ImageToBlob(); undef $image; return $blobs[0]; @@ -129,11 +131,101 @@ sub _crop { throw Error::Simple("resize failed: $err") if "$err"; $err = $image->Extent( geometry => '90x60', gravity => 'Center' ); throw Error::Simple("resize failed: $err") if "$err"; + $image->Strip(); my @blobs = $image->ImageToBlob(); undef $image; return $blobs[0]; } +=head2 process_photo + +Handle the photo - either checking and storing it after an upload or retrieving +it from the cache. + +Store any error message onto 'photo_error' in stash. +=cut + +sub process_photo : Private { + my ( $self, $c ) = @_; + + return + $c->forward('process_photo_upload') + || $c->forward('process_photo_cache') + || 1; # always return true +} + +sub process_photo_upload : Private { + my ( $self, $c ) = @_; + + # check for upload or return + my $upload = $c->req->upload('photo') + || return; + + # check that the photo is a jpeg + my $ct = $upload->type; + $ct =~ s/x-citrix-//; # Thanks, Citrix + # Had a report of a JPEG from an Android 2.1 coming through as a byte stream + unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' || $ct eq 'application/octet-stream' ) { + $c->stash->{photo_error} = _('Please upload a JPEG image only'); + return; + } + + # get the photo into a variable + my $photo_blob = eval { + my $filename = $upload->tempname; + my $out = `jhead -se -autorot $filename 2>&1`; + die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; + my $photo = $upload->slurp; + return $photo; + }; + if ( my $error = $@ ) { + my $format = _( +"That image doesn't appear to have uploaded correctly (%s), please try again." + ); + $c->stash->{photo_error} = sprintf( $format, $error ); + return; + } + + # we have an image we can use - save it to the upload dir for storage + my $cache_dir = dir( $c->config->{UPLOAD_DIR} ); + $cache_dir->mkpath; + unless ( -d $cache_dir && -w $cache_dir ) { + warn "Can't find/write to photo cache directory '$cache_dir'"; + return; + } + + my $fileid = sha1_hex($photo_blob); + $upload->copy_to( file($cache_dir, $fileid . '.jpeg') ); + + # stick the hash on the stash, so don't have to reupload in case of error + $c->stash->{upload_fileid} = $fileid; + + return 1; +} + +=head2 process_photo_cache + +Look for the upload_fileid parameter and check it matches a file on disk. If it +does return true and put fileid on stash, otherwise false. + +=cut + +sub process_photo_cache : Private { + my ( $self, $c ) = @_; + + # get the fileid and make sure it is just a hex number + my $fileid = $c->req->param('upload_fileid') || ''; + $fileid =~ s{[^0-9a-f]}{}gi; + return unless $fileid; + + my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); + return unless -e $file; + + $c->stash->{upload_fileid} = $fileid; + return 1; +} + + =head1 AUTHOR Struan Donald diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 6ed7ddd9d..fe71f3fbb 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -244,7 +244,7 @@ sub process_questionnaire : Private { push @errors, _('Please provide some explanation as to why you\'re reopening this report') if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update}; - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); push @errors, $c->stash->{photo_error} if $c->stash->{photo_error}; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 59e3a4410..afe180c29 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -51,7 +51,7 @@ sub display : Path('') : Args(1) { return $c->res->redirect( $c->uri_for($1), 301 ); } - $c->forward('load_problem_or_display_error', [ $id ] ); + $c->forward( 'load_problem_or_display_error', [ $id ] ); $c->forward( 'load_updates' ); $c->forward( 'format_problem_for_display' ); } @@ -88,7 +88,24 @@ sub load_updates : Private { { order_by => 'confirmed' } ); - $c->stash->{updates} = $updates; + my $questionnaires = $c->model('DB::Questionnaire')->search( + { + problem_id => $c->stash->{problem}->id, + whenanswered => { '!=', undef }, + old_state => 'confirmed', new_state => 'confirmed', + }, + { order_by => 'whenanswered' } + ); + + my @combined; + while (my $update = $updates->next) { + push @combined, [ $update->confirmed, $update ]; + } + while (my $update = $questionnaires->next) { + push @combined, [ $update->whenanswered, $update ]; + } + @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; + $c->stash->{updates} = \@combined; return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 70dee63c6..70f937eed 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -5,7 +5,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Geocode; -use Digest::SHA1 qw(sha1_hex); use Encode; use Image::Magick; use List::MoreUtils qw(uniq); @@ -78,6 +77,8 @@ partial =cut +use constant COUNCIL_ID_BARNET => 2489; + sub report_new : Path : Args(0) { my ( $self, $c ) = @_; @@ -97,7 +98,7 @@ sub report_new : Path : Args(0) { return unless $c->forward('check_form_submitted'); $c->forward('process_user'); $c->forward('process_report'); - $c->forward('process_photo'); + $c->forward('/photo/process_photo'); return unless $c->forward('check_for_errors'); $c->forward('save_user_and_report'); $c->forward('redirect_or_confirm_creation'); @@ -171,9 +172,14 @@ sub report_form_ajax : Path('ajax') : Args(0) { $c->forward('initialize_report'); # work out the location for this report and do some checks - # XXX We don't want to do this here if this actually happens! - return $c->forward('redirect_to_around') - unless $c->forward('determine_location'); + if ( ! $c->forward('determine_location') ) { + my $body = JSON->new->utf8(1)->encode( { + error => $c->stash->{location_error}, + } ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); + return; + } $c->forward('setup_categories_and_councils'); @@ -266,7 +272,7 @@ sub report_import : Path('/import') { } # handle the photo upload - $c->forward( 'process_photo_upload' ); + $c->forward( '/photo/process_photo_upload' ); my $fileid = $c->stash->{upload_fileid}; if ( my $error = $c->stash->{photo_error} ) { push @errors, $error; @@ -602,9 +608,15 @@ sub setup_categories_and_councils : Private { } elsif ($first_council->{type} eq 'LBO') { $area_ids_to_list{ $first_council->{id} } = 1; + my @local_categories; + if ($first_council->{id} == COUNCIL_ID_BARNET) { + @local_categories = sort(keys %{ Utils::barnet_categories() }); # removed 'Other' option + } else { + @local_categories = sort keys %{ Utils::london_categories() } + } @category_options = ( _('-- Pick a category --'), - sort keys %{ Utils::london_categories() } + @local_categories ); $category_label = _('Category:'); @@ -791,8 +803,15 @@ 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} == COUNCIL_ID_BARNET ) { + unless ( exists Utils::barnet_categories()->{ $report->category } or $report->category eq 'Other') { + $c->stash->{field_errors}->{category} = _('Please choose a category'); + } + $report->council( $first_council->{id} ); + + } elsif ( $first_council->{type} eq 'LBO') { + unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } @@ -871,91 +890,6 @@ sub process_report : Private { return 1; } -=head2 process_photo - -Handle the photo - either checking and storing it after an upload or retrieving -it from the cache. - -Store any error message onto 'photo_error' in stash. -=cut - -sub process_photo : Private { - my ( $self, $c ) = @_; - - return - $c->forward('process_photo_upload') - || $c->forward('process_photo_cache') - || 1; # always return true -} - -sub process_photo_upload : Private { - my ( $self, $c ) = @_; - - # check for upload or return - my $upload = $c->req->upload('photo') - || return; - - # check that the photo is a jpeg - my $ct = $upload->type; - unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { - $c->stash->{photo_error} = _('Please upload a JPEG image only'); - return; - } - - # get the photo into a variable - my $photo_blob = eval { - my $filename = $upload->tempname; - my $out = `jhead -se -autorot $filename`; - my $photo = $upload->slurp; - return $photo; - }; - if ( my $error = $@ ) { - my $format = _( -"That image doesn't appear to have uploaded correctly (%s), please try again." - ); - $c->stash->{photo_error} = sprintf( $format, $error ); - return; - } - - # we have an image we can use - save it to the upload dir for storage - my $cache_dir = dir( $c->config->{UPLOAD_DIR} ); - $cache_dir->mkpath; - unless ( -d $cache_dir && -w $cache_dir ) { - warn "Can't find/write to photo cache directory '$cache_dir'"; - return; - } - - my $fileid = sha1_hex($photo_blob); - $upload->copy_to( file($cache_dir, $fileid . '.jpeg') ); - - # stick the hash on the stash, so don't have to reupload in case of error - $c->stash->{upload_fileid} = $fileid; - - return 1; -} - -=head2 process_photo_cache - -Look for the upload_fileid parameter and check it matches a file on disk. If it -does return true and put fileid on stash, otherwise false. - -=cut - -sub process_photo_cache : Private { - my ( $self, $c ) = @_; - - # get the fileid and make sure it is just a hex number - my $fileid = $c->req->param('upload_fileid') || ''; - $fileid =~ s{[^0-9a-f]}{}gi; - return unless $fileid; - - my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - return unless -e $file; - - $c->stash->{upload_fileid} = $fileid; - return 1; -} - =head2 check_for_errors Examine the user and the report for errors. If found put them on stash and diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 15444f556..8a87fe7a2 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -23,7 +23,7 @@ sub report_update : Path : Args(0) { $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ); $c->forward('process_update'); $c->forward('process_user'); - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index e7620f755..9fb72121e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -341,9 +341,11 @@ sub load_and_group_problems : Private { { columns => [ 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - { duration => { extract => "epoch from current_timestamp-lastupdate" } }, - { age => { extract => "epoch from current_timestamp-confirmed" } }, - { confirmed => { extract => 'epoch from confirmed' } }, + #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, + #{ age => { extract => "epoch from current_timestamp-confirmed" } }, + { confirmed => { extract => 'epoch from confirmed' } }, + { whensent => { extract => 'epoch from whensent' } }, + { lastupdate => { extract => 'epoch from lastupdate' } }, { photo => 'photo is not null' }, ], order_by => { -desc => 'lastupdate' }, @@ -355,9 +357,10 @@ sub load_and_group_problems : Private { my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age', 'confirmed', 'photo' ); + my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; + $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 9cdf0b523..7f7d7f5fd 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -68,7 +68,7 @@ Forward to the standard 404 error page sub default : Path { my ( $self, $c ) = @_; - $c->detach('/page_error_404_not_found'); + $c->detach('/page_error_404_not_found', []); } =head2 page_error_404_not_found, page_error_410_gone diff --git a/perllib/FixMyStreet/App/Controller/Static.pm b/perllib/FixMyStreet/App/Controller/Static.pm index 52b230c27..d4b7a1b83 100755 --- a/perllib/FixMyStreet/App/Controller/Static.pm +++ b/perllib/FixMyStreet/App/Controller/Static.pm @@ -29,6 +29,10 @@ sub for_councils_faq : Path('/for-councils/faq') : Args(0) { my ( $self, $c ) = @_; } +sub privacy : Global : Args(0) { + my ( $self, $c ) = @_; +} + sub faq : Global : Args(0) { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 755f1e405..092e362f9 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -75,6 +75,7 @@ sprintf (different name to avoid clash) sub tprintf { my ( $self, $c, $format, @args ) = @_; + @args = @{$args[0]} if ref $args[0] eq 'ARRAY'; return sprintf $format, @args; } diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 9791b071a..6f115ec63 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -10,7 +10,9 @@ sub council_name { return 'Barnet Council'; } sub council_url { return 'barnet'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, centre => '51.612832,-0.218169', span => '0.0563,0.09', bounds => [ '51.584682,-0.263169', '51.640982,-0.173169' ], diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm new file mode 100644 index 000000000..75174b638 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -0,0 +1,35 @@ +package FixMyStreet::Cobrand::Bromley; +use base 'FixMyStreet::Cobrand::UKCouncils'; + +use strict; +use warnings; + +sub council_id { return 2482; } +sub council_area { return 'Bromley'; } +sub council_name { return 'Bromley Council'; } +sub council_url { return 'bromley'; } + +sub path_to_web_templates { + my $self = shift; + return [ + FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify, + FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify + ]; +} + +sub disambiguate_location { + my $self = shift; + return { + %{ $self->SUPER::disambiguate_location() }, + centre => '51.366836,0.040623', + span => '0.154963,0.24347', + bounds => [ '51.289355,-0.081112', '51.444318,0.162358' ], + }; +} + +sub example_places { + return ( 'BR1 3UH', 'Glebe Rd, Bromley' ); +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index aacfb5e2b..c45c36b0b 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -239,6 +239,8 @@ Returns disambiguating information available sub disambiguate_location { return { country => 'uk', + bing_culture => 'en-GB', + bing_country => 'United Kingdom' }; } @@ -457,7 +459,7 @@ sub find_closest { my ( $self, $latitude, $longitude, $problem ) = @_; my $str = ''; - if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude ) ) { + if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) { # cache the bing results for use in alerts if ( $problem ) { $problem->geocode( $j ); @@ -504,7 +506,7 @@ sub find_closest_address_for_rss { # if we've not cached it then we don't want to look it up in order to avoid # hammering the bing api # if ( !$j ) { - # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ); + # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture}, 1 ); # $problem->geocode( $j ); # $problem->update; @@ -914,5 +916,9 @@ Get stats to display on the council reports page sub get_report_stats { return 0; } +sub example_places { + return [ 'B2 4QA', 'Tib St, Manchester' ]; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 91c5e10ec..4d93aaf76 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -21,7 +21,9 @@ sub problems_clause { # FIXME - need to double check this is all correct sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, centre => '52.688198,-1.804966', span => '0.1196,0.218675', bounds => [ '52.807793,-1.586291', '52.584891,-1.963232' ], diff --git a/perllib/FixMyStreet/Cobrand/Reading.pm b/perllib/FixMyStreet/Cobrand/Reading.pm index afc2b6ac6..c8591924e 100644 --- a/perllib/FixMyStreet/Cobrand/Reading.pm +++ b/perllib/FixMyStreet/Cobrand/Reading.pm @@ -12,11 +12,13 @@ sub council_name { return 'Reading City Council'; } sub council_url { return 'reading'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, town => 'Reading', - centre => '51.452983169803964,-0.98382678731985973', - span => '0.0833543573028663,0.124500468843446', - bounds => [ '51.409779668156361,-1.0529948144525243', '51.493134025459227,-0.92849434560907829' ], + centre => '51.452983,-0.983827', + span => '0.083355,0.1245', + bounds => [ '51.409779,-1.052994', '51.493134,-0.928494' ], }; } diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index 5bb7df3b6..b57091bef 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -10,7 +10,9 @@ sub council_name { return 'Southampton City Council'; } sub council_url { return 'southampton'; } sub disambiguate_location { + my $self = shift; return { + %{ $self->SUPER::disambiguate_location() }, town => 'Southampton', centre => '50.913822,-1.400493', span => '0.084628,0.15701', diff --git a/perllib/FixMyStreet/DB.pm b/perllib/FixMyStreet/DB.pm index 18c8cc2ca..a1767abe9 100644 --- a/perllib/FixMyStreet/DB.pm +++ b/perllib/FixMyStreet/DB.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB; # Created by DBIx::Class::Schema::Loader @@ -10,8 +11,9 @@ use base 'DBIx::Class::Schema'; __PACKAGE__->load_namespaces; -# Created by DBIx::Class::Schema::Loader v0.07009 @ 2011-03-01 15:43:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tJZ+CpaAfZVPrctDXTZTuQ + +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CjFpUvon7KggFM7OF7VK/w # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/Abuse.pm b/perllib/FixMyStreet/DB/Result/Abuse.pm index b1cf9c1ed..e8e554afa 100644 --- a/perllib/FixMyStreet/DB/Result/Abuse.pm +++ b/perllib/FixMyStreet/DB/Result/Abuse.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Abuse; # Created by DBIx::Class::Schema::Loader @@ -7,15 +8,14 @@ use strict; use warnings; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("abuse"); __PACKAGE__->add_columns("email", { data_type => "text", is_nullable => 0 }); __PACKAGE__->set_primary_key("email"); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IuTLiJSDZGLF/WX8q3iKIQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PnQhGMx+ktK++3gWOMJBpQ # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm index da97950a0..ede786871 100644 --- a/perllib/FixMyStreet/DB/Result/AdminLog.pm +++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::AdminLog; # 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("admin_log"); __PACKAGE__->add_columns( @@ -36,8 +36,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7427CuN3/6IL2GxiQDoWUA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+NlSH8U+beRjBZl8CpqK9A # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index eddd98f37..ca9ad45c2 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Alert; # 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("alert"); __PACKAGE__->add_columns( @@ -24,6 +24,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "parameter2", { data_type => "text", is_nullable => 1 }, + "user_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "confirmed", { data_type => "integer", default_value => 0, is_nullable => 0 }, "lang", @@ -40,8 +42,6 @@ __PACKAGE__->add_columns( }, "whendisabled", { data_type => "timestamp", is_nullable => 1 }, - "user_id", - { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( @@ -50,22 +50,22 @@ __PACKAGE__->belongs_to( { ref => "alert_type" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +__PACKAGE__->has_many( + "alerts_sent", + "FixMyStreet::DB::Result::AlertSent", + { "foreign.alert_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); __PACKAGE__->belongs_to( "user", "FixMyStreet::DB::Result::User", { id => "user_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -__PACKAGE__->has_many( - "alert_sents", - "FixMyStreet::DB::Result::AlertSent", - { "foreign.alert_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, -); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d2TrE9UIZdXu3eXYJH0Zmw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vump36YxUO4FQi5Do6DwvA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/AlertSent.pm b/perllib/FixMyStreet/DB/Result/AlertSent.pm index a901c2fde..a537c95cd 100644 --- a/perllib/FixMyStreet/DB/Result/AlertSent.pm +++ b/perllib/FixMyStreet/DB/Result/AlertSent.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::AlertSent; # 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("alert_sent"); __PACKAGE__->add_columns( @@ -30,8 +30,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fTiWIoriQUvHpWc9PpFLvA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oN+36hDWJuc0hqkCW9BHOw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/AlertType.pm b/perllib/FixMyStreet/DB/Result/AlertType.pm index d23a2983d..3aa9677e0 100644 --- a/perllib/FixMyStreet/DB/Result/AlertType.pm +++ b/perllib/FixMyStreet/DB/Result/AlertType.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::AlertType; # 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("alert_type"); __PACKAGE__->add_columns( @@ -47,8 +47,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+PKqo7IZ4MlM9ur4V2P9tA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KDBYzNEAM5lPvZjb9cv22g # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 195fe4019..5b45c63a8 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( @@ -20,6 +20,10 @@ __PACKAGE__->add_columns( }, "problem_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "user_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "anonymous", + { data_type => "boolean", is_nullable => 0 }, "name", { data_type => "text", is_nullable => 1 }, "website", @@ -48,30 +52,26 @@ __PACKAGE__->add_columns( { data_type => "boolean", is_nullable => 0 }, "mark_open", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, - "user_id", - { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, - "anonymous", - { data_type => "boolean", is_nullable => 0 }, "problem_state", { data_type => "text", 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-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E+96vo/AB0zz1jAEPj/OKw use DateTime::TimeZone; use Image::Size; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index 941e4e1bb..c32b75d0c 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Contact; # 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("contacts"); __PACKAGE__->add_columns( @@ -40,8 +40,9 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-08-01 10:07:59 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4y6yRz4rMN66pBpkzfJJhg + +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hyvU0bMWSFxEPAJT7wqM/Q __PACKAGE__->filter_column( extra => { diff --git a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm index 811a06b44..deb00fb95 100644 --- a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm +++ b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::ContactsHistory; # 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("contacts_history"); __PACKAGE__->add_columns( @@ -40,8 +40,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("contacts_history_id"); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9APvBwAOebG5g4MGxJuVKQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dN2ueIDoP3d/+Mg1UDqsMw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index 0a5784560..742a12ebd 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,15 @@ __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 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); -# 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-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ClYnPB2gsKapnfHuco5d/w # 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..532c209d8 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Problem; # 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("problem"); __PACKAGE__->add_columns( @@ -84,6 +84,14 @@ __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", default_value => 0, is_nullable => 0 }, + "send_fail_reason", + { data_type => "text", is_nullable => 1 }, + "send_fail_timestamp", + { data_type => "timestamp", is_nullable => 1 }, + "send_method_used", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -92,22 +100,22 @@ __PACKAGE__->has_many( { "foreign.problem_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); -__PACKAGE__->belongs_to( - "user", - "FixMyStreet::DB::Result::User", - { id => "user_id" }, - { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, -); __PACKAGE__->has_many( "questionnaires", "FixMyStreet::DB::Result::Questionnaire", { "foreign.problem_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__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-09-19 14:38:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nq8Ufn/SEoDGSrrGlHIxag +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-03 16:05:20 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EvwI91Ot7SioQWqwnXRTBQ # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -562,7 +570,50 @@ sub body { return $body; } +# returns true if the external id is the council's ref, i.e., useful to publish it +# (by way of an example, the barnet send method returns a useful reference when +# it succeeds, so that is the ref we should show on the problem report page). +# Future: this is installation-dependent so maybe should be using the contact +# data to determine if the external id is public on a council-by-council basis. +# Note: this only makes sense when called on a problem that has been sent! +sub can_display_external_id { + my $self = shift; + if ($self->external_id && $self->send_method_used && $self->send_method_used eq 'barnet') { + return 1; + } + return 0; +} + # TODO Some/much of this could be moved to the template + +# either: +# "sent to council 3 mins later" +# "[Council name] ref: XYZ" +# or +# "sent to council 3 mins later, their ref: XYZ" +# +# Note: some silliness with pronouns and the adjacent comma mean this is +# being presented as a single string rather than two +sub processed_summary_string { + my ( $problem, $c ) = @_; + my ($duration_clause, $external_ref_clause); + if ($problem->whensent) { + $duration_clause = $problem->duration_string($c) + } + if ($problem->can_display_external_id) { + if ($duration_clause) { + $external_ref_clause = sprintf(_('their ref: %s'), $problem->external_id); + } else { + $external_ref_clause = sprintf(_('%s ref: %s'), $problem->external_body, $problem->external_id); + } + } + if ($duration_clause and $external_ref_clause) { + return "$duration_clause, $external_ref_clause" + } else { + return $duration_clause || $external_ref_clause + } +} + sub duration_string { my ( $problem, $c ) = @_; my $body = $problem->body( $c ); diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index cc4ec300b..b6791603a 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Questionnaire; # 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("questionnaire"); __PACKAGE__->add_columns( @@ -40,8 +40,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QNFqqCg6J4SFlg4zwm7TWw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NGlSRjoBpDoIvK3EueqN6Q use DateTime::TimeZone; diff --git a/perllib/FixMyStreet/DB/Result/Secret.pm b/perllib/FixMyStreet/DB/Result/Secret.pm index 8a1fa671d..449dfec0e 100644 --- a/perllib/FixMyStreet/DB/Result/Secret.pm +++ b/perllib/FixMyStreet/DB/Result/Secret.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Secret; # Created by DBIx::Class::Schema::Loader @@ -7,14 +8,13 @@ use strict; use warnings; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("secret"); __PACKAGE__->add_columns("secret", { data_type => "text", is_nullable => 0 }); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MfqW1K0aFtwpa/1c/UwHjg +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9XiWSKJ1PD3LSYjrSA3drw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Session.pm b/perllib/FixMyStreet/DB/Result/Session.pm index 9d5d509dc..4713c99eb 100644 --- a/perllib/FixMyStreet/DB/Result/Session.pm +++ b/perllib/FixMyStreet/DB/Result/Session.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Session; # 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("sessions"); __PACKAGE__->add_columns( @@ -21,8 +21,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TagSQOXnDttkwfJ7oDH8Yw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MVmCn4gLQWXTDIIaDHiVmA # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm index 3a900858d..b223ada3a 100644 --- a/perllib/FixMyStreet/DB/Result/Token.pm +++ b/perllib/FixMyStreet/DB/Result/Token.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::Token; # 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("token"); __PACKAGE__->add_columns( @@ -27,8 +27,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("scope", "token"); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:frl+na3HrIzGw9D1t891nA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+LLZ8P5GXqPetuGyrra2vw # Trying not to use this # use mySociety::DBHandle qw(dbh); diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 56d726a8d..e13d88b88 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::User; # 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("users"); __PACKAGE__->add_columns( @@ -53,8 +53,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:25:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9IHuqRTcHZCqJeBAaiQxzw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tM1LUGrqDeQnF4BDgnYXGQ __PACKAGE__->add_columns( "password" => { diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 856d7061e..a24f7c102 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -23,10 +23,11 @@ use Digest::MD5 qw(md5_hex); sub string { my ( $s, $c, $params ) = @_; $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i; - my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s&c=en-GB"; # FIXME nb-NO for Norway - $url .= '&mapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] + my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s"; + $url .= '&userMapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] if $params->{bounds}; $url .= '&userLocation=' . $params->{centre} if $params->{centre}; + $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; my $cache_file = $cache_dir . md5_hex($url); @@ -43,7 +44,7 @@ sub string { if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; - } elsif ($js =~ /BT\d/) { + } elsif ($js =~ /BT\d/ && $params->{bing_country} eq 'United Kingdom') { return { error => _("We do not currently cover Northern Ireland, I'm afraid.") }; } @@ -54,24 +55,43 @@ sub string { my $results = $js->{resourceSets}->[0]->{resources}; my ( $error, @valid_locations, $latitude, $longitude ); + foreach (@$results) { my $address = $_->{name}; - next unless $_->{address}->{countryRegion} eq 'United Kingdom'; # FIXME This is UK only + next unless $_->{address}->{countryRegion} eq $params->{bing_country}; + + # Getting duplicate, yet different, results from Bing sometimes + next if @valid_locations + && $_->{address}{postalCode} && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode} + && ( $valid_locations[-1]{address}{locality} eq $_->{address}{adminDistrict2} + || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality} + || $valid_locations[-1]{address}{locality} eq $_->{address}{locality} + ); + ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; - push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); + # These co-ordinates are output as query parameters in a URL, make sure they have a "." + mySociety::Locale::in_gb_locale { + push (@$error, { + address => $address, + latitude => sprintf('%0.6f', $latitude), + longitude => sprintf('%0.6f', $longitude) + }); + }; push (@valid_locations, $_); } + return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; return { error => $error }; } sub reverse { - my ( $latitude, $longitude, $cache ) = @_; + my ( $latitude, $longitude, $bing_culture, $cache ) = @_; # Get nearest road-type thing from Bing my $key = mySociety::Config::get('BING_MAPS_API_KEY', ''); if ($key) { - my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=$key"; + my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key"; + $url .= '&c=' . $bing_culture if $bing_culture; my $j; if ( $cache ) { my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm index 83b36dbcd..1ab347066 100644 --- a/perllib/FixMyStreet/Geocode/Google.pm +++ b/perllib/FixMyStreet/Geocode/Google.pm @@ -75,7 +75,14 @@ sub string { my $address = $_->{address}; next unless $c->cobrand->geocoded_string_check( $address ); ( $longitude, $latitude ) = @{ $_->{Point}->{coordinates} }; - push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); + # These co-ordinates are output as query parameters in a URL, make sure they have a "." + mySociety::Locale::in_gb_locale { + push (@$error, { + address => $address, + latitude => sprintf('%0.6f', $latitude), + longitude => sprintf('%0.6f', $longitude) + }); + }; push (@valid_locations, $_); } return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm new file mode 100644 index 000000000..9cf6de01f --- /dev/null +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# +# FixMyStreet:Map::OSM::CycleMap +# OSM CycleMap maps on FixMyStreet. +# +# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ + +package FixMyStreet::Map::OSM::MapQuest; +use base 'FixMyStreet::Map::OSM'; + +use strict; + +sub map_type { + return 'OpenLayers.Layer.OSM.MapQuestOpen'; +} + +sub map_tiles { + my ($self, $x, $y, $z) = @_; + my $tile_url = $self->base_tile_url(); + return [ + "http://otile1.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", + "http://otile2.$tile_url/$z/$x/" . ($y - 1) . ".png", + "http://otile3.$tile_url/$z/" . ($x - 1) . "/$y.png", + "http://otile4.$tile_url/$z/$x/$y.png", + ]; +} + +sub base_tile_url { + return 'mqcdn.com/tiles/1.0.0/osm/'; +} + +1; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index a8cbc98f2..7daf01f56 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -151,7 +151,7 @@ sub delete_user { ok( $p->delete, "delete problem " . $p->title ); } for my $a ( $user->alerts ) { - $a->alert_sents->delete; + $a->alerts_sent->delete; ok( $a->delete, "delete alert " . $a->alert_type ); } ok( $_->delete, "delete comment " . $_->text ) for $user->comments; |