diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/Result')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 143 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 2 |
6 files changed, 88 insertions, 95 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 4ce72f873..c64cb2ff4 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -69,24 +69,16 @@ __PACKAGE__->belongs_to( # You can replace this text with custom code or comments, and it will be preserved on regeneration -use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -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; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 3fae6860a..836462ed5 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -95,25 +95,17 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -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; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index eca028c9b..2fbb0716d 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -63,4 +63,12 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); +use Moose; +use namespace::clean -except => [ 'meta' ]; + +with 'FixMyStreet::Roles::Extra'; + +# we need the inline_constructor bit as we don't inherit from Moose +__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); + 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 34d740912..bed2f160a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -153,13 +153,13 @@ __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; -with 'FixMyStreet::Roles::Abuser'; +with 'FixMyStreet::Roles::Abuser', + 'FixMyStreet::Roles::Extra'; =head2 @@ -228,38 +228,6 @@ sub closed_states { =head2 - @states = FixMyStreet::DB::Problem::visible_states(); - -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 @@ -293,6 +261,70 @@ sub all_states { =head2 + @visible_states = FixMyStreet::DB::Problem::visible_states(); + @hidden_states = FixMyStreet::DB::Problem::hidden_states(); + +Get a list of states that should be visible (or hidden) on the site. If called +in array context then returns an array of names, otherwise returns a HASHREF. + +=cut + +my $hidden_states = { + 'hidden' => 1, + 'partial' => 1, + 'unconfirmed' => 1, +}; + +my $visible_states = { + map { + $hidden_states->{$_} ? () : ($_ => 1) + } all_states() +}; + ## e.g.: + # '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 hidden_states { + return wantarray ? keys %{$hidden_states} : $hidden_states; +} + +sub visible_states { + return wantarray ? keys %{$visible_states} : $visible_states; +} + +sub visible_states_add { + my ($self, @states) = @_; + for my $state (@states) { + delete $hidden_states->{$state}; + $visible_states->{$state} = 1; + } +} + +sub visible_states_remove { + my ($self, @states) = @_; + for my $state (@states) { + delete $visible_states->{$state}; + $hidden_states->{$state} = 1; + } +} + +sub visible_states_add_unconfirmed { + $_[0]->visible_states_add('unconfirmed') +} + +=head2 + @states = FixMyStreet::DB::Problem::council_states(); Get a list of states that are availble to council users. If called in @@ -316,18 +348,11 @@ sub council_states { return wantarray ? keys %{$states} : $states; } -my $tz = DateTime::TimeZone->new( name => "local" ); - -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; + FixMyStreet->set_time_zone($s); return $s; }; @@ -380,14 +405,6 @@ sub check_for_errors { if ( !$self->name || $self->name !~ m/\S/ ) { $errors{name} = _('Please enter your name'); } - elsif (length( $self->name ) < 5 - || $self->name !~ m/\s/ - || $self->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i ) - { - $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 && $self->category eq _('-- Pick a category --') ) @@ -402,18 +419,6 @@ 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; } @@ -662,14 +667,14 @@ sub processed_summary_string { } if ($problem->can_display_external_id) { if ($duration_clause) { - $external_ref_clause = sprintf(_('council ref: %s'), $problem->external_id); + $external_ref_clause = '<strong>' . sprintf(_('Council ref: %s'), $problem->external_id) . '.</strong>'; } else { - $external_ref_clause = sprintf(_('%s ref: %s'), $problem->external_body, $problem->external_id); + $external_ref_clause = '<strong>' . sprintf(_('%s ref: %s'), $problem->external_body, $problem->external_id) . '.</strong>'; } } if ($duration_clause and $external_ref_clause) { - return "$duration_clause, $external_ref_clause" - } else { + return "$duration_clause. $external_ref_clause" + } else { return $duration_clause || $external_ref_clause } } @@ -688,6 +693,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 @@ -745,7 +754,7 @@ sub update_from_open311_service_request { # of course if local timezone is not the one that went into the data # base then we're also in trouble my $lastupdate = $self->lastupdate; - $lastupdate->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); + $lastupdate->set_time_zone( FixMyStreet->local_time_zone ); # update from open311 is older so skip if ( $req_time < $lastupdate ) { diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index 7f9c79d9a..6f2941546 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -43,22 +43,14 @@ __PACKAGE__->belongs_to( # 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" ); - -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; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 6a93f97ec..f08b666c8 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -100,7 +100,7 @@ use mySociety::EmailUtil; =head2 check_for_errors - $error_hashref = $problem->check_for_errors(); + $error_hashref = $user->check_for_errors(); Look at all the fields and return a hashref with all errors found, keyed on the field name. This is intended to be passed back to the form to display the |