diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 65 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 40 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Bing.pm | 32 |
6 files changed, 134 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f7942c45a..e5e15092f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -810,14 +810,7 @@ sub user_edit : Path('user_edit') : Args(1) { my $user = $c->model('DB::User')->find( { id => $id } ); $c->stash->{user} = $user; - my @area_types = $c->cobrand->area_types; - my $areas = mySociety::MaPit::call('areas', \@area_types); - - my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; - @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); - - $c->stash->{council_ids} = \@councils_ids; - $c->stash->{council_details} = $areas; + $c->forward('set_up_council_details'); if ( $c->req->param('submit') ) { $c->forward('check_token'); @@ -833,6 +826,7 @@ sub user_edit : Path('user_edit') : Args(1) { $user->name( $c->req->param('name') ); $user->email( $c->req->param('email') ); $user->from_council( $c->req->param('council') || undef ); + $user->flagged( $c->req->param('flagged') || 0 ); $user->update; if ($edited) { @@ -869,6 +863,8 @@ sub stats : Path('stats') : Args(0) { $c->forward('check_page_allowed'); + $c->forward('set_up_council_details'); + if ( $c->req->param('getcounts') ) { my ( $start_date, $end_date, @errors ); @@ -901,25 +897,51 @@ sub stats : Path('stats') : Args(0) { return 1 if @errors; + my $bymonth = $c->req->param('bymonth'); + $c->stash->{bymonth} = $bymonth; + my ( %council, %dates ); + $council{council} = { like => $c->req->param('council') } + if $c->req->param('council'); + + $c->stash->{selected_council} = $c->req->param('council'); + my $field = 'confirmed'; $field = 'created' if $c->req->param('unconfirmed'); my $one_day = DateTime::Duration->new( days => 1 ); + + my %select = ( + select => [ 'state', { 'count' => 'me.id' } ], + as => [qw/state count/], + group_by => [ 'state' ], + order_by => [ 'state' ], + ); + + if ( $c->req->param('bymonth') ) { + %select = ( + select => [ + { extract => \"year from $field", -as => 'c_year' }, + { extract => \"month from $field", -as => 'c_month' }, + { 'count' => 'me.id' } + ], + as => [qw/c_year c_month count/], + group_by => [qw/c_year c_month/], + order_by => [qw/c_year c_month/], + ); + } + my $p = $c->model('DB::Problem')->search( { -AND => [ $field => { '>=', $start_date}, $field => { '<=', $end_date + $one_day }, ], + %council, + %dates, }, - { - select => [ 'state', { 'count' => 'me.id' } ], - as => [qw/state count/], - group_by => [ 'state' ], - order_by => [ 'state' ], - } + \%select, ); # in case the total_report count is 0 @@ -1153,6 +1175,21 @@ sub check_page_allowed : Private { return 1; } +sub set_up_council_details : Private { + my ($self, $c ) = @_; + + my @area_types = $c->cobrand->area_types; + my $areas = mySociety::MaPit::call('areas', \@area_types); + + my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; + @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); + + $c->stash->{council_ids} = \@councils_ids; + $c->stash->{council_details} = $areas; + + return 1; +} + sub trim { my $self = shift; my $e = shift; diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 45a16a9dd..767d38c21 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -263,6 +263,12 @@ sub add_row : Private { my $key = $alert_type->item_table eq 'comment' ? 'c' : 'id'; $item{description} .= ent("\n<br><img src=\"". $c->cobrand->base_url . "/photo?$key=$row->{id}\">"); } + + if ( $row->{used_map} ) { + #my $address = $c->cobrand->find_closest_address_for_rss( $row->{latitude}, $row->{longitude} ); + #$item{description} .= ent("\n<br>$address"); + } + my $recipient_name = $c->cobrand->contact_name; $item{description} .= ent("\n<br><a href='$url'>" . sprintf(_("Report on %s"), $recipient_name) . "</a>"); diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 5579d0d53..43d46ae25 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -19,7 +19,7 @@ __PACKAGE__->config( render_die => 1, expose_methods => [ 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', - 'add_links', + 'add_links', 'version', ], FILTERS => { escape_js => \&escape_js, @@ -165,5 +165,15 @@ sub html_filter { return $text; } +my %version_hash; +sub version { + my ( $self, $c, $file ) = @_; + unless ($version_hash{$file}) { + my $path = FixMyStreet->path_to('web', $file); + $version_hash{$file} = ( stat( $path ) )[9]; + } + return "$file?$version_hash{$file}"; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 69718f613..1e87468ac 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -4,6 +4,7 @@ use strict; use warnings; use FixMyStreet; use URI; +use Digest::MD5 qw(md5_hex); use Carp; use mySociety::MaPit; @@ -547,17 +548,10 @@ sub find_closest { my ( $self, $latitude, $longitude ) = @_; my $str = ''; - # 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 $j = LWP::Simple::get($url); - if ($j) { - $j = JSON->new->utf8->allow_nonref->decode($j); - if ($j->{resourceSets}[0]{resources}[0]{name}) { - $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), - $j->{resourceSets}[0]{resources}[0]{name}) . "\n\n"; - } + if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude ) ) { + if ($j->{resourceSets}[0]{resources}[0]{name}) { + $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), + $j->{resourceSets}[0]{resources}[0]{name}) . "\n\n"; } } @@ -575,6 +569,30 @@ sub find_closest { return $str; } +=head2 find_closest_address_for_rss + +Used by rss feeds to provide a bit more context + +=cut + +sub find_closest_address_for_rss { + my ( $self, $latitude, $longitude ) = @_; + my $str = ''; + + if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ) ) { + if ($j->{resourceSets}[0]{resources}[0]{name}) { + my $address = $j->{resourceSets}[0]{resources}[0]{address}; + my @address; + push @address, $address->{addressLine} if $address->{addressLine} ne 'Street'; + push @address, $address->{locality}; + $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), + join( ', ', @address ) ); + } + } + + return $str; +} + =head2 council_check Paramters are COUNCILS, QUERY, CONTEXT. Return a boolean indicating whether diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 8c1f95bae..44c066454 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -64,11 +64,14 @@ sub recent { my ( $rs ) = @_; my $key = "recent:$site_key"; my $result = Memcached::get($key); - unless ($result) { + if ( $result ) { + # Need to reattach schema so that confirmed column gets reinflated. + $result->[0]->result_source->schema( $rs->result_source->schema ); + } else { $result = [ $rs->search( { state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }, { - columns => [ 'id', 'title' ], + columns => [ 'id', 'title', 'confirmed' ], order_by => { -desc => 'confirmed' }, rows => 5, } )->all ]; diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 90d7f98bd..4e12a7a7f 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -64,4 +64,36 @@ sub string { return { error => $error }; } +sub reverse { + my ( $latitude, $longitude, $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 $j; + if ( $cache ) { + my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; + my $cache_file = $cache_dir . md5_hex($url); + + if (-s $cache_file) { + $j = File::Slurp::read_file($cache_file); + } else { + $j = LWP::Simple::get($url); + File::Path::mkpath($cache_dir); + File::Slurp::write_file($cache_file, $j) if $j; + } + } else { + $j = LWP::Simple::get($url); + } + + if ($j) { + $j = JSON->new->utf8->allow_nonref->decode($j); + return $j; + } + } + + return undef; +} + 1; |