diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 135 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 42 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 2 |
7 files changed, 212 insertions, 16 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index ae152eb31..958194eb8 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -52,6 +52,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "anonymous", { data_type => "boolean", is_nullable => 0 }, + "problem_state", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( @@ -68,8 +70,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TYFusbxkOkAewaiZYZVJUA +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:07:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ilLn3dlagg5COdpZDmzrVQ use DateTime::TimeZone; use Image::Size; @@ -147,6 +149,22 @@ sub get_photo_params { return $photo; } +=head2 meta_problem_state + +Returns a string suitable for display in the update meta section. +Mostly removes the '- council/user' bit from fixed states + +=cut + +sub meta_problem_state { + my $self = shift; + + my $state = $self->problem_state; + $state =~ s/ -.*$//; + + return $state; +} + # 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/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 6472b91db..987c92c64 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -121,6 +121,92 @@ use Utils; with 'FixMyStreet::Roles::Abuser'; +=head2 + + @states = FixMyStreet::DB::Problem::open_states(); + +Get a list or states that are regarded as open. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub open_states { + my $states = { + 'confirmed' => 1, + 'investigating' => 1, + 'planned' => 1, + 'in progress' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + +=head2 + + @states = FixMyStreet::DB::Problem::fixed_states(); + +Get a list or states that should be regarded as fixed. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub fixed_states { + my $states = { + 'fixed' => 1, + 'fixed - user' => 1, + 'fixed - council' => 1, + }; + + return wantarray ? keys %{ $states } : $states; +} + +=head2 + + @states = FixMyStreet::DB::Problem::closed_states(); + +Get a list or states that should be regarded as closed. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub closed_states { + my $states = { + 'closed' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + + +=head2 + + @states = FixMyStreet::DB::Problem::visible_states(); + +Get a list or states that should be visible on the site. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub visible_states { + my $states = { + 'confirmed' => 1, + 'planned' => 1, + 'investigating' => 1, + 'in progress' => 1, + 'fixed' => 1, + 'fixed - council' => 1, + 'fixed - user' => 1, + 'closed' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + + my $tz = DateTime::TimeZone->new( name => "local" ); sub confirmed_local { @@ -286,6 +372,55 @@ sub get_photo_params { return $photo; } +=head2 is_open + +Returns 1 if the problem is in a open state otherwise 0. + +=cut + +sub is_open { + my $self = shift; + + return exists $self->open_states->{ $self->state } ? 1 : 0; +} + + +=head2 is_fixed + +Returns 1 if the problem is in a fixed state otherwise 0. + +=cut + +sub is_fixed { + my $self = shift; + + return exists $self->fixed_states->{ $self->state } ? 1 : 0; +} + +=head2 is_closed + +Returns 1 if the problem is in a closed state otherwise 0. + +=cut + +sub is_closed { + my $self = shift; + + return exists $self->closed_states->{ $self->state } ? 1 : 0; +} + +=head2 is_visible + +Returns 1 if the problem should be displayed on the site otherwise 0. + +=cut + +sub is_visible { + my $self = shift; + + return exists $self->visible_states->{ $self->state } ? 1 : 0; +} + =head2 meta_line Returns a string to be used on a problem report page, describing some of the diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index cf4fc56d5..d2e43b5b0 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -26,6 +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 }, "flagged", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); @@ -51,8 +53,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T2JK+KyfoE2hkCLgreq1XQ +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:25:21 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9IHuqRTcHZCqJeBAaiQxzw __PACKAGE__->add_columns( "password" => { @@ -134,4 +136,40 @@ sub alert_for_problem { } ); } +sub council { + 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; +} + +=head2 belongs_to_council + + $belongs_to_council = $user->belongs_to_council( $council_list ); + +Returns true if the user belongs to the comma seperated list of council ids passed in + +=cut + +sub belongs_to_council { + my $self = shift; + my $council = shift; + + my %councils = map { $_ => 1 } split '\|', $council; + + return 1 if $self->from_council && $councils{ $self->from_council }; + + return 0; +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 46009cb85..bf085e32a 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -50,6 +50,7 @@ sub email_alerts ($) { # XXX Ugh - needs work $query =~ s/\?/alert.parameter/ if ($query =~ /\?/); $query =~ s/\?/alert.parameter2/ if ($query =~ /\?/); + $query = dbh()->prepare($query); $query->execute(); my $last_alert_id; @@ -74,10 +75,13 @@ sub email_alerts ($) { } # create problem status message for the templates - $data{state_message} = - $row->{state} eq 'fixed' - ? _("This report is currently marked as fixed.") - : _("This report is currently marked as open."); + if ( FixMyStreet::DB::Result::Problem::fixed_states()->{$row->{state}} ) { + $data{state_message} = _("This report is currently marked as fixed."); + } elsif ( FixMyStreet::DB::Result::Problem::closed_states()->{$row->{state}} ) { + $data{state_message} = _("This report is currently marked as closed.") + } else { + $data{state_message} = _("This report is currently marked as open."); + } my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} ); if ($row->{item_text}) { @@ -130,11 +134,12 @@ sub email_alerts ($) { $d = mySociety::Locale::in_gb_locale { sprintf("%f", int($d*10+0.5)/10); }; + my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'"; my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data ); my $q = "select problem.id, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users where nearby.problem_id = problem.id and problem.user_id = users.id - and problem.state in ('confirmed', 'fixed') + and problem.state in ($states) and problem.confirmed >= ? and problem.confirmed >= ms_current_timestamp() - '7 days'::interval and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 3b3a3d90b..04089096e 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -8,7 +8,7 @@ sub nearby { my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_; my $params = { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem::visible_states() ], }; $params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" } if $interval; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index ca329ab59..89f17fa60 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -21,7 +21,7 @@ sub recent_fixed { my $result = Memcached::get($key); unless ($result) { $result = $rs->search( { - state => 'fixed', + state => [ FixMyStreet::DB::Result::Problem->fixed_states() ], lastupdate => { '>', \"current_timestamp-'1 month'::interval" }, } )->count; Memcached::set($key, $result, 3600); @@ -50,7 +50,7 @@ sub recent_new { my $result = Memcached::get($key); unless ($result) { $result = $rs->search( { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], confirmed => { '>', \"current_timestamp-'$interval'::interval" }, } )->count; Memcached::set($key, $result, 3600); @@ -66,7 +66,7 @@ sub recent { my $result = Memcached::get($key); unless ($result) { $result = [ $rs->search( { - state => [ 'confirmed', 'fixed' ] + state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }, { columns => [ 'id', 'title' ], order_by => { -desc => 'confirmed' }, @@ -81,7 +81,7 @@ sub recent_photos { my ( $rs, $num, $lat, $lon, $dist ) = @_; my $probs; my $query = { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], photo => { '!=', undef }, }; my $attrs = { @@ -125,7 +125,7 @@ sub around_map { $attr->{rows} = $limit if $limit; my $q = { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], latitude => { '>=', $min_lat, '<', $max_lat }, longitude => { '>=', $min_lon, '<', $max_lon }, }; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index e490c77a6..665e0e3e0 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -19,7 +19,7 @@ sub send_questionnaires_period { # Select all problems that need a questionnaire email sending my $q_params = { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem::visible_states() ], whensent => [ '-and', { '!=', undef }, |