aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2015-03-31 08:58:41 +0000
committerHakim Cassimally <hakim@mysociety.org>2015-03-31 08:58:41 +0000
commit2604aa3b3c6c9edc3df444eeede83491c6ce405c (patch)
tree4fe91e9fe7def2e12986b5a558a05e8cda07b0bf /perllib
parent458d9c84b639d5625cdc491d56a4cf98bef1b51c (diff)
parentc6f9498c79527fbee3cdb1a53f65524c716f20e9 (diff)
Merge branch 'issues/commercial/678-open311-and-csv'
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm7
-rw-r--r--perllib/FixMyStreet/Cobrand/Base.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm46
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm4
6 files changed, 60 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index f3841acef..64b21db6b 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -252,7 +252,12 @@ sub output_requests : Private {
'interface_used' => [ $problem->service ], # Not in Open311 v2
};
- if ( $c->cobrand->moniker ne 'zurich' ) { # XXX
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ $request->{service_notice} = [
+ $problem->get_extra_metadata('public_response')
+ ];
+ }
+ else {
# FIXME Not according to Open311 v2
$request->{agency_responsible} = $problem->bodies;
}
diff --git a/perllib/FixMyStreet/Cobrand/Base.pm b/perllib/FixMyStreet/Cobrand/Base.pm
index 4941712b2..5a9842233 100644
--- a/perllib/FixMyStreet/Cobrand/Base.pm
+++ b/perllib/FixMyStreet/Cobrand/Base.pm
@@ -51,5 +51,8 @@ sub is_default {
return $self->moniker eq 'default';
}
+# NB: this Base class is for 'meta' features. To add base methods for all cobrands,
+# you may want to look at FMS::Cobrand::Default instead!
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index fa3d856bc..abf5d4fb5 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -898,5 +898,10 @@ sub get_country_for_ip_address {
return 0;
}
+sub jurisdiction_id_example {
+ my $self = shift;
+ return $self->moniker;
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 34cb2f719..7b175f371 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -223,4 +223,8 @@ sub reports_body_check {
}
}
+sub jurisdiction_id_example {
+ 'fiksgatami.no';
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 8d7424328..100349efb 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -735,25 +735,55 @@ sub admin_stats {
'latitude', 'longitude',
'cobrand', 'category',
'state', 'user_id',
- 'external_body'
- ]
+ 'external_body',
+ 'title', 'detail',
+ 'photo',
+ 'whensent', 'lastupdate',
+ 'service',
+ 'extra',
+ ],
}
);
- my $body = "ID,Created,E,N,Category,Status,UserID,External Body\n";
+ my $body = "Report ID,Created,Sent to Agency,Last Updated,E,N,Category,Status,UserID,External Body,Title,Detail,Media URL,Interface Used,Council Response\n";
+ require Text::CSV;
+ my $csv = Text::CSV->new({ binary => 1 });
while ( my $report = $problems->next ) {
my $external_body;
my $body_name = "";
if ( $external_body = $report->body($c) ) {
- $body_name = $external_body->name;
+ $body_name = $external_body->name || '[Unknown body]';
}
- $body .= join( ',',
- $report->id, $report->created,
+
+ my $detail = $report->detail;
+ my $public_response = $report->get_extra_metadata('public_response') || '';
+
+ # replace newlines with HTML <br/> element
+ $detail =~ s{\r?\n}{ <br/> }g;
+ $public_response =~ s{\r?\n}{ <br/> }g;
+
+ my @columns = (
+ $report->id,
+ $report->created,
+ $report->whensent,
+ $report->lastupdate,
$report->local_coords, $report->category,
$report->state, $report->user_id,
- "\"$body_name\"" )
- . "\n";
+ $body_name,
+ $report->title,
+ $detail,
+ $c->cobrand->base_url . $report->get_photo_params->{url},
+ $report->service || 'Web interface',
+ $public_response,
+ );
+ if ($csv->combine(@columns)) {
+ $body .= $csv->string . "\n";
+ }
+ else {
+ $body .= sprintf "{{error emitting CSV line: %s}}\n", $csv->error_diag;
+ }
}
$c->res->content_type('text/csv; charset=utf-8');
+ $c->res->header('Content-Disposition' => 'attachment; filename=stats.csv');
$c->res->body($body);
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 93dc16811..bfe87009d 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -681,6 +681,10 @@ sub local_coords {
my ($x, $y) = Geo::Coordinates::CH1903::from_latlon($self->latitude, $self->longitude);
return ( int($x+0.5), int($y+0.5) );
}
+ else {
+ # return a dummy value until this function is implemented. useful for testing.
+ return (0, 0);
+ }
}
=head2 update_from_open311_service_request