diff options
Diffstat (limited to 'perllib/Open311')
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 68 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 26 |
2 files changed, 94 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm new file mode 100644 index 000000000..dc8fb7672 --- /dev/null +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -0,0 +1,68 @@ +package Open311::GetServiceRequestUpdates; + +use Moose; +use Open311; +use FixMyStreet::App; + +has council_list => ( is => 'ro' ); +has system_user => ( is => 'ro' ); + +sub update_comments { + my ( $self, $open311, $council_details ) = @_; + + my $requests = $open311->get_service_request_updates( ); + + for my $request (@$requests) { + my $request_id = $request->{service_request_id}; + + # If there's no request id then we can't work out + # what problem it belongs to so just skip + next unless $request_id; + + my $problem = + FixMyStreet::App->model('DB::Problem') + ->search( { + external_id => $request_id, + council => { like => '%' . $council_details->{areaid} . '%' }, + } ); + + if (my $p = $problem->first) { + my $c = $p->comments->search( { external_id => $request->{update_id} } ); + + if ( !$c->first ) { + my $comment = FixMyStreet::App->model('DB::Comment')->new( + { + problem => $p, + user => $self->system_user, + external_id => $request->{update_id}, + text => $request->{description}, + mark_fixed => 0, + mark_open => 0, + anonymous => 0, + name => $self->system_user->name + } + ); + $comment->confirm; + + + if ( $p->is_open and $request->{status} eq 'closed' ) { + $p->state( 'fixed - council' ); + $p->update; + + $comment->mark_fixed( 1 ); + } elsif ( ( $p->is_closed || $p->is_fixed ) and $request->{status} eq 'open' ) { + $p->state( 'confirmed' ); + $p->update; + + $comment->mark_open( 1 ); + } + + $comment->insert(); + } + } + } + + return 1; +} + +1; diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index cfec9005d..ac355a33c 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -189,6 +189,12 @@ sub _add_contact_to_meta { print "Fetching meta data for $self->_current_service->{service_code}\n"; my $meta_data = $self->_current_open311->get_service_meta_info( $self->_current_service->{service_code} ); + if ( ref $meta_data->{ attributes }->{ attribute } eq 'HASH' ) { + $meta_data->{ attributes }->{ attribute } = [ + $meta_data->{ attributes }->{ attribute } + ]; + } + # turn the data into something a bit more friendly to use my @meta = # remove trailing colon as we add this when we display so we don't want 2 @@ -197,6 +203,26 @@ sub _add_contact_to_meta { sort { $a->{order} <=> $b->{order} } @{ $meta_data->{attributes}->{attribute} }; + # we add these later on from bromley so don't list them here + # as we don't want to display them + if ( $self->_current_council->area_id == 2482 ) { + my %ignore = map { $_ => 1 } qw/ + service_request_id_ext + requested_datetime + report_url + title + last_name + email + easting + northing + report_title + public_anonymity_required + email_alerts_requested + /; + + @meta = grep { ! $ignore{ $_->{ code } } } @meta; + } + $contact->extra( \@meta ); $contact->update; } |