aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/Result')
-rw-r--r--perllib/FixMyStreet/DB/Result/Alert.pm39
-rw-r--r--perllib/FixMyStreet/DB/Result/AlertSent.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm112
-rw-r--r--perllib/FixMyStreet/DB/Result/BodyArea.pm33
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm78
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm37
-rw-r--r--perllib/FixMyStreet/DB/Result/ContactsHistory.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Open311conf.pm60
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm325
-rw-r--r--perllib/FixMyStreet/DB/Result/Questionnaire.pm34
-rw-r--r--perllib/FixMyStreet/DB/Result/Token.pm24
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm60
12 files changed, 465 insertions, 349 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm
index ca9ad45c2..4ce72f873 100644
--- a/perllib/FixMyStreet/DB/Result/Alert.pm
+++ b/perllib/FixMyStreet/DB/Result/Alert.pm
@@ -48,7 +48,7 @@ __PACKAGE__->belongs_to(
"alert_type",
"FixMyStreet::DB::Result::AlertType",
{ ref => "alert_type" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
__PACKAGE__->has_many(
"alerts_sent",
@@ -60,12 +60,12 @@ __PACKAGE__->belongs_to(
"user",
"FixMyStreet::DB::Result::User",
{ id => "user_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vump36YxUO4FQi5Do6DwvA
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d9yIFiTGtbtFaULXZNKstQ
# You can replace this text with custom code or comments, and it will be preserved on regeneration
@@ -77,22 +77,21 @@ with 'FixMyStreet::Roles::Abuser';
my $tz = DateTime::TimeZone->new( name => "local" );
-
-sub whensubscribed_local {
- my $self = shift;
-
- return $self->whensubscribed
- ? $self->whensubscribed->set_time_zone($tz)
- : $self->whensubscribed;
-}
-
-sub whendisabled_local {
- my $self = shift;
-
- return $self->whendisabled
- ? $self->whendisabled->set_time_zone($tz)
- : $self->whendisabled;
-}
+my $tz_f;
+$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') )
+ if FixMyStreet->config('TIME_ZONE');
+
+my $stz = sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my $s = $self->$orig(@_);
+ return $s unless $s && UNIVERSAL::isa($s, "DateTime");
+ $s->set_time_zone($tz);
+ $s->set_time_zone($tz_f) if $tz_f;
+ return $s;
+};
+
+around whensubscribed => $stz;
+around whendisabled => $stz;
=head2 confirm
diff --git a/perllib/FixMyStreet/DB/Result/AlertSent.pm b/perllib/FixMyStreet/DB/Result/AlertSent.pm
index a537c95cd..422e010a9 100644
--- a/perllib/FixMyStreet/DB/Result/AlertSent.pm
+++ b/perllib/FixMyStreet/DB/Result/AlertSent.pm
@@ -26,12 +26,12 @@ __PACKAGE__->belongs_to(
"alert",
"FixMyStreet::DB::Result::Alert",
{ id => "alert_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oN+36hDWJuc0hqkCW9BHOw
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:COwsprqRSNZS1IxJrPYgMQ
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
new file mode 100644
index 000000000..be4adeca9
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -0,0 +1,112 @@
+use utf8;
+package FixMyStreet::DB::Result::Body;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
+__PACKAGE__->table("body");
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_auto_increment => 1,
+ is_nullable => 0,
+ sequence => "body_id_seq",
+ },
+ "name",
+ { data_type => "text", is_nullable => 0 },
+ "parent",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+ "endpoint",
+ { data_type => "text", is_nullable => 1 },
+ "jurisdiction",
+ { data_type => "text", is_nullable => 1 },
+ "api_key",
+ { data_type => "text", is_nullable => 1 },
+ "send_method",
+ { data_type => "text", is_nullable => 1 },
+ "send_comments",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "comment_user_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+ "suppress_alerts",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "can_be_devolved",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "send_extended_statuses",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "deleted",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "external_url",
+ { data_type => "text", is_nullable => 0 },
+);
+__PACKAGE__->set_primary_key("id");
+__PACKAGE__->has_many(
+ "bodies",
+ "FixMyStreet::DB::Result::Body",
+ { "foreign.parent" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->has_many(
+ "body_areas",
+ "FixMyStreet::DB::Result::BodyArea",
+ { "foreign.body_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->belongs_to(
+ "comment_user",
+ "FixMyStreet::DB::Result::User",
+ { id => "comment_user_id" },
+ {
+ is_deferrable => 0,
+ join_type => "LEFT",
+ on_delete => "NO ACTION",
+ on_update => "NO ACTION",
+ },
+);
+__PACKAGE__->has_many(
+ "contacts",
+ "FixMyStreet::DB::Result::Contact",
+ { "foreign.body_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->belongs_to(
+ "parent",
+ "FixMyStreet::DB::Result::Body",
+ { id => "parent" },
+ {
+ is_deferrable => 0,
+ join_type => "LEFT",
+ on_delete => "NO ACTION",
+ on_update => "NO ACTION",
+ },
+);
+__PACKAGE__->has_many(
+ "users",
+ "FixMyStreet::DB::Result::User",
+ { "foreign.from_body" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 18:11:23
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hTOxxiiHmC8nmQK/p8dXhQ
+
+sub url {
+ my ( $self, $c ) = @_;
+ # XXX $areas_info was used here for Norway parent - needs body parents, I guess
+ return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ) );
+}
+
+sub areas {
+ my $self = shift;
+ my %ids = map { $_->area_id => 1 } $self->body_areas->all;
+ return \%ids;
+}
+
+1;
diff --git a/perllib/FixMyStreet/DB/Result/BodyArea.pm b/perllib/FixMyStreet/DB/Result/BodyArea.pm
new file mode 100644
index 000000000..4447777dc
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/BodyArea.pm
@@ -0,0 +1,33 @@
+use utf8;
+package FixMyStreet::DB::Result::BodyArea;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
+__PACKAGE__->table("body_areas");
+__PACKAGE__->add_columns(
+ "body_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "area_id",
+ { data_type => "integer", is_nullable => 0 },
+);
+__PACKAGE__->add_unique_constraint("body_areas_body_id_area_id_idx", ["body_id", "area_id"]);
+__PACKAGE__->belongs_to(
+ "body",
+ "FixMyStreet::DB::Result::Body",
+ { id => "body_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+hzie6kHleUBoEt199c/nQ
+
+ __PACKAGE__->set_primary_key(__PACKAGE__->columns);
+
+1;
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 8c9fea282..e170a5655 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -54,6 +54,10 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"problem_state",
{ data_type => "text", is_nullable => 1 },
+ "external_id",
+ { data_type => "text", is_nullable => 1 },
+ "extra",
+ { data_type => "text", is_nullable => 1 },
"send_fail_count",
{ data_type => "integer", default_value => 0, is_nullable => 0 },
"send_fail_reason",
@@ -62,76 +66,52 @@ __PACKAGE__->add_columns(
{ data_type => "timestamp", is_nullable => 1 },
"whensent",
{ data_type => "timestamp", is_nullable => 1 },
- "external_id",
- { data_type => "text", is_nullable => 1 },
- "extra",
- { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"problem",
"FixMyStreet::DB::Result::Problem",
{ id => "problem_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
__PACKAGE__->belongs_to(
"user",
"FixMyStreet::DB::Result::User",
{ id => "user_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-07-11 18:53:26
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tSejJzLxHD/fMWjpa10lfA
-
-__PACKAGE__->filter_column(
- extra => {
- filter_from_storage => sub {
- my $self = shift;
- my $ser = shift;
- return undef unless defined $ser;
- my $h = new IO::String($ser);
- return RABX::wire_rd($h);
- },
- filter_to_storage => sub {
- my $self = shift;
- my $data = shift;
- my $ser = '';
- my $h = new IO::String($ser);
- RABX::wire_wr( $data, $h );
- return $ser;
- },
- }
-);
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:D/+UWcF7JO/EkCiJaAHUOw
+
+__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
+__PACKAGE__->rabx_column('extra');
use DateTime::TimeZone;
use Image::Size;
use Moose;
use namespace::clean -except => [ 'meta' ];
-use RABX;
with 'FixMyStreet::Roles::Abuser';
my $tz = DateTime::TimeZone->new( name => "local" );
-sub created_local {
- my $self = shift;
+my $tz_f;
+$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') )
+ if FixMyStreet->config('TIME_ZONE');
- return $self->created
- ? $self->created->set_time_zone($tz)
- : $self->created;
-}
+my $stz = sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my $s = $self->$orig(@_);
+ return $s unless $s && UNIVERSAL::isa($s, "DateTime");
+ $s->set_time_zone($tz);
+ $s->set_time_zone($tz_f) if $tz_f;
+ return $s;
+};
-sub confirmed_local {
- my $self = shift;
-
- # if confirmed is null then it doesn't get inflated so don't
- # try and set the timezone
- return $self->confirmed
- ? $self->confirmed->set_time_zone($tz)
- : $self->confirmed;
-}
+around created => $stz;
+around confirmed => $stz;
# You can replace this text with custom code or comments, and it will be preserved on regeneration
@@ -146,6 +126,12 @@ sub check_for_errors {
$errors{update} = _('Please enter a message')
unless $self->text =~ m/\S/;
+ # Bromley Council custom character limit
+ if ( $self->text && $self->problem && $self->problem->bodies_str
+ && $self->problem->bodies_str eq '2482' && length($self->text) > 1750 ) {
+ $errors{update} = sprintf( _('Updates are limited to %s characters in length. Please shorten your update'), 1750 );
+ }
+
return \%errors;
}
@@ -175,8 +161,8 @@ sub get_photo_params {
=head2 meta_problem_state
-Returns a string suitable for display in the update meta section.
-Mostly removes the '- council/user' bit from fixed states
+Returns a string suitable for display lookup in the update meta section.
+Removes the '- council/user' bit from fixed states.
=cut
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index 993e3524b..eca028c9b 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -18,8 +18,8 @@ __PACKAGE__->add_columns(
is_nullable => 0,
sequence => "contacts_id_seq",
},
- "area_id",
- { data_type => "integer", is_nullable => 0 },
+ "body_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"category",
{ data_type => "text", default_value => "Other", is_nullable => 0 },
"email",
@@ -48,30 +48,19 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
-__PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]);
+__PACKAGE__->add_unique_constraint("contacts_body_id_category_idx", ["body_id", "category"]);
+__PACKAGE__->belongs_to(
+ "body",
+ "FixMyStreet::DB::Result::Body",
+ { id => "body_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-31 10:29:17
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:t6yOPhZmedV/eH6AUvHI6w
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hq/BFHDEu4OUI4MSy3OyHg
-__PACKAGE__->filter_column(
- extra => {
- filter_from_storage => sub {
- my $self = shift;
- my $ser = shift;
- return undef unless defined $ser;
- my $h = new IO::String($ser);
- return RABX::wire_rd($h);
- },
- filter_to_storage => sub {
- my $self = shift;
- my $data = shift;
- my $ser = '';
- my $h = new IO::String($ser);
- RABX::wire_wr( $data, $h );
- return $ser;
- },
- }
-);
+__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
+__PACKAGE__->rabx_column('extra');
1;
diff --git a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
index deb00fb95..7126d91c9 100644
--- a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
+++ b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
@@ -20,7 +20,7 @@ __PACKAGE__->add_columns(
},
"contact_id",
{ data_type => "integer", is_nullable => 0 },
- "area_id",
+ "body_id",
{ data_type => "integer", is_nullable => 0 },
"category",
{ data_type => "text", default_value => "Other", is_nullable => 0 },
@@ -40,8 +40,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("contacts_history_id");
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dN2ueIDoP3d/+Mg1UDqsMw
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 16:37:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sxflEBBn0Mn0s3MroWnWFA
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm
deleted file mode 100644
index 8051e27de..000000000
--- a/perllib/FixMyStreet/DB/Result/Open311conf.pm
+++ /dev/null
@@ -1,60 +0,0 @@
-use utf8;
-package FixMyStreet::DB::Result::Open311conf;
-
-# Created by DBIx::Class::Schema::Loader
-# DO NOT MODIFY THE FIRST PART OF THIS FILE
-
-use strict;
-use warnings;
-
-use base 'DBIx::Class::Core';
-__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
-__PACKAGE__->table("open311conf");
-__PACKAGE__->add_columns(
- "id",
- {
- data_type => "integer",
- is_auto_increment => 1,
- is_nullable => 0,
- sequence => "open311conf_id_seq",
- },
- "area_id",
- { data_type => "integer", is_nullable => 0 },
- "endpoint",
- { data_type => "text", is_nullable => 0 },
- "jurisdiction",
- { data_type => "text", is_nullable => 1 },
- "api_key",
- { data_type => "text", is_nullable => 1 },
- "send_method",
- { data_type => "text", is_nullable => 1 },
- "send_comments",
- { data_type => "boolean", default_value => \"false", is_nullable => 0 },
- "comment_user_id",
- { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
- "suppress_alerts",
- { data_type => "boolean", default_value => \"false", is_nullable => 0 },
- "can_be_devolved",
- { data_type => "boolean", default_value => \"false", is_nullable => 0 },
-);
-__PACKAGE__->set_primary_key("id");
-__PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]);
-__PACKAGE__->belongs_to(
- "comment_user",
- "FixMyStreet::DB::Result::User",
- { id => "comment_user_id" },
- {
- is_deferrable => 1,
- join_type => "LEFT",
- on_delete => "CASCADE",
- on_update => "CASCADE",
- },
-);
-
-
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q
-
-
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
-1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 02e5adb7d..3463ebab6 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -24,7 +24,7 @@ __PACKAGE__->add_columns(
{ data_type => "double precision", is_nullable => 0 },
"longitude",
{ data_type => "double precision", is_nullable => 0 },
- "council",
+ "bodies_str",
{ data_type => "text", is_nullable => 1 },
"areas",
{ data_type => "text", is_nullable => 0 },
@@ -99,7 +99,7 @@ __PACKAGE__->add_columns(
"external_source_id",
{ data_type => "text", is_nullable => 1 },
"interest_count",
- { data_type => "integer", is_nullable => 1 },
+ { data_type => "integer", default_value => 0, is_nullable => 1 },
"subcategory",
{ data_type => "text", is_nullable => 1 },
);
@@ -120,12 +120,12 @@ __PACKAGE__->belongs_to(
"user",
"FixMyStreet::DB::Result::User",
{ id => "user_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-03 17:48:10
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xN/RB8Vx50CwyOeBjvJezQ
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U/4BT8EGfcCLKA/7LX+qyQ
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
@@ -135,52 +135,15 @@ __PACKAGE__->has_one(
{ cascade_copy => 0, cascade_delete => 0 },
);
-__PACKAGE__->filter_column(
- extra => {
- filter_from_storage => sub {
- my $self = shift;
- my $ser = shift;
- return undef unless defined $ser;
- my $h = new IO::String($ser);
- return RABX::wire_rd($h);
- },
- filter_to_storage => sub {
- my $self = shift;
- my $data = shift;
- my $ser = '';
- my $h = new IO::String($ser);
- RABX::wire_wr( $data, $h );
- return $ser;
- },
- }
-);
-
-__PACKAGE__->filter_column(
- geocode => {
- filter_from_storage => sub {
- my $self = shift;
- my $ser = shift;
- return undef unless defined $ser;
- my $h = new IO::String($ser);
- return RABX::wire_rd($h);
- },
- filter_to_storage => sub {
- my $self = shift;
- my $data = shift;
- my $ser = '';
- my $h = new IO::String($ser);
- RABX::wire_wr( $data, $h );
- return $ser;
- },
- }
-);
+__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
+__PACKAGE__->rabx_column('extra');
+__PACKAGE__->rabx_column('geocode');
use DateTime::TimeZone;
use Image::Size;
use Moose;
use namespace::clean -except => [ 'meta' ];
use Utils;
-use RABX;
with 'FixMyStreet::Roles::Abuser';
@@ -196,10 +159,11 @@ HASHREF.
sub open_states {
my $states = {
- 'confirmed' => 1,
- 'investigating' => 1,
- 'planned' => 1,
- 'in progress' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
};
return wantarray ? keys %{$states} : $states;
@@ -237,7 +201,11 @@ HASHREF.
sub closed_states {
my $states = {
- 'closed' => 1,
+ 'closed' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'internal referral' => 1,
};
return wantarray ? keys %{$states} : $states;
@@ -248,61 +216,111 @@ sub closed_states {
@states = FixMyStreet::DB::Problem::visible_states();
-Get a list or states that should be visible on the site. If called in
+Get a list of states that should be visible on the site. If called in
array context then returns an array of names, otherwise returns a
HASHREF.
=cut
+my $visible_states = {
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'closed' => 1,
+ 'internal referral' => 1,
+};
sub visible_states {
+ return wantarray ? keys %{$visible_states} : $visible_states;
+}
+sub visible_states_add_unconfirmed {
+ $visible_states->{unconfirmed} = 1;
+}
+
+=head2
+
+ @states = FixMyStreet::DB::Problem::all_states();
+
+Get a list of all states that a problem can have. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub all_states {
my $states = {
- 'confirmed' => 1,
- 'planned' => 1,
- 'investigating' => 1,
- 'in progress' => 1,
- 'fixed' => 1,
- 'fixed - council' => 1,
- 'fixed - user' => 1,
- 'closed' => 1,
+ 'hidden' => 1,
+ 'partial' => 1,
+ 'unconfirmed' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'closed' => 1,
+ 'internal referral' => 1,
};
return wantarray ? keys %{$states} : $states;
}
+=head2
-my $tz = DateTime::TimeZone->new( name => "local" );
-
-sub confirmed_local {
- my $self = shift;
+ @states = FixMyStreet::DB::Problem::council_states();
- return $self->confirmed
- ? $self->confirmed->set_time_zone($tz)
- : $self->confirmed;
-}
+Get a list of states that are availble to council users. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
-sub created_local {
- my $self = shift;
+=cut
+sub council_states {
+ my $states = {
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'action scheduled' => 1,
+ 'in progress' => 1,
+ 'fixed - council' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'internal referral' => 1,
+ };
- return $self->created
- ? $self->created->set_time_zone($tz)
- : $self->created;
+ return wantarray ? keys %{$states} : $states;
}
-sub whensent_local {
- my $self = shift;
+my $tz = DateTime::TimeZone->new( name => "local" );
- return $self->whensent
- ? $self->whensent->set_time_zone($tz)
- : $self->whensent;
-}
+my $tz_f;
+$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') )
+ if FixMyStreet->config('TIME_ZONE');
-sub lastupdate_local {
- my $self = shift;
+my $stz = sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my $s = $self->$orig(@_);
+ return $s unless $s && UNIVERSAL::isa($s, "DateTime");
+ $s->set_time_zone($tz);
+ $s->set_time_zone($tz_f) if $tz_f;
+ return $s;
+};
- return $self->lastupdate
- ? $self->lastupdate->set_time_zone($tz)
- : $self->lastupdate;
-}
+around created => $stz;
+around confirmed => $stz;
+around whensent => $stz;
+around lastupdate => $stz;
around service => sub {
my ( $orig, $self ) = ( shift, shift );
@@ -311,6 +329,12 @@ around service => sub {
return $s;
};
+sub title_safe {
+ my $self = shift;
+ return _('Awaiting moderation') if $self->cobrand eq 'zurich' && $self->state eq 'unconfirmed';
+ return $self->title;
+}
+
=head2 check_for_errors
$error_hashref = $problem->check_for_errors();
@@ -335,9 +359,9 @@ sub check_for_errors {
$errors{detail} = _('Please enter some details')
unless $self->detail =~ m/\S/;
- $errors{council} = _('No council selected')
- unless $self->council
- && $self->council =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/;
+ $errors{bodies} = _('No council selected')
+ unless $self->bodies_str
+ && $self->bodies_str =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/;
if ( !$self->name || $self->name !~ m/\S/ ) {
$errors{name} = _('Please enter your name');
@@ -348,7 +372,7 @@ sub check_for_errors {
{
$errors{name} = _(
'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below'
- );
+ ) unless $self->cobrand eq 'emptyhomes';
}
if ( $self->category
@@ -364,6 +388,18 @@ sub check_for_errors {
$self->category(undef);
}
+ if ( $self->bodies_str && $self->detail ) {
+ # Custom character limit:
+ # Bromley Council
+ if ( $self->bodies_str eq '2482' && length($self->detail) > 1750 ) {
+ $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 );
+ }
+ # Oxfordshire
+ if ( $self->bodies_str eq '2237' && length($self->detail) > 1700 ) {
+ $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 );
+ }
+ }
+
return \%errors;
}
@@ -390,18 +426,26 @@ sub confirm {
return 1;
}
-=head2 councils
+sub bodies_str_ids {
+ my $self = shift;
+ return unless $self->bodies_str;
+ (my $bodies = $self->bodies_str) =~ s/\|.*$//;
+ my @bodies = split( /,/, $bodies );
+ return \@bodies;
+}
-Returns an arrayref of councils to which a report was sent.
+=head2 bodies
+
+Returns a hashref of bodies to which a report was sent.
=cut
-sub councils {
+sub bodies($) {
my $self = shift;
- return [] unless $self->council;
- (my $council = $self->council) =~ s/\|.*$//;
- my @council = split( /,/, $council );
- return \@council;
+ return {} unless $self->bodies_str;
+ my $bodies = $self->bodies_str_ids;
+ my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all;
+ return { map { $_->id => $_ } @bodies };
}
=head2 url
@@ -485,8 +529,7 @@ meta data about the report.
sub meta_line {
my ( $problem, $c ) = @_;
- my $date_time =
- Utils::prettify_epoch( $problem->confirmed_local->epoch );
+ my $date_time = Utils::prettify_dt( $problem->confirmed );
my $meta = '';
# FIXME Should be in cobrand
@@ -494,11 +537,7 @@ sub meta_line {
my $category = _($problem->category);
utf8::decode($category);
- if ($problem->anonymous) {
- $meta = sprintf(_('%s, reported anonymously at %s'), $category, $date_time);
- } else {
- $meta = sprintf(_('%s, reported by %s at %s'), $category, $problem->name, $date_time);
- }
+ $meta = sprintf(_('%s, reported at %s'), $category, $date_time);
} else {
@@ -507,11 +546,11 @@ sub meta_line {
and $problem->category && $problem->category ne _('Other') )
{
$meta =
- sprintf( _('Reported by %s in the %s category anonymously at %s'),
+ sprintf( _('Reported via %s in the %s category anonymously at %s'),
$problem->service, $problem->category, $date_time );
}
elsif ( $problem->service ) {
- $meta = sprintf( _('Reported by %s anonymously at %s'),
+ $meta = sprintf( _('Reported via %s anonymously at %s'),
$problem->service, $date_time );
}
elsif ( $problem->category and $problem->category ne _('Other') ) {
@@ -527,13 +566,13 @@ sub meta_line {
and $problem->category && $problem->category ne _('Other') )
{
$meta = sprintf(
- _('Reported by %s in the %s category by %s at %s'),
+ _('Reported via %s in the %s category by %s at %s'),
$problem->service, $problem->category,
$problem->name, $date_time
);
}
elsif ( $problem->service ) {
- $meta = sprintf( _('Reported by %s by %s at %s'),
+ $meta = sprintf( _('Reported via %s by %s at %s'),
$problem->service, $problem->name, $date_time );
}
elsif ( $problem->category and $problem->category ne _('Other') ) {
@@ -555,21 +594,22 @@ sub body {
my ( $problem, $c ) = @_;
my $body;
if ($problem->external_body) {
- $body = $problem->external_body;
+ if ($problem->cobrand eq 'zurich') {
+ $body = $c->model('DB::Body')->find({ id => $problem->external_body });
+ } else {
+ $body = $problem->external_body;
+ }
} else {
- my $councils = $problem->councils;
- my $areas_info = mySociety::MaPit::call('areas', $councils);
+ my $bodies = $problem->bodies;
$body = join( _(' and '),
map {
- my $name = $areas_info->{$_}->{name};
+ my $name = $_->name;
if (mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS')) {
- '<a href="'
- . $c->uri_for( '/reports/' . $c->cobrand->short_name( $areas_info->{$_} ) )
- . '">' . $name . '</a>';
+ '<a href="' . $_->url($c) . '">' . $name . '</a>';
} else {
$name;
}
- } @$councils
+ } values %$bodies
);
}
return $body;
@@ -583,10 +623,10 @@ sub body {
# Note: this only makes sense when called on a problem that has been sent!
sub can_display_external_id {
my $self = shift;
- if ($self->external_id && $self->send_method_used && $self->send_method_used eq 'barnet') {
+ if ($self->external_id && $self->bodies_str =~ /2237/) {
return 1;
}
- return 0;
+ return 0;
}
# TODO Some/much of this could be moved to the template
@@ -603,7 +643,7 @@ sub processed_summary_string {
my ( $problem, $c ) = @_;
my ($duration_clause, $external_ref_clause);
if ($problem->whensent) {
- $duration_clause = $problem->duration_string($c)
+ $duration_clause = $problem->duration_string($c);
}
if ($problem->can_display_external_id) {
if ($duration_clause) {
@@ -623,19 +663,30 @@ sub duration_string {
my ( $problem, $c ) = @_;
my $body = $problem->body( $c );
return sprintf(_('Sent to %s %s later'), $body,
- Utils::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute')
+ Utils::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute')
);
}
+sub local_coords {
+ my $self = shift;
+ if ($self->cobrand eq 'zurich') {
+ my ($x, $y) = Geo::Coordinates::CH1903::from_latlon($self->latitude, $self->longitude);
+ return ( int($x+0.5), int($y+0.5) );
+ }
+}
+
=head2 update_from_open311_service_request
- $p->update_from_open311_service_request( $request, $council_details, $system_user );
+ $p->update_from_open311_service_request( $request, $body, $system_user );
-Updates the problem based on information in the passed in open311 request. If the request
-has an older update time than the problem's lastupdate time then nothing happens.
+Updates the problem based on information in the passed in open311 request
+(standard, not the extension that uses GetServiceRequestUpdates) . If the
+request has an older update time than the problem's lastupdate time then
+nothing happens.
-Otherwise a comment will be created if there is status update text in the open311 request.
-If the open311 request has a state of closed then the problem will be marked as fixed.
+Otherwise a comment will be created if there is status update text in the
+open311 request. If the open311 request has a state of closed then the problem
+will be marked as fixed.
NB: a comment will always be created if the problem is being marked as fixed.
@@ -644,7 +695,7 @@ Fixed problems will not be re-opened by this method.
=cut
sub update_from_open311_service_request {
- my ( $self, $request, $council_details, $system_user ) = @_;
+ my ( $self, $request, $body, $system_user ) = @_;
my ( $updated, $status_notes );
@@ -667,11 +718,10 @@ sub update_from_open311_service_request {
mark_fixed => 0,
user => $system_user,
anonymous => 0,
- name => $council_details->{name},
+ name => $body->name,
}
);
-
my $w3c = DateTime::Format::W3CDTF->new;
my $req_time = $w3c->parse_datetime( $request->{updated_datetime} );
@@ -720,6 +770,29 @@ sub update_send_failed {
} );
}
+sub as_hashref {
+ my $self = shift;
+ my $c = shift;
+
+ return {
+ id => $self->id,
+ title => $self->title,
+ category => $self->category,
+ detail => $self->detail,
+ latitude => $self->latitude,
+ longitude => $self->longitude,
+ postcode => $self->postcode,
+ state => $self->state,
+ state_t => _( $self->state ),
+ used_map => $self->used_map,
+ is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0,
+ photo => $self->get_photo_params,
+ meta => $self->confirmed ? $self->meta_line( $c ) : '',
+ confirmed_pp => $self->confirmed ? $c->cobrand->prettify_dt( $self->confirmed ): '',
+ created_pp => $c->cobrand->prettify_dt( $self->created ),
+ };
+}
+
# we need the inline_constructor bit as we don't inherit from Moose
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm
index b6791603a..7f9c79d9a 100644
--- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm
@@ -36,31 +36,33 @@ __PACKAGE__->belongs_to(
"problem",
"FixMyStreet::DB::Result::Problem",
{ id => "problem_id" },
- { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NGlSRjoBpDoIvK3EueqN6Q
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oL1Hk4/bNG14CY74GA75SA
use DateTime::TimeZone;
+use Moose;
+use namespace::clean -except => [ 'meta' ];
my $tz = DateTime::TimeZone->new( name => "local" );
-sub whensent_local {
- my $self = shift;
+my $tz_f;
+$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') )
+ if FixMyStreet->config('TIME_ZONE');
- return $self->whensent
- ? $self->whensent->set_time_zone($tz)
- : $self->whensent;
-}
+my $stz = sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my $s = $self->$orig(@_);
+ return $s unless $s && UNIVERSAL::isa($s, "DateTime");
+ $s->set_time_zone($tz);
+ $s->set_time_zone($tz_f) if $tz_f;
+ return $s;
+};
-sub whenanswered_local {
- my $self = shift;
-
- return $self->whenanswered
- ? $self->whenanswered->set_time_zone($tz)
- : $self->whenanswered;
-}
+around whensent => $stz;
+around whenanswered => $stz;
1;
diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm
index b223ada3a..5525fe7a5 100644
--- a/perllib/FixMyStreet/DB/Result/Token.pm
+++ b/perllib/FixMyStreet/DB/Result/Token.pm
@@ -34,8 +34,6 @@ __PACKAGE__->set_primary_key("scope", "token");
# use mySociety::DBHandle qw(dbh);
use mySociety::AuthToken;
-use IO::String;
-use RABX;
=head1 NAME
@@ -54,25 +52,9 @@ ms_current_timestamp.
=cut
-__PACKAGE__->filter_column(
- data => {
- filter_from_storage => sub {
- my $self = shift;
- my $ser = shift;
- return undef unless defined $ser;
- my $h = new IO::String($ser);
- return RABX::wire_rd($h);
- },
- filter_to_storage => sub {
- my $self = shift;
- my $data = shift;
- my $ser = '';
- my $h = new IO::String($ser);
- RABX::wire_wr( $data, $h );
- return $ser;
- },
- }
-);
+__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
+__PACKAGE__->rabx_column('data');
+
sub new {
my ( $class, $attrs ) = @_;
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 7f43d1a52..523382670 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -26,8 +26,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"password",
{ data_type => "text", default_value => "", is_nullable => 0 },
- "from_council",
- { data_type => "integer", is_nullable => 1 },
+ "from_body",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
"flagged",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"title",
@@ -42,16 +42,27 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
+ "bodies",
+ "FixMyStreet::DB::Result::Body",
+ { "foreign.comment_user_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->has_many(
"comments",
"FixMyStreet::DB::Result::Comment",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
-__PACKAGE__->has_many(
- "open311confs",
- "FixMyStreet::DB::Result::Open311conf",
- { "foreign.comment_user_id" => "self.id" },
- { cascade_copy => 0, cascade_delete => 0 },
+__PACKAGE__->belongs_to(
+ "from_body",
+ "FixMyStreet::DB::Result::Body",
+ { id => "from_body" },
+ {
+ is_deferrable => 0,
+ join_type => "LEFT",
+ on_delete => "NO ACTION",
+ on_update => "NO ACTION",
+ },
);
__PACKAGE__->has_many(
"problems",
@@ -61,8 +72,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-01 16:20:29
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LKi8u5IYnHW1+Mez64nvGg
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jRAtXRLRNozCmthAg9p0dA
__PACKAGE__->add_columns(
"password" => {
@@ -144,38 +155,27 @@ sub alert_for_problem {
} );
}
-sub council {
+sub body {
my $self = shift;
-
- return '' unless $self->from_council;
-
- my $key = 'council_name:' . $self->from_council;
- my $result = Memcached::get($key);
-
- unless ($result) {
- my $area_info = mySociety::MaPit::call('area', $self->from_council);
- $result = $area_info->{name};
- Memcached::set($key, $result, 86400);
- }
-
- return $result;
+ return '' unless $self->from_body;
+ return $self->from_body->name;
}
-=head2 belongs_to_council
+=head2 belongs_to_body
- $belongs_to_council = $user->belongs_to_council( $council_list );
+ $belongs_to_body = $user->belongs_to_body( $bodies );
-Returns true if the user belongs to the comma seperated list of council ids passed in
+Returns true if the user belongs to the comma seperated list of body ids passed in
=cut
-sub belongs_to_council {
+sub belongs_to_body {
my $self = shift;
- my $council = shift;
+ my $bodies = shift;
- my %councils = map { $_ => 1 } split ',', $council;
+ my %bodies = map { $_ => 1 } split ',', $bodies;
- return 1 if $self->from_council && $councils{ $self->from_council };
+ return 1 if $self->from_body && $bodies{ $self->from_body->id };
return 0;
}