1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
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 => "<Filter><DWithin><PropertyName>geom</PropertyName><gml:Point><gml:coordinates>$x,$y</gml:coordinates></gml:Point><Distance units='m'>15</Distance></DWithin></Filter>",
};
my $ukc = FixMyStreet::Cobrand::UKCouncils->new;
my $features = $ukc->_fetch_features($cfg, $x, $y);
return scalar @$features ? 1 : 0;
}
1;
|