diff options
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/Default.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 117 |
1 files changed, 82 insertions, 35 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index ac70fff08..250919d09 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -4,6 +4,7 @@ use base 'FixMyStreet::Cobrand::Base'; use strict; use warnings; use FixMyStreet; +use FixMyStreet::DB; use FixMyStreet::Geocode::Bing; use DateTime; use Encode; @@ -71,7 +72,7 @@ a cobrand that only wants some of the data. sub problems { my $self = shift; - return $self->problems_restriction($self->{c}->model('DB::Problem')); + return $self->problems_restriction(FixMyStreet::DB->resultset('Problem')); } =head1 problems_on_map @@ -83,7 +84,7 @@ restricted to a subset if we're on a cobrand that only wants some of the data. sub problems_on_map { my $self = shift; - return $self->problems_on_map_restriction($self->{c}->model('DB::Problem')); + return $self->problems_on_map_restriction(FixMyStreet::DB->resultset('Problem')); } =head1 updates @@ -95,7 +96,7 @@ a cobrand that only wants some of the data. sub updates { my $self = shift; - return $self->updates_restriction($self->{c}->model('DB::Comment')); + return $self->updates_restriction(FixMyStreet::DB->resultset('Comment')); } =head1 problems_restriction/updates_restriction @@ -149,7 +150,7 @@ a cobrand that only wants some of the data. sub users { my $self = shift; - return $self->users_restriction($self->{c}->model('DB::User')); + return $self->users_restriction(FixMyStreet::DB->resultset('User')); } =head1 users_restriction @@ -178,7 +179,7 @@ sub restriction { return $self->moniker ? { cobrand => $self->moniker } : {}; } -=head2 base_url_with_lang +=head2 base_url_with_lang =cut @@ -268,6 +269,8 @@ sub set_lang_and_domain { DateTime->DefaultLocale( 'en_US' ); } + FixMyStreet::DB->schema->lang($set_lang); + return $set_lang; } sub languages { FixMyStreet->config('LANGUAGES') || [] } @@ -355,7 +358,7 @@ sub front_stats_data { Returns any disambiguating information available. Defaults to none. -=cut +=cut sub disambiguate_location { FixMyStreet->config('GEOCODING_DISAMBIGUATION') or {}; } @@ -509,27 +512,35 @@ sub geocoded_string_check { return 1; } =head2 find_closest -Used by send-reports to attach nearest things to the bottom of the report +Used by send-reports and similar to attach nearest things to the bottom of the +report. =cut sub find_closest { - my ( $self, $latitude, $longitude, $problem ) = @_; - my $str = ''; + my ( $self, $problem, $as_data ) = @_; - if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) { + my $j = $problem->geocode; + if (!$j) { + $j = FixMyStreet::Geocode::Bing::reverse( $problem->latitude, $problem->longitude, + disambiguate_location()->{bing_culture} ); # cache the bing results for use in alerts - if ( $problem ) { - $problem->geocode( $j ); - $problem->update; - } - 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"; + $problem->geocode( $j ); + $problem->update; + } + + my $data = $as_data ? {} : ''; + if ($j && $j->{resourceSets}[0]{resources}[0]{name}) { + my $str = $j->{resourceSets}[0]{resources}[0]{name}; + if ($as_data) { + $data->{road} = $str; + } else { + $data .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), + $str) . "\n\n"; } } - return $str; + return $data; } =head2 find_closest_address_for_rss @@ -539,26 +550,14 @@ Used by rss feeds to provide a bit more context =cut sub find_closest_address_for_rss { - my ( $self, $latitude, $longitude, $problem ) = @_; - my $str = ''; + my ( $self, $problem ) = @_; - my $j; - if ( $problem && ref($problem) =~ /FixMyStreet/ && $problem->can( 'geocode' ) ) { - $j = $problem->geocode; - } else { + if (ref($problem) eq 'HASH') { $problem = FixMyStreet::App->model('DB::Problem')->find( { id => $problem->{id} } ); - $j = $problem->geocode; } + my $j = $problem->geocode; - # 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, disambiguate_location()->{bing_culture}, 1 ); - - # $problem->geocode( $j ); - # $problem->update; - # } - + my $str = ''; if ($j && $j->{resourceSets}[0]{resources}[0]{name}) { my $address = $j->{resourceSets}[0]{resources}[0]{address}; my @address; @@ -643,6 +642,7 @@ sub admin_pages { # There are some pages that only super users can see if ( $user->is_superuser ) { $pages->{flagged} = [ _('Flagged'), 7 ]; + $pages->{states} = [ _('States'), 8 ]; $pages->{config} = [ _('Configuration'), 9]; }; # And some that need special permissions @@ -669,6 +669,10 @@ sub admin_pages { $pages->{users} = [ _('Users'), 6 ]; $pages->{user_edit} = [ undef, undef ]; } + if ( $self->allow_report_extra_fields && $user->has_body_permission_to('category_edit') ) { + $pages->{reportextrafields} = [ _('Extra Fields'), 10 ]; + $pages->{reportextrafields_edit} = [ undef, undef ]; + } return $pages; } @@ -711,6 +715,7 @@ sub available_permissions { report_instruct => _("Instruct contractors to fix problems"), # future use planned_reports => _("Manage shortlist"), contribute_as_another_user => _("Create reports/updates on a user's behalf"), + contribute_as_anonymous_user => _("Create reports/updates as anonymous user"), contribute_as_body => _("Create reports/updates as the council"), view_body_contribute_details => _("See user detail for reports created as the council"), @@ -816,7 +821,7 @@ sub is_two_tier { 0; } =item council_rss_alert_options -Generate a set of options for council rss alerts. +Generate a set of options for council rss alerts. =cut @@ -948,6 +953,15 @@ sub pin_colour { return $p->is_fixed ? 'green' : 'red'; } +=head2 pin_new_report_colour + +Returns the colour of pin to be used for a new report. + +=cut +sub pin_new_report_colour { + return 'green'; +} + =head2 path_to_pin_icons Used to override the path for the pin icons if you want to add custom pin icons @@ -1053,6 +1067,28 @@ sub show_unconfirmed_reports { 0; } +sub state_groups_admin { + my $rs = FixMyStreet::DB->resultset("State"); + my @fixed = FixMyStreet::DB::Result::Problem->fixed_states; + [ + [ $rs->display('confirmed'), [ FixMyStreet::DB::Result::Problem->open_states ] ], + @fixed ? [ $rs->display('fixed'), [ FixMyStreet::DB::Result::Problem->fixed_states ] ] : (), + [ $rs->display('closed'), [ FixMyStreet::DB::Result::Problem->closed_states ] ], + [ $rs->display('hidden'), [ FixMyStreet::DB::Result::Problem->hidden_states ] ] + ] +} + +sub state_groups_inspect { + my $rs = FixMyStreet::DB->resultset("State"); + my @fixed = FixMyStreet::DB::Result::Problem->fixed_states; + [ + [ $rs->display('confirmed'), [ grep { $_ ne 'planned' } FixMyStreet::DB::Result::Problem->open_states ] ], + @fixed ? [ $rs->display('fixed'), [ 'fixed - council' ] ] : (), + [ $rs->display('closed'), [ grep { $_ ne 'closed' } FixMyStreet::DB::Result::Problem->closed_states ] ], + [ $rs->display('hidden'), [ 'hidden' ] ] + ] +} + =head2 never_confirm_updates If true then we never send an email to confirm an update @@ -1212,5 +1248,16 @@ the 'n days ago' format is used. By default the absolute date is always used. =cut sub display_days_ago_threshold { 0 } +=head2 allow_report_extra_fields + +Used to control whether site-wide extra fields are available. If true, +users with the category_edit permission can add site-wide fields via the +admin. + +=cut + +sub allow_report_extra_fields { 0 } + + 1; |