diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-21 12:31:17 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-21 12:31:17 +0000 |
commit | e2bf144a6aaa19779fc55a04081a3c269b9d0f81 (patch) | |
tree | 00318d801d35948938743608252fccd2d1b4e585 /perllib | |
parent | eb0c0d42f3596c5dc21e9bcdcc02a4008a541c34 (diff) | |
parent | f8a8948ddb790e7e7593d538c55a3a278fbf3973 (diff) |
Merge remote branch 'origin/zurich'
(locale ignored, will rerun .po extraction after to get all changes.)
Conflicts:
locale/FixMyStreet.po
locale/cy_GB.UTF-8/LC_MESSAGES/EmptyHomes.po
locale/de_CH.UTF-8/LC_MESSAGES/FixMyStreet.po
locale/nb_NO.UTF-8/LC_MESSAGES/FixMyStreet.po
locale/nn_NO.UTF-8/LC_MESSAGES/FixMyStreet.po
templates/web/fixmystreet/report/banner.html
templates/web/zurich/faq/faq-de-ch.html
Diffstat (limited to 'perllib')
23 files changed, 459 insertions, 183 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index b76f4d3ba..4469ad1c9 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -315,6 +315,7 @@ sub send_email { { _template_ => $email->body, # will get line wrapped _parameters_ => {}, + _line_indent => $c->cobrand->email_indent, $email->header_pairs } ) }; @@ -443,18 +444,29 @@ Hashref contains height, width and url keys. sub get_photo_params { my ($self, $key) = @_; - $key = ($key eq 'id') ? '' : "/$key"; return {} unless $self->photo; + $key = ($key eq 'id') ? '' : "/$key"; + + my $pre = "/photo$key/" . $self->id; + my $post = '.jpeg'; my $photo = {}; + if (length($self->photo) == 40) { - $photo->{url_full} = '/photo' . $key . '/' . $self->id . '.full.jpeg'; + $post .= '?' . $self->photo; + $photo->{url_full} = "$pre.full$post"; + # XXX Can't use size here because {url} (currently 250px height) may be + # being used, but at this point it doesn't yet exist to find the width + # $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg'; } else { - ( $photo->{width}, $photo->{height} ) = - Image::Size::imgsize( \$self->photo ); + my $str = \$self->photo; + ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str ); } - $photo->{url} = '/photo' . $key . '/' . $self->id . '.jpeg'; + + $photo->{url} = "$pre$post"; + $photo->{url_tn} = "$pre.tn$post"; + $photo->{url_fp} = "$pre.fp$post"; return $photo; } diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index a3a241590..bb7ec2381 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -145,34 +145,34 @@ sub timeline : Path( 'timeline' ) : Args(0) { my $probs = $c->cobrand->problems->timeline; foreach ($probs->all) { - push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created_local, obj => $_ }; - push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed_local, obj => $_ } if $_->confirmed; - push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent_local, obj => $_ } if $_->whensent; + push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created, obj => $_ }; + push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed, obj => $_ } if $_->confirmed; + push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent, obj => $_ } if $_->whensent; } my $questionnaires = $c->model('DB::Questionnaire')->timeline( $c->cobrand->restriction ); foreach ($questionnaires->all) { - push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent_local, obj => $_ }; - push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered_local, obj => $_ } if $_->whenanswered; + push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent, obj => $_ }; + push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered; } my $updates = $c->model('DB::Comment')->timeline( $site_restriction ); foreach ($updates->all) { - push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created_local, obj => $_} ; + push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ; } my $alerts = $c->model('DB::Alert')->timeline_created( $c->cobrand->restriction ); foreach ($alerts->all) { - push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed_local, obj => $_ }; + push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed, obj => $_ }; } $alerts = $c->model('DB::Alert')->timeline_disabled( $c->cobrand->restriction ); foreach ($alerts->all) { - push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled_local, obj => $_ }; + push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled, obj => $_ }; } $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); @@ -485,6 +485,25 @@ sub body_edit : Path('body_edit') : Args(2) { sub reports : Path('reports') { my ( $self, $c ) = @_; + my $query = {}; + if ( $c->cobrand->moniker eq 'zurich' ) { + my $type = $c->stash->{admin_type}; + my $body = $c->stash->{body}; + if ( $type eq 'dm' ) { + my @children = map { $_->id } $body->bodies->all; + my @all = (@children, $body->id); + $query = { bodies_str => \@all }; + } elsif ( $type eq 'sdm' ) { + $query = { bodies_str => $body->id }; + } + } + + my $order = $c->req->params->{o} || 'created'; + my $dir = defined $c->req->params->{d} ? $c->req->params->{d} : 1; + $c->stash->{order} = $order; + $c->stash->{dir} = $dir; + $order .= ' desc' if $dir; + if (my $search = $c->req->param('search')) { $c->stash->{searched} = $search; @@ -503,21 +522,20 @@ sub reports : Path('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 = [ + $query->{'-or'} = [ 'user.email' => { ilike => $like_search }, ]; } elsif ($search =~ /^id:(\d+)$/) { - $query = [ + $query->{'-or'} = [ 'me.id' => int($1), ]; } elsif ($search =~ /^area:(\d+)$/) { - $query = [ + $query->{'-or'} = [ 'me.areas' => { like => "%,$1,%" } ]; } else { - $query = [ + $query->{'-or'} = [ 'me.id' => $search_n, 'user.email' => { ilike => $like_search }, 'me.name' => { ilike => $like_search }, @@ -527,13 +545,12 @@ sub reports : Path('reports') { cobrand_data => { like => $like_search }, ]; } + my $problems = $c->cobrand->problems->search( - { - -or => $query, - }, + $query, { prefetch => 'user', - order_by => [\"(state='hidden')",'created'] + order_by => [ \"(state='hidden')", \$order ] } ); @@ -576,7 +593,7 @@ sub reports : Path('reports') { { -select => [ 'me.*', qw/problem.bodies_str problem.state/ ], prefetch => [qw/user problem/], - order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] + order_by => [ \"(me.state='hidden')", \"(problem.state='hidden')", 'me.created' ] } ); $c->stash->{updates} = [ $updates->all ]; @@ -584,6 +601,15 @@ sub reports : Path('reports') { # Switch quoting back off. See above for explanation of this. $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); + } else { + + my $page = $c->req->params->{p} || 1; + my $problems = $c->cobrand->problems->search( + $query, + { order_by => $order } + )->page( $page ); + $c->stash->{problems} = [ $problems->all ]; + $c->stash->{pager} = $problems->pager; } } @@ -601,13 +627,8 @@ sub report_edit : Path('report_edit') : Args(1) { $c->forward('get_token'); - if ( $c->req->param('rotate_photo') ) { - $c->forward('rotate_photo'); - return 1; - } - if ( $c->cobrand->moniker eq 'zurich' ) { - + $c->stash->{page} = 'admin'; FixMyStreet::Map::display_map( $c, latitude => $problem->latitude, @@ -616,12 +637,19 @@ sub report_edit : Path('report_edit') : Args(1) { ? [ { latitude => $problem->latitude, longitude => $problem->longitude, - colour => 'yellow', + colour => $c->cobrand->pin_colour($problem), type => 'big', } ] : [], ); + } + + if ( $c->req->param('rotate_photo') ) { + $c->forward('rotate_photo'); + return 1; + } + if ( $c->cobrand->moniker eq 'zurich' ) { my $done = $c->cobrand->admin_report_edit(); return if $done; } @@ -782,6 +810,16 @@ sub users: Path('users') : Args(0) { } else { $c->forward('get_token'); $c->forward('fetch_all_bodies'); + + # Admin users by default + my $users = $c->model('DB::User')->search( + { from_body => { '!=', undef } }, + { order_by => 'name' } + ); + my @users = $users->all; + my %email2user = map { $_->email => $_ } @users; + $c->stash->{users} = \@users; + } return 1; @@ -903,6 +941,8 @@ sub user_add : Path('user_edit') : Args(0) { $c->forward('check_token'); + return unless $c->req->param('name') && $c->req->param('email'); + my $user = $c->model('DB::User')->find_or_create( { name => $c->req->param('name'), email => $c->req->param('email'), @@ -982,7 +1022,7 @@ sub stats : Path('stats') : Args(0) { $c->forward('fetch_all_bodies'); - if ( $c->cobrand->moniker eq 'seesomething' ) { + if ( $c->cobrand->moniker eq 'seesomething' || $c->cobrand->moniker eq 'zurich' ) { return $c->cobrand->admin_stats(); } @@ -1288,7 +1328,7 @@ sub rotate_photo : Private { my ( $self, $c ) =@_; my $direction = $c->req->param('rotate_photo'); - return unless $direction =~ /Left/ or $direction =~ /Right/; + return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right'); my $photo = $c->stash->{problem}->photo; my $file; @@ -1299,16 +1339,12 @@ sub rotate_photo : Private { $photo = $file->slurp; } - $photo = _rotate_image( $photo, $direction =~ /Left/ ? -90 : 90 ); + $photo = _rotate_image( $photo, $direction eq _('Rotate Left') ? -90 : 90 ); return unless $photo; - my $fileid; - if ( !$file ) { - $fileid = sha1_hex($photo); - $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - } - - $c->stash->{rotated} = 1; + # Write out to new location + my $fileid = sha1_hex($photo); + $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); my $fh = $file->open('w'); print $fh $photo; @@ -1316,10 +1352,8 @@ sub rotate_photo : Private { unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' ); - if ( $fileid ) { - $c->stash->{problem}->photo( $fileid ); - $c->stash->{problem}->update(); - } + $c->stash->{problem}->photo( $fileid ); + $c->stash->{problem}->update(); return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 9a754f063..bad269a83 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -40,9 +40,10 @@ sub around_index : Path : Args(0) { my $partial_report = $c->forward('load_partial'); # Try to create a location for whatever we have - return - unless $c->forward('/location/determine_location_from_coords') - || $c->forward('/location/determine_location_from_pc'); + my $ret = $c->forward('/location/determine_location_from_coords') + || $c->forward('/location/determine_location_from_pc'); + return unless $ret; + return $c->res->redirect('/') if $ret == -1 && !$partial_report; # Check to see if the spot is covered by a area - if not show an error. return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable'); diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index f4d6d86e4..57b53a155 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -31,7 +31,7 @@ sub general : Path : Args(0) { my $req = $c->req; $c->detach( 'redirect_on_signin', [ $req->param('r') ] ) - if $c->user && $req->param('r') && $req->param('r') !~ /admin/; + if $c->user && $req->param('r'); # all done unless we have a form posted to us return unless $req->method eq 'POST'; @@ -182,6 +182,10 @@ Used after signing in to take the person back to where they were. sub redirect_on_signin : Private { my ( $self, $c, $redirect ) = @_; $redirect = 'my' unless $redirect; + if ( $c->cobrand->moniker eq 'zurich' ) { + $redirect = 'my' if $redirect eq 'admin'; + $redirect = 'admin' if $c->user->from_body; + } $c->res->redirect( $c->uri_for( "/$redirect" ) ); } diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index fd3fadd9f..f103ff7f9 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -50,6 +50,8 @@ sub determine_location_from_coords : Private { User has searched for a location - try to find it for them. +Return -1 if nothing provided. + If one match is found returns true and lat/lng is set. If several possible matches are found puts an array onto stash so that user can be prompted to pick one and returns false. @@ -62,7 +64,7 @@ sub determine_location_from_pc : Private { my ( $self, $c, $pc ) = @_; # check for something to search - $pc ||= $c->req->param('pc') || return; + $pc ||= $c->req->param('pc') || return -1; $c->stash->{pc} = $pc; # for template if ( $pc =~ /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/ ) { diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 7b8cb649f..a4e72e9bd 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -240,8 +240,8 @@ sub output_requests : Private { 'long' => [ $problem->longitude ], 'status' => [ $problem->state ], # 'status_notes' => [ {} ], - 'requested_datetime' => [ w3date($problem->confirmed_local) ], - 'updated_datetime' => [ w3date($problem->lastupdate_local) ], + 'requested_datetime' => [ w3date($problem->confirmed) ], + 'updated_datetime' => [ w3date($problem->lastupdate) ], # 'expected_datetime' => [ {} ], # 'address' => [ {} ], # 'address_id' => [ {} ], @@ -260,7 +260,7 @@ sub output_requests : Private { if ( $problem->whensent ) { # Not in Open311 v2 $request->{'agency_sent_datetime'} = - [ w3date($problem->whensent_local) ]; + [ w3date($problem->whensent) ]; } # Extract number of updates diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 460ccaec5..57b2d781e 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -173,7 +173,10 @@ sub format_problem_for_display : Private { if ( $c->stash->{ajax} ) { $c->res->content_type('application/json; charset=utf-8'); my $content = JSON->new->utf8(1)->encode( - $problem->as_hashref( $c ) + { + report => $c->cobrand->problem_as_hashref( $problem, $c ), + updates => $c->cobrand->updates_as_hashref( $problem, $c ), + } ); $c->res->body( $content ); return 1; @@ -196,7 +199,7 @@ sub generate_map_tags : Private { ? [ { latitude => $problem->latitude, longitude => $problem->longitude, - colour => 'yellow', + colour => $c->cobrand->moniker eq 'zurich'? $c->cobrand->pin_colour($problem) : 'yellow', type => 'big', } ] : [], diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 0c8d567c4..257d9ec24 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -708,7 +708,7 @@ Returns the colour of pin to be used for a particular report =cut sub pin_colour { my ( $self, $p, $context ) = @_; - #return 'green' if time() - $p->confirmed_local->epoch < 7 * 24 * 60 * 60; + #return 'green' if time() - $p->confirmed->epoch < 7 * 24 * 60 * 60; return 'yellow' if $context eq 'around' || $context eq 'reports'; return $p->is_fixed ? 'green' : 'red'; } @@ -795,5 +795,44 @@ sub show_unconfirmed_reports { 0; } +=head2 prettify_dt + + my $date = $c->prettify_dt( $datetime ); + +Takes a datetime object and returns a string representation. + +=cut + +sub prettify_dt { + my $self = shift; + my $dt = shift; + + return Utils::prettify_dt( $dt, 1 ); +} + +=head2 email_indent + +Set to an indent string if you wish to override the default email handling. + +=cut + +sub email_indent { undef; } + +sub problem_as_hashref { + my $self = shift; + my $problem = shift; + my $ctx = shift; + + return $problem->as_hashref( $ctx ); +} + +sub updates_as_hashref { + my $self = shift; + my $problem = shift; + my $ctx = shift; + + return {}; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index ec65ec8f0..7ac776df2 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -39,11 +39,68 @@ sub languages { [ 'de-ch,Deutsch,de_CH', 'en-gb,English,en_GB' ] }; sub uri { my ( $self, $uri ) = @_; - $uri->query_param( zoom => 7 ) + $uri->query_param( zoom => 6 ) if $uri->query_param('lat') && !$uri->query_param('zoom'); return $uri; } +sub prettify_dt { + my $self = shift; + my $dt = shift; + + return Utils::prettify_dt( $dt, 'zurich' ); +} + +sub problem_as_hashref { + my $self = shift; + my $problem = shift; + my $ctx = shift; + + my $hashref = $problem->as_hashref( $ctx ); + + if ( $problem->state eq 'unconfirmed' ) { + for my $var ( qw( photo detail state state_t is_fixed meta ) ) { + delete $hashref->{ $var }; + } + $hashref->{detail} = _('This report is awaiting moderation.'); + $hashref->{state} = 'submitted'; + $hashref->{state_t} = _('Submitted'); + } else { + if ( $problem->state eq 'confirmed' ) { + $hashref->{state} = 'open'; + $hashref->{state_t} = _('Open'); + } elsif ( $problem->is_fixed ) { + $hashref->{state} = 'closed'; + $hashref->{state_t} = _('Closed'); + } elsif ( $problem->state eq 'in progress' || $problem->state eq 'planned' ) { + $hashref->{state} = 'in progress'; + $hashref->{state_t} = _('In progress'); + } + } + + return $hashref; +} + +sub updates_as_hashref { + my $self = shift; + my $problem = shift; + my $ctx = shift; + + my $hashref = {}; + + if ( $problem->state eq 'fixed - council' || $problem->state eq 'closed' ) { + $hashref->{update_pp} = $self->prettify_dt( $problem->lastupdate ); + + if ( $problem->state eq 'fixed - council' ) { + $hashref->{details} = FixMyStreet::App::View::Web->add_links( $ctx, $problem->extra->{public_response} ); + } elsif ( $problem->state eq 'closed' ) { + $hashref->{details} = sprintf( _('Assigned to %s'), $problem->body($ctx)->name ); + } + } + + return $hashref; +} + sub remove_redundant_areas { my $self = shift; my $all_areas = shift; @@ -115,16 +172,18 @@ sub overdue { if ( $problem->state eq 'unconfirmed' || $problem->state eq 'confirmed' ) { # One working day $w = add_days( $w, 1 ); - return $w < DateTime->now(); + return $w < DateTime->now() ? 1 : 0; } elsif ( $problem->state eq 'in progress' ) { # Five working days $w = add_days( $w, 5 ); - return $w < DateTime->now(); + return $w < DateTime->now() ? 1 : 0; } else { return 0; } } +sub email_indent { ''; } + # Specific administrative displays sub admin_pages { @@ -149,6 +208,7 @@ sub admin_pages { $pages = { %$pages, 'users' => [_('Users'), 3], + 'stats' => [_('Stats'), 4], 'user_edit' => [undef, undef], }; return $pages if $type eq 'super'; @@ -188,37 +248,68 @@ sub admin { my @children = map { $_->id } $body->bodies->all; my @all = (@children, $body->id); + my $order = $c->req->params->{o} || 'created'; + my $dir = defined $c->req->params->{d} ? $c->req->params->{d} : 1; + $c->stash->{order} = $order; + $c->stash->{dir} = $dir; + $order .= ' desc' if $dir; + # XXX No multiples or missing bodies $c->stash->{unconfirmed} = $c->cobrand->problems->search({ state => [ 'unconfirmed', 'confirmed' ], bodies_str => $c->stash->{body}->id, + }, { + order_by => $order, }); $c->stash->{approval} = $c->cobrand->problems->search({ state => 'planned', bodies_str => $c->stash->{body}->id, + }, { + order_by => $order, }); + + my $page = $c->req->params->{p} || 1; $c->stash->{other} = $c->cobrand->problems->search({ state => { -not_in => [ 'unconfirmed', 'confirmed', 'planned' ] }, bodies_str => \@all, - }); + }, { + order_by => $order, + })->page( $page ); + $c->stash->{pager} = $c->stash->{other}->pager; + } elsif ($type eq 'sdm') { $c->stash->{template} = 'admin/index-sdm.html'; my $body = $c->stash->{body}; + my $order = $c->req->params->{o} || 'created'; + my $dir = defined $c->req->params->{d} ? $c->req->params->{d} : 1; + $c->stash->{order} = $order; + $c->stash->{dir} = $dir; + $order .= ' desc' if $dir; + # XXX No multiples or missing bodies $c->stash->{reports_new} = $c->cobrand->problems->search( { state => 'in progress', bodies_str => $body->id, + }, { + order_by => $order } ); $c->stash->{reports_unpublished} = $c->cobrand->problems->search( { state => 'planned', bodies_str => $body->parent->id, + }, { + order_by => $order } ); + + my $page = $c->req->params->{p} || 1; $c->stash->{reports_published} = $c->cobrand->problems->search( { state => 'fixed - council', bodies_str => $body->parent->id, - } ); + }, { + order_by => $order + } )->page( $page ); + $c->stash->{pager} = $c->stash->{reports_published}->pager; } } @@ -274,8 +365,7 @@ sub admin_report_edit { $extra->{publish_photo} = $c->req->params->{publish_photo} || 0; $extra->{third_personal} = $c->req->params->{third_personal} || 0; # Make sure we have a copy of the original detail field - $extra->{original_detail} = $problem->detail unless $extra->{original_detail}; - $problem->extra( { %$extra } ); + $extra->{original_detail} = $problem->detail if !$extra->{original_detail} && $c->req->params->{detail} && $problem->detail ne $c->req->params->{detail}; # Workflow things my $redirect = 0; @@ -286,14 +376,17 @@ sub admin_report_edit { $problem->external_body( undef ); $problem->bodies_str( $cat->body_id ); $problem->whensent( undef ); + $extra->{changed_category} = 1; $redirect = 1 if $cat->body_id ne $body->id; } elsif ( my $subdiv = $c->req->params->{body_subdivision} ) { + $extra->{moderated_overdue} = $self->overdue( $problem ); $problem->state( 'in progress' ); $problem->external_body( undef ); $problem->bodies_str( $subdiv ); $problem->whensent( undef ); $redirect = 1; } elsif ( my $external = $c->req->params->{body_external} ) { + $extra->{moderated_overdue} = $self->overdue( $problem ); $problem->state( 'closed' ); $problem->external_body( $external ); $problem->whensent( undef ); @@ -306,8 +399,11 @@ sub admin_report_edit { } } + $problem->extra( { %$extra } ); $problem->title( $c->req->param('title') ); $problem->detail( $c->req->param('detail') ); + $problem->latitude( $c->req->param('latitude') ); + $problem->longitude( $c->req->param('longitude') ); # Final, public, Update from DM if (my $update = $c->req->param('status_update')) { @@ -357,14 +453,23 @@ sub admin_report_edit { } elsif ($c->req->param('submit')) { $c->forward('check_token'); + my $db_update = 0; + if ( $c->req->param('latitude') != $problem->latitude || $c->req->param('longitude') != $problem->longitude ) { + $problem->latitude( $c->req->param('latitude') ); + $problem->longitude( $c->req->param('longitude') ); + $db_update = 1; + } + my $extra = $problem->extra || {}; $extra->{internal_notes} ||= ''; if ($c->req->param('internal_notes') && $c->req->param('internal_notes') ne $extra->{internal_notes}) { $extra->{internal_notes} = $c->req->param('internal_notes'); $problem->extra( { %$extra } ); - $problem->update; + $db_update = 1; } + $problem->update if $db_update; + # Add new update from status_update if (my $update = $c->req->param('status_update')) { FixMyStreet::App->model('DB::Comment')->create( { @@ -384,9 +489,11 @@ sub admin_report_edit { if ($c->req->param('no_more_updates')) { $problem->bodies_str( $body->parent->id ); $problem->whensent( undef ); + my $extra = $problem->extra || {}; + $extra->{subdiv_overdue} = $self->overdue( $problem ); + $problem->extra( { %$extra } ); $problem->state( 'planned' ); $problem->update; - # log here $c->res->redirect( '/admin/summary' ); } } @@ -412,9 +519,15 @@ sub _admin_send_email { ? [ $problem->user->email, $problem->name ] : $problem->user->email; + # Similar to what SendReport::Zurich does to find address to send to + my $body = ( values %{$problem->bodies} )[0]; + my $sender = $body->endpoint || $c->cobrand->contact_email; + my $sender_name = $c->cobrand->contact_name; # $body->name? + $c->send_email( $template, { to => [ $to ], url => $c->uri_for_email( $problem->url ), + from => [ $sender, $sender_name ], } ); } @@ -457,4 +570,94 @@ sub admin_fetch_all_bodies { return @out; } +sub admin_stats { + my $self = shift; + my $c = $self->{c}; + + my %date_params; + my $ym = $c->req->params->{ym}; + my ($m, $y) = $ym =~ /^(\d+)\.(\d+)$/; + $c->stash->{ym} = $ym; + if ($y && $m) { + $c->stash->{start_date} = DateTime->new( year => $y, month => $m, day => 1 ); + $c->stash->{end_date} = $c->stash->{start_date} + DateTime::Duration->new( months => 1 ); + $date_params{created} = { '>=', $c->stash->{start_date}, '<', $c->stash->{end_date} }; + } + + my %params = ( + %date_params, + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + ); + + if ( $c->req->params->{export} ) { + my $problems = $c->model('DB::Problem')->search( { %params }, { columns => [ 'id', 'created', 'latitude', 'longitude', 'cobrand', 'category' ] } ); + my $body = "ID,Created,E,N,Category\n"; + while (my $report = $problems->next) { + $body .= join( ',', $report->id, $report->created, $report->local_coords, $report->category ) . "\n"; + } + $c->res->content_type('text/csv; charset=utf-8'); + $c->res->body($body); + } + + # Total reports (non-hidden) + my $total = $c->model('DB::Problem')->search( \%params )->count; + # Device for apps (iOS/Android) + my $per_service = $c->model('DB::Problem')->search( \%params, { + select => [ 'service', { count => 'id' } ], + as => [ 'service', 'c' ], + group_by => [ 'service' ], + }); + # Reports solved + my $solved = $c->model('DB::Problem')->search( { state => 'fixed - council', %date_params } )->count; + # Reports marked as spam + my $hidden = $c->model('DB::Problem')->search( { state => 'hidden', %date_params } )->count; + # Reports assigned to third party + my $closed = $c->model('DB::Problem')->search( { state => 'closed', %date_params } )->count; + # Reports moderated within 1 day + my $moderated = $c->model('DB::Problem')->search( { extra => { like => '%moderated_overdue,I1:0%' }, %params } )->count; + # Reports solved within 5 days + my $subdiv_dealtwith = $c->model('DB::Problem')->search( { extra => { like => '%subdiv_overdue,I1:0%' }, %params } )->count; + # Reports per category + my $per_category = $c->model('DB::Problem')->search( \%params, { + select => [ 'category', { count => 'id' } ], + as => [ 'category', 'c' ], + group_by => [ 'category' ], + }); + # How many reports have had their category changed by a DM (wrong category chosen by user) + my $changed = $c->model('DB::Problem')->search( { extra => { like => '%changed_category,I1:1%' }, %params } )->count; + # pictures taken + my $pictures_taken = $c->model('DB::Problem')->search( { photo => { '!=', undef }, %params } )->count; + # pictures published + my $pictures_published = $c->model('DB::Problem')->search( { extra => { like => '%publish_photo,I1:1%' }, %params } )->count; + # how many times was a telephone number provided + # XXX => How many users have a telephone number stored + # my $phone = $c->model('DB::User')->search( { phone => { '!=', undef } } )->count; + # how many times was the email address confirmed + my $email_confirmed = $c->model('DB::Problem')->search( { extra => { like => '%email_confirmed%' }, %params } )->count; + # how many times was the name provided + my $name = $c->model('DB::Problem')->search( { name => { '!=', '' }, %params } )->count; + # how many times was the geolocation used vs. addresssearch + # ? + + $c->stash( + per_service => $per_service, + per_category => $per_category, + reports_total => $total, + reports_solved => $solved, + reports_spam => $hidden, + reports_assigned => $closed, + reports_moderated => $moderated, + reports_dealtwith => $subdiv_dealtwith, + reports_category_changed => $changed, + pictures_taken => $pictures_taken, + pictures_published => $pictures_published, + #users_phone => $phone, + email_confirmed => $email_confirmed, + name_provided => $name, + # GEO + ); + + return 1; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index ca9ad45c2..fc84c8fd5 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -77,22 +77,21 @@ with 'FixMyStreet::Roles::Abuser'; my $tz = DateTime::TimeZone->new( name => "local" ); - -sub whensubscribed_local { - my $self = shift; - - return $self->whensubscribed - ? $self->whensubscribed->set_time_zone($tz) - : $self->whensubscribed; -} - -sub whendisabled_local { - my $self = shift; - - return $self->whendisabled - ? $self->whendisabled->set_time_zone($tz) - : $self->whendisabled; -} +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + +my $stz = sub { + my ( $orig, $self ) = ( shift, shift ); + my $s = $self->$orig(@_); + return $s unless $s && UNIVERSAL::isa($s, "DateTime"); + $s->set_time_zone($tz); + $s->set_time_zone($tz_f) if $tz_f; + return $s; +}; + +around whensubscribed => $stz; +around whendisabled => $stz; =head2 confirm diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 33fbb9356..eb9e52a65 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -116,23 +116,21 @@ with 'FixMyStreet::Roles::Abuser'; my $tz = DateTime::TimeZone->new( name => "local" ); -sub created_local { - my $self = shift; - - return $self->created - ? $self->created->set_time_zone($tz) - : $self->created; -} - -sub confirmed_local { - my $self = shift; - - # if confirmed is null then it doesn't get inflated so don't - # try and set the timezone - return $self->confirmed - ? $self->confirmed->set_time_zone($tz) - : $self->confirmed; -} +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + +my $stz = sub { + my ( $orig, $self ) = ( shift, shift ); + my $s = $self->$orig(@_); + return $s unless $s && UNIVERSAL::isa($s, "DateTime"); + $s->set_time_zone($tz); + $s->set_time_zone($tz_f) if $tz_f; + return $s; +}; + +around created => $stz; +around confirmed => $stz; # 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 24aa12944..ec15600b6 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -301,6 +301,7 @@ sub all_states { 'confirmed' => 1, 'investigating' => 1, 'in progress' => 1, + 'planned' => 1, 'action scheduled' => 1, 'fixed' => 1, 'fixed - council' => 1, @@ -342,37 +343,23 @@ sub council_states { my $tz = DateTime::TimeZone->new( name => "local" ); -sub confirmed_local { - my $self = shift; - - return $self->confirmed - ? $self->confirmed->set_time_zone($tz) - : $self->confirmed; -} - -sub created_local { - my $self = shift; - - return $self->created - ? $self->created->set_time_zone($tz) - : $self->created; -} - -sub whensent_local { - my $self = shift; +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); - return $self->whensent - ? $self->whensent->set_time_zone($tz) - : $self->whensent; -} - -sub lastupdate_local { - my $self = shift; +my $stz = sub { + my ( $orig, $self ) = ( shift, shift ); + my $s = $self->$orig(@_); + return $s unless $s && UNIVERSAL::isa($s, "DateTime"); + $s->set_time_zone($tz); + $s->set_time_zone($tz_f) if $tz_f; + return $s; +}; - return $self->lastupdate - ? $self->lastupdate->set_time_zone($tz) - : $self->lastupdate; -} +around created => $stz; +around confirmed => $stz; +around whensent => $stz; +around lastupdate => $stz; around service => sub { my ( $orig, $self ) = ( shift, shift ); @@ -574,7 +561,7 @@ meta data about the report. sub meta_line { my ( $problem, $c ) = @_; - my $date_time = Utils::prettify_dt( $problem->confirmed_local ); + my $date_time = Utils::prettify_dt( $problem->confirmed ); my $meta = ''; # FIXME Should be in cobrand @@ -709,7 +696,7 @@ sub duration_string { my ( $problem, $c ) = @_; my $body = $problem->body( $c ); return sprintf(_('Sent to %s %s later'), $body, - Utils::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') + Utils::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute') ); } @@ -832,8 +819,8 @@ sub as_hashref { is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0, photo => $self->get_photo_params, meta => $self->confirmed ? $self->meta_line( $c ) : '', - confirmed_pp => $self->confirmed ? Utils::prettify_dt( $self->confirmed_local, 1 ): '', - created_pp => Utils::prettify_dt( $self->created_local, 1 ), + confirmed_pp => $self->confirmed ? $c->cobrand->prettify_dt( $self->confirmed ): '', + created_pp => $c->cobrand->prettify_dt( $self->created ), }; } diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index b6791603a..fcaa17d99 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -44,23 +44,25 @@ __PACKAGE__->belongs_to( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NGlSRjoBpDoIvK3EueqN6Q use DateTime::TimeZone; +use Moose; +use namespace::clean -except => [ 'meta' ]; my $tz = DateTime::TimeZone->new( name => "local" ); -sub whensent_local { - my $self = shift; +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); - return $self->whensent - ? $self->whensent->set_time_zone($tz) - : $self->whensent; -} +my $stz = sub { + my ( $orig, $self ) = ( shift, shift ); + my $s = $self->$orig(@_); + return $s unless $s && UNIVERSAL::isa($s, "DateTime"); + $s->set_time_zone($tz); + $s->set_time_zone($tz_f) if $tz_f; + return $s; +}; -sub whenanswered_local { - my $self = shift; - - return $self->whenanswered - ? $self->whenanswered->set_time_zone($tz) - : $self->whenanswered; -} +around whensent => $stz; +around whenanswered => $stz; 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 8e9b3d17e..f2b86725d 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -236,6 +236,7 @@ sub _send_aggregated_alert_email(%) { { _template_ => $template, _parameters_ => \%data, + _line_indent => $cobrand->email_indent, From => [ $sender, _($cobrand->contact_name) ], To => $data{alert_email}, }, diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 116151753..dc1c5c248 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -269,7 +269,7 @@ sub send_reports { # Template variables for the email my $email_base_url = $cobrand->base_url_for_report($row); my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/; - map { $h{$_} = $row->user->$_ } qw/email phone/; + map { $h{$_} = $row->user->$_ || '' } qw/email phone/; $h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) ) if $row->confirmed; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 1b9521a9f..8d811180e 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -101,6 +101,7 @@ sub send_questionnaires_period { { _template_ => $template, _parameters_ => \%h, + _line_indent => $cobrand->email_indent, To => [ [ $row->user->email, $row->name ] ], From => [ $sender, $sender_name ], }, diff --git a/perllib/FixMyStreet/Map/Zurich.pm b/perllib/FixMyStreet/Map/Zurich.pm index 262b6e229..73ebc5608 100644 --- a/perllib/FixMyStreet/Map/Zurich.pm +++ b/perllib/FixMyStreet/Map/Zurich.pm @@ -13,9 +13,10 @@ use Geo::Coordinates::CH1903; use Math::Trig; use Utils; -use constant ZOOM_LEVELS => 7; +use constant ZOOM_LEVELS => 8; use constant DEFAULT_ZOOM => 5; use constant MIN_ZOOM_LEVEL => 0; +use constant ID_OFFSET => 2; sub map_tiles { my ( $self, %params ) = @_; @@ -45,31 +46,24 @@ sub copyright { sub display_map { my ($self, $c, %params) = @_; - my $numZoomLevels = ZOOM_LEVELS; - my $zoomOffset = MIN_ZOOM_LEVEL; -# if ($params{any_zoom}) { -# $numZoomLevels = 10; -# $zoomOffset = 0; -# } - - # TODO Adjust zoom level dependent upon population density - my $default_zoom = DEFAULT_ZOOM; - # Map centre may be overridden in the query string $params{latitude} = Utils::truncate_coordinate($c->req->params->{lat} + 0) if defined $c->req->params->{lat}; $params{longitude} = Utils::truncate_coordinate($c->req->params->{lon} + 0) if defined $c->req->params->{lon}; - my $zoom = defined $c->req->params->{zoom} ? $c->req->params->{zoom} + 0 : $default_zoom; - $zoom = $numZoomLevels - 1 if $zoom >= $numZoomLevels; + my $zoom = defined $c->req->params->{zoom} + ? $c->req->params->{zoom} + 0 + : $c->stash->{page} eq 'report' + ? DEFAULT_ZOOM+1 + : DEFAULT_ZOOM; + $zoom = ZOOM_LEVELS - 1 if $zoom >= ZOOM_LEVELS; $zoom = 0 if $zoom < 0; - $params{zoom_act} = $zoomOffset + $zoom; - ($params{x_tile}, $params{y_tile}, $params{matrix_id}) = latlon_to_tile_with_adjust($params{latitude}, $params{longitude}, $params{zoom_act}); + ($params{x_tile}, $params{y_tile}, $params{matrix_id}) = latlon_to_tile_with_adjust($params{latitude}, $params{longitude}, $zoom); foreach my $pin (@{$params{pins}}) { - ($pin->{px}, $pin->{py}) = latlon_to_px($pin->{latitude}, $pin->{longitude}, $params{x_tile}, $params{y_tile}, $params{zoom_act}); + ($pin->{px}, $pin->{py}) = latlon_to_px($pin->{latitude}, $pin->{longitude}, $params{x_tile}, $params{y_tile}, $zoom); } $c->stash->{map} = { @@ -79,8 +73,8 @@ sub display_map { tiles => $self->map_tiles( %params ), copyright => $self->copyright(), zoom => $zoom, - zoomOffset => $zoomOffset, - numZoomLevels => $numZoomLevels, + zoomOffset => MIN_ZOOM_LEVEL, + numZoomLevels => ZOOM_LEVELS, }; } @@ -90,13 +84,11 @@ sub latlon_to_tile($$$) { my ($x, $y) = Geo::Coordinates::CH1903::from_latlon($lat, $lon); - my $matrix_id = $zoom; - $matrix_id = 0 if $matrix_id < 0; - - my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000' ); + my $matrix_id = $zoom + ID_OFFSET; + my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ); my $tileOrigin = { lat => 30814423, lon => -29386322 }; my $tileSize = 256; - my $res = $scales[$zoom] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH + my $res = $scales[$matrix_id] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH my $fx = ( $x - $tileOrigin->{lon} ) / ($res * $tileSize); my $fy = ( $tileOrigin->{lat} - $y ) / ($res * $tileSize); @@ -124,10 +116,11 @@ sub latlon_to_tile_with_adjust($$$) { sub tile_to_latlon { my ($fx, $fy, $zoom) = @_; + my $matrix_id = $zoom + ID_OFFSET; my @scales = ( '250000', '125000', '64000', '32000', '16000', '8000', '4000', '2000', '1000', '500' ); my $tileOrigin = { lat => 30814423, lon => -29386322 }; my $tileSize = 256; - my $res = $scales[$zoom] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH + my $res = $scales[$matrix_id] / (39.3701 * 96); # OpenLayers.INCHES_PER_UNIT[units] * OpenLayers.DOTS_PER_INCH my $x = $fx * $res * $tileSize + $tileOrigin->{lon}; my $y = $tileOrigin->{lat} - $fy * $res * $tileSize; @@ -164,12 +157,11 @@ sub click_to_tile { # Given some click co-ords (the tile they were on, and where in the # tile they were), convert to WGS84 and return. -# XXX Note use of MIN_ZOOM_LEVEL here. (Copied from OSM, needed here?) sub click_to_wgs84 { my ($self, $c, $pin_tile_x, $pin_x, $pin_tile_y, $pin_y) = @_; my $tile_x = click_to_tile($pin_tile_x, $pin_x); my $tile_y = click_to_tile($pin_tile_y, $pin_y); - my $zoom = MIN_ZOOM_LEVEL + (defined $c->req->params->{zoom} ? $c->req->params->{zoom} : DEFAULT_ZOOM); + my $zoom = (defined $c->req->params->{zoom} ? $c->req->params->{zoom} : DEFAULT_ZOOM); my ($lat, $lon) = tile_to_latlon($tile_x, $tile_y, $zoom); return ( $lat, $lon ); } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 1ff476da3..9006e2f11 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -87,6 +87,7 @@ sub send { { _template_ => $self->get_template( $row ), _parameters_ => $h, + _line_indent => $row->cobrand eq 'zurich' ? '' : undef, # XXX Access to Cobrand module here? To => $self->to, From => $self->send_from( $row ), }, diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 61f59f725..b92aa8cfd 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -57,7 +57,7 @@ sub send { push @$extra, { name => 'report_title', value => $row->title }; push @$extra, { name => 'public_anonymity_required', value => $row->anonymous ? 'TRUE' : 'FALSE' }; push @$extra, { name => 'email_alerts_requested', value => 'FALSE' }; # always false as can never request them - push @$extra, { name => 'requested_datetime', value => DateTime::Format::W3CDTF->format_datetime($row->confirmed_local->set_nanosecond(0)) }; + push @$extra, { name => 'requested_datetime', value => DateTime::Format::W3CDTF->format_datetime($row->confirmed->set_nanosecond(0)) }; push @$extra, { name => 'email', value => $row->user->email }; $row->extra( $extra ); diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm index e0c95283e..4930ff61e 100644 --- a/perllib/FixMyStreet/SendReport/Zurich.pm +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -9,12 +9,14 @@ sub build_recipient_list { # Only one body ever, most of the time with an email endpoint my $body = @{ $self->bodies }[0]; - $body = FixMyStreet::App->model("DB::Body")->find( { id => $row->external_body } ) - if $row->external_body; + if ( $row->external_body ) { + $body = FixMyStreet::App->model("DB::Body")->find( { id => $row->external_body } ); + $h->{bodies_name} = $body->name; + } my $body_email = $body->endpoint; - my @bodies = $body->bodies; - if ($body->parent && @bodies) { + my $parent = $body->parent; + if ($parent && !$parent->parent) { # Division, might have an individual contact email address my $contact = FixMyStreet::App->model("DB::Contact")->find( { body_id => $body->id, diff --git a/perllib/Open311.pm b/perllib/Open311.pm index efa0ac64f..3be5ac365 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -322,7 +322,7 @@ sub _populate_service_request_update_params { } my $params = { - updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)), + updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed->set_nanosecond(0)), service_request_id => $comment->problem->external_id, status => $status, email => $comment->user->email, diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index aae0940c7..ae1f06a50 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -120,7 +120,7 @@ sub update_comments { # if the comment is older than the last update # do not change the status of the problem as it's # tricky to determine the right thing to do. - if ( $comment->created_local > $p->lastupdate_local ) { + if ( $comment->created > $p->lastupdate ) { my $state = $self->map_state( $request->{status} ); # don't update state unless it's an allowed state and it's diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 04d973067..27d604a59 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -226,12 +226,7 @@ sub prettify_dt { $type ||= ''; $type = 'short' if $type eq '1'; - $dt->set_time_zone( FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - - my $now = DateTime->now( time_zone => 'local' ); - $now->set_time_zone( FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); + my $now = DateTime->now( time_zone => FixMyStreet->config('TIME_ZONE') || 'local' ); my $tt = ''; $tt = $dt->strftime('%H:%M') unless $type eq 'date'; |