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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
package FixMyStreet::Cobrand::Bexley;
use parent 'FixMyStreet::Cobrand::Whitelabel';
use strict;
use warnings;
use Time::Piece;
sub council_area_id { 2494 }
sub council_area { 'Bexley' }
sub council_name { 'London Borough of Bexley' }
sub council_url { 'bexley' }
sub get_geocoder { 'Bexley' }
sub map_type { 'MasterMap' }
sub disambiguate_location {
my $self = shift;
my $string = shift;
return {
%{ $self->SUPER::disambiguate_location() },
centre => '51.46088,0.142359',
bounds => [ 51.408484, 0.074653, 51.515542, 0.2234676 ],
};
}
sub disable_resend_button { 1 }
# We can resend reports upon category change, unless it will be going to the
# same Symology database, because that will reject saying it already has the
# ID.
sub category_change_force_resend {
my ($self, $old, $new) = @_;
# Get the Open311 identifiers
my $contacts = $self->{c}->stash->{contacts};
($old) = map { $_->email } grep { $_->category eq $old } @$contacts;
($new) = map { $_->email } grep { $_->category eq $new } @$contacts;
# Okay if we're switching to/from/within Confirm/Uniform
return 1 if $old =~ /^(Confirm|Uniform)/ || $new =~ /^(Confirm|Uniform)/;
# Otherwise, okay if we're switching between Symology DBs, but not within
return ($old =~ /^StreetLighting/ xor $new =~ /^StreetLighting/);
}
sub on_map_default_status { 'open' }
sub open311_munge_update_params {
my ($self, $params, $comment, $body) = @_;
$params->{service_request_id_ext} = $comment->problem->id;
my $contact = $comment->problem->contact;
$params->{service_code} = $contact->email;
}
sub open311_get_update_munging {
my ($self, $comment) = @_;
# If we've received an update via Open311 that's closed
# or fixed the report, also close it to updates.
$comment->problem->set_extra_metadata(closed_updates => 1)
if !$comment->problem->is_open;
}
sub lookup_site_code_config {
my ($self, $property) = @_;
# uncoverable subroutine
# uncoverable statement
{
buffer => 1000, # metres
url => "https://tilma.mysociety.org/mapserver/bexley",
srsname => "urn:ogc:def:crs:EPSG::27700",
typename => "Streets",
property => $property,
accept_feature => sub { 1 }
}
}
sub open311_config {
my ($self, $row, $h, $params) = @_;
$params->{multi_photos} = 1;
}
sub open311_extra_data_include {
my ($self, $row, $h, $contact) = @_;
my $open311_only;
if ($contact->email =~ /^Confirm/) {
push @$open311_only,
{ name => 'report_url', description => 'Report URL',
value => $h->{url} },
{ name => 'title', description => 'Title',
value => $row->title },
{ name => 'description', description => 'Detail',
value => $row->detail };
if (!$row->get_extra_field_value('site_code')) {
if (my $ref = $self->lookup_site_code($row, 'NSG_REF')) {
$row->update_extra_field({ name => 'site_code', value => $ref, description => 'Site code' });
}
}
} elsif ($contact->email =~ /^Uniform/) {
# Reports made via the app probably won't have a UPRN because we don't
# display the road layer. Instead we'll look up the closest asset from the
# WFS service at the point we're sending the report over Open311.
if (!$row->get_extra_field_value('uprn')) {
if (my $ref = $self->lookup_site_code($row, 'UPRN')) {
$row->update_extra_field({ name => 'uprn', description => 'UPRN', value => $ref });
}
}
} else { # Symology
# Reports made via the app probably won't have a NSGRef because we don't
# display the road layer. Instead we'll look up the closest asset from the
# WFS service at the point we're sending the report over Open311.
if (!$row->get_extra_field_value('NSGRef')) {
if (my $ref = $self->lookup_site_code($row, 'NSG_REF')) {
$row->update_extra_field({ name => 'NSGRef', description => 'NSG Ref', value => $ref });
}
}
}
return $open311_only;
}
sub admin_user_domain { 'bexley.gov.uk' }
sub open311_post_send {
my ($self, $row, $h, $contact) = @_;
# Check Open311 was successful
return unless $row->external_id;
my @lighting = (
'Lamp post',
'Light in multi-storey car park',
'Light in outside car park',
'Light in park or open space',
'Traffic bollard',
'Traffic sign light',
'Underpass light',
'Zebra crossing light',
);
my %lighting = map { $_ => 1 } @lighting;
my @flooding = (
'Flooding in the road',
'Blocked rainwater gulleys',
);
my %flooding = map { $_ => 1 } @flooding;
my $emails = $self->feature('open311_email') || return;
my $dangerous = $row->get_extra_field_value('dangerous') || '';
my $p1_email = 0;
my $outofhours_email = 0;
if ($row->category eq 'Abandoned and untaxed vehicles') {
my $burnt = $row->get_extra_field_value('burnt') || '';
$p1_email = 1 if $burnt eq 'Yes';
} elsif ($row->category eq 'Dead animal') {
$p1_email = 1;
$outofhours_email = 1;
} elsif ($row->category eq 'Gulley covers' || $row->category eq 'Manhole covers') {
my $reportType = $row->get_extra_field_value('reportType') || '';
if ($reportType eq 'Cover missing' || $dangerous eq 'Yes') {
$p1_email = 1;
$outofhours_email = 1;
}
} elsif ($row->category eq 'Street cleaning and litter') {
my $reportType = $row->get_extra_field_value('reportType') || '';
if ($reportType eq 'Oil spillage' || $dangerous eq 'Yes') {
$p1_email = 1;
$outofhours_email = 1;
}
} elsif ($row->category eq 'Damage to kerb' || $row->category eq 'Damaged road' || $row->category eq 'Damaged pavement') {
$p1_email = 1;
$outofhours_email = 1;
} elsif (!$lighting{$row->category}) {
$p1_email = 1 if $dangerous eq 'Yes';
$outofhours_email = 1 if $dangerous eq 'Yes';
}
my @to;
my $p1_email_to_use = ($contact->email =~ /^Confirm/) ? $emails->{p1confirm} : $emails->{p1};
push @to, email_list($p1_email_to_use, 'Bexley P1 email') if $p1_email;
push @to, email_list($emails->{lighting}, 'FixMyStreet Bexley Street Lighting') if $lighting{$row->category};
push @to, email_list($emails->{flooding}, 'FixMyStreet Bexley Flooding') if $flooding{$row->category};
push @to, email_list($emails->{outofhours}, 'Bexley out of hours') if $outofhours_email && _is_out_of_hours();
if ($contact->email =~ /^Uniform/) {
push @to, email_list($emails->{eh}, 'FixMyStreet Bexley EH');
$row->push_extra_fields({ name => 'uniform_id', description => 'Uniform ID', value => $row->external_id });
}
return unless @to;
my $sender = FixMyStreet::SendReport::Email->new( to => \@to );
$self->open311_config($row, $h, {}, $contact); # Populate NSGRef again if needed
$sender->send($row, $h);
}
sub email_list {
my ($emails, $name) = @_;
return unless $emails;
my @emails = split /,/, $emails;
my @to = map { [ $_, $name ] } @emails;
return @to;
}
sub _is_out_of_hours {
my $time = localtime;
return 1 if $time->hour > 16 || ($time->hour == 16 && $time->min >= 45);
return 1 if $time->hour < 8;
return 1 if $time->wday == 1 || $time->wday == 7;
return 1 if FixMyStreet::Cobrand::UK::is_public_holiday();
return 0;
}
sub update_anonymous_message {
my ($self, $update) = @_;
my $t = Utils::prettify_dt( $update->confirmed );
my $staff = $update->user->from_body || $update->get_extra_metadata('is_body_user') || $update->get_extra_metadata('is_superuser');
return sprintf('Posted anonymously by a non-staff user at %s', $t) if !$staff;
}
1;
|