package FixMyStreet::Cobrand::HighwaysEngland; use parent 'FixMyStreet::Cobrand::UK'; use strict; use warnings; sub council_url { 'highwaysengland' } sub site_key { 'highwaysengland' } sub restriction { { cobrand => shift->moniker } } sub hide_areas_on_reports { 1 } sub all_reports_single_body { { name => 'Highways England' } } sub body { my $self = shift; my $body = FixMyStreet::DB->resultset('Body')->search({ name => 'Highways England' })->first; return $body; } # Copying of functions from UKCouncils that are needed here also - factor out to a role of some sort? sub cut_off_date { '' } sub problems_restriction { FixMyStreet::Cobrand::UKCouncils::problems_restriction($_[0], $_[1]) } sub problems_on_map_restriction { $_[0]->problems_restriction($_[1]) } sub problems_sql_restriction { FixMyStreet::Cobrand::UKCouncils::problems_sql_restriction($_[0], $_[1]) } sub users_restriction { FixMyStreet::Cobrand::UKCouncils::users_restriction($_[0], $_[1]) } sub updates_restriction { FixMyStreet::Cobrand::UKCouncils::updates_restriction($_[0], $_[1]) } sub base_url { FixMyStreet::Cobrand::UKCouncils::base_url($_[0]) } sub admin_allow_user { my ( $self, $user ) = @_; return 1 if $user->is_superuser; return undef unless defined $user->from_body; return $user->from_body->name eq 'Highways England'; } sub report_form_extras { ( { name => 'where_hear' } ) } sub enter_postcode_text { 'Enter a location, road name or postcode' } sub example_places { my $self = shift; return $self->feature('example_places') || $self->next::method(); } sub geocode_postcode { my ( $self, $s ) = @_; if ($s =~ /^\s*[AM]\d+\s*$/i) { return { error => "Please be more specific about the location of the issue, eg M1, Jct 16 or A5, Towcester" }; } return $self->next::method($s); } sub lookup_by_ref_regex { return qr/^\s*((?:FMS\s*)?\d+)\s*$/i; } sub lookup_by_ref { my ($self, $ref) = @_; if ( $ref =~ s/^\s*FMS\s*//i ) { return { 'id' => $ref }; } return 0; } sub allow_photo_upload { 0 } sub allow_anonymous_reports { 'button' } sub admin_user_domain { 'highwaysengland.co.uk' } sub anonymous_account { my $self = shift; return { email => $self->feature('anonymous_account') . '@' . $self->admin_user_domain, name => 'Anonymous user', }; } sub updates_disallowed { my ($self, $problem) = @_; return 1 if $problem->is_fixed || $problem->is_closed; return 1 if $problem->get_extra_metadata('closed_updates'); return 0; } # Bypass photo requirement, we have none sub recent_photos { my ( $self, $area, $num, $lat, $lon, $dist ) = @_; return $self->problems->recent if $area eq 'front'; return []; } sub area_check { my ( $self, $params, $context ) = @_; my $areas = $params->{all_areas}; $areas = { map { $_->{id} => $_ } # If no country, is prefetched area and can assume is E grep { ($_->{country} || 'E') eq 'E' } values %$areas }; return $areas if %$areas; my $error_msg = 'Sorry, this site only covers England.'; return ( 0, $error_msg ); } sub fetch_area_children { my $self = shift; my $areas = FixMyStreet::MapIt::call('areas', $self->area_types); $areas = { map { $_->{id} => $_ } grep { ($_->{country} || 'E') eq 'E' } values %$areas }; return $areas; } sub munge_report_new_bodies { my ($self, $bodies) = @_; # On the cobrand there is only the HE body %$bodies = map { $_->id => $_ } grep { $_->name eq 'Highways England' } values %$bodies; } sub report_new_is_on_he_road { my ( $self ) = @_; my ($x, $y) = ( $self->{c}->stash->{longitude}, $self->{c}->stash->{latitude}, ); my $cfg = { url => "https://tilma.mysociety.org/mapserver/highways", srsname => "urn:ogc:def:crs:EPSG::4326", typename => "Highways", filter => "geom$x,$y15", }; my $ukc = FixMyStreet::Cobrand::UKCouncils->new; my $features = $ukc->_fetch_features($cfg, $x, $y); return scalar @$features ? 1 : 0; } 1;