aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/Harrogate.pm
blob: 8f4a6e2ead99cdeff7ac134532dd2142adf422c1 (plain)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package FixMyStreet::Cobrand::Harrogate;
use base 'FixMyStreet::Cobrand::UKCouncils';

use strict;
use warnings;
use feature 'say';

sub council_id { return 2407; }
sub council_area { return 'Harrogate'; }
sub council_name { return 'Harrogate Borough Council'; }
sub council_url { return 'harrogate'; }
sub is_two_tier { return 1; } # with North Yorkshire CC 2235

sub base_url {
    my $self = shift;
    return $self->next::method() if FixMyStreet->config('STAGING_SITE');
    return 'http://fix.harrogate.gov.uk';
}

sub disambiguate_location {
    my $self    = shift;
    my $string  = shift;

    my $town = 'Harrogate';

    # as it's the requested example location, try to avoid a disambiguation page
    $town .= ', HG1 1DH' if $string =~ /^\s*king'?s\s+r(?:oa)?d\s*(?:,\s*har\w+\s*)?$/i;

    return {
        %{ $self->SUPER::disambiguate_location() },
        town   => $town,
        centre => '54.0671557690306,-1.59581319536637',
        span   => '0.370193897090822,0.829517054931808',
        bounds => [ 53.8914112467619, -2.00450542308575, 54.2616051438527, -1.17498836815394 ],
    };
}

sub example_places {
    return ( 'HG1 2SG', "King's Road" );
}

sub enter_postcode_text {
    my ($self) = @_;
    return 'Enter a Harrogate district postcode, or street name and area';
}

# increase map zoom level so street names are visible
sub default_map_zoom { return 3; }


=head2 temp_email_to_update, temp_update_contacts

Temporary helper routines to update the extra for potholes (temporary setup
hack, cargo-culted from ESCC, may in future be superseded either by
Open311/integration or a better mechanism for manually creating rich contacts).

Can run with a script or command line like:

 bin/cron-wrapper perl -MFixMyStreet::App -MFixMyStreet::Cobrand::Harrogate -e \
 'FixMyStreet::Cobrand::Harrogate->new({c => FixMyStreet::App->new})->temp_update_contacts'

=cut

sub temp_email_to_update {
    return 'CustomerServices@harrogate.gov.uk';
}

sub temp_update_contacts {
    my $self = shift;

    my $contact_rs = $self->{c}->model('DB::Contact');

    my $email = $self->temp_email_to_update;
    my $_update = sub {
        my ($category, $field, $category_details) = @_; 
        # NB: we're accepting just 1 field, but supply as array [ $field ]

        my $contact = $contact_rs->find_or_create(
            {
                body_id => $self->council_id,
                category => $category,

                confirmed => 1,
                deleted => 0,
                email => $email,
                editor => 'automated script',
                note => '',
                send_method => '',
                whenedited => \'NOW()',
                %{ $category_details || {} },
            },
            {
                key => 'contacts_body_id_category_idx'
            }
        );

        say "Editing category: $category";

        my %default = (
            variable => 'true',
            order => '1',
            required => 'no',
            datatype => 'string',
            datatype_description => 'a string',
        );

        if ($field->{datatype} || '' eq 'boolean') {
            my $description = $field->{description};
            %default = (
                %default,
                datatype => 'singlevaluelist',
                datatype_description => 'Yes or No',
                values => { value => [ 
                        { key => ['No'],  name => ['No'] },
                        { key => ['Yes'], name => ['Yes'] }, 
                ] },
            );
        }

        $contact->update({
            # XXX: we're just setting extra with the expected layout,
            # this could be encapsulated more nicely
            extra => { _fields => [ { %default, %$field } ] },
            confirmed => 1,
            deleted => 0,
            editor => 'automated script',
            whenedited => \'NOW()',
            note => 'Edited by script as per requirements Dec 2014',
        });
    };

    $_update->( 'Abandoned vehicles', {
            code => 'registration',
            description => 'Vehicle Registration number:',
        });

    $_update->( 'Dead animals', {
            code => 'INFO_TEXT',
            variable => 'false',
            description => 'We do not remove small species, e.g. squirrels, rabbits, and small birds.',
        });

    $_update->( 'Flyposting', {
            code => 'offensive',
            description => 'Is it offensive?',
            datatype => 'boolean', # mapped onto singlevaluelist
        });

    $_update->( 'Flytipping', {
            code => 'size',
            description => 'Size?',
            datatype => 'singlevaluelist',
            values => { value => [ 
                    { key => ['Single Item'],       name => ['Single item'] },
                    { key => ['Car boot load'],     name => ['Car boot load'] },
                    { key => ['Small van load'],    name => ['Small van load'] },
                    { key => ['Transit van load'],  name => ['Transit van load'] },
                    { key => ['Tipper lorry load'], name => ['Tipper lorry load'] },
                    { key => ['Significant load'],  name => ['Significant load'] },
                ] },
        });

    $_update->( 'Graffiti', {
            code => 'offensive',
            description => 'Is it offensive?',
            datatype => 'boolean', # mapped onto singlevaluelist
        });

    $_update->( 'Parks and playgrounds', {
            code => 'dangerous',
            description => 'Is it dangerous or could cause injury?',
            datatype => 'boolean', # mapped onto singlevaluelist
        });

    $_update->( 'Trees', {
            code => 'dangerous',
            description => 'Is it dangerous or could cause injury?',
            datatype => 'boolean', # mapped onto singlevaluelist
        });

    # also ensure that the following categories are created:
    for my $category (
        'Car parking',
        'Dog and litter bins',
        'Dog fouling',
        'Other',
        'Rubbish (refuse and recycling)',
        'Street cleaning',
        'Street lighting',
        'Street nameplates',
    ) {
        say "Creating $category if required";
        my $contact = $contact_rs->find_or_create(
            {
                body_id => $self->council_id,
                category => $category,
                confirmed => 1,
                deleted => 0,
                email => $email,
                editor => 'automated script',
                note => 'Created by script as per requirements Dec 2014',
                send_method => '',
                whenedited => \'NOW()',
            }
        );
    }

    my @to_delete = (
        'Parks/landscapes', # delete in favour of to parks and playgrounds
        'Public toilets',   # as no longer in specs
    );
    say sprintf "Deleting: %s (if present)", join ',' => @to_delete;
    $contact_rs->search({
        body_id => $self->council_id,
        category => \@to_delete,
        deleted => 0
    })->update({
        deleted => 1,
        editor => 'automated script',
        whenedited => \'NOW()',
        note => 'Deleted by script as per requirements Dec 2014',
    });
}

sub contact_email {
    my $self = shift;
    return join( '@', 'customerservices', 'harrogate.gov.uk' );
}

sub process_additional_metadata_for_email {
    my ($self, $problem, $h) = @_;

    my $additional = '';
    if (my $extra = $problem->get_extra_fields) {
        $additional = join "\n\n", map {
            if ($_->{name} eq 'INFO_TEXT') {
                ();
            }
            else {
                sprintf '%s: %s', $_->{description}, $_->{value};
            }
        } @$extra;
        $additional = "\n\n$additional" if $additional;
    }

    $h->{additional_information} = $additional;
}

sub send_questionnaires {
    return 0;
}

sub munge_category_list {
    my ($self, $categories_ref, $contacts_ref, $extras_ref) = @_;

    # we want to know which contacts *only* belong to NYCC
    # that's because for shared responsibility, we don't expect
    # the user to have to figure out which authority to contact.

    # so we start building up the list of both
    my (%harrogate_contacts, %nycc_contacts);

    my $harrogate_id = $self->council_id; # XXX: note reference to council_id as body id!
    for my $contact (@$contacts_ref) {
        my $category = $contact->category;
        if ($contact->body_id == $harrogate_id) {
            $harrogate_contacts{$category} = 1;
        }
        else {
            $nycc_contacts{$category}++;
        }
    }

    # and then remove any that also have Harrogate involvement
    delete $nycc_contacts{$_} for keys %harrogate_contacts;

    # here, we simply *mark* the text with (NYCC) at the end, and
    # the rest will get done in the template with javascript
    my @categories = map {
        $nycc_contacts{$_} ?
            "$_ (NYCC)"
            : $_
    } @$categories_ref;

    # replace the entire list with this transformed one
    @$categories_ref = @categories;
}

1;