diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/CrossSell.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 69 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Base.pm | 69 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 93 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EmptyHomes.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 63 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Reading.pm | 67 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 69 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 79 |
17 files changed, 199 insertions, 354 deletions
diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm index 9235d0a03..4a0f31ea8 100644 --- a/perllib/CrossSell.pm +++ b/perllib/CrossSell.pm @@ -167,7 +167,7 @@ EOF sub display_advert ($$;$%) { my ($c, $email, $name, %data) = @_; - return '' unless $c->cobrand->is_default; + return '' unless $c->cobrand->moniker eq 'fixmystreet'; #if (defined $data{council} && $data{council} eq '2326') { # my ($out, $ad) = display_hfyc_cheltenham_advert($email, $name); diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index c988b23c1..0e34ea64b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -81,7 +81,7 @@ sub index : Path : Args(0) { $c->stash->{alerts} = \%alert_counts; - my $contacts = $c->model('DB::Contact')->summary_count( $c->cobrand->contact_restriction ); + my $contacts = $c->model('DB::Contact')->summary_count(); my %contact_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; @@ -770,7 +770,7 @@ sub update_edit : Path('update_edit') : Args(1) { # If we're hiding an update, see if it marked as fixed and unfix if so if ( $new_state eq 'hidden' && $update->mark_fixed ) { - if ( $update->problem->state eq 'fixed' ) { + if ( $update->problem->state =~ /^fixed/ ) { $update->problem->state('confirmed'); $update->problem->update; } diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index ff92a7d2d..40dde455e 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -27,8 +27,6 @@ Show the alerts page sub index : Path('') : Args(0) { my ( $self, $c ) = @_; - $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); - unless ( $c->req->referer && $c->req->referer =~ /fixmystreet\.com/ ) { $c->forward( 'add_recent_photos', [10] ); } @@ -149,7 +147,6 @@ sub updates : Path('updates') : Args(0) { $c->stash->{email} = $c->req->param('rznvy'); $c->stash->{problem_id} = $c->req->param('id'); - $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); } =head2 confirm @@ -508,8 +505,6 @@ sub setup_request : Private { $c->stash->{rznvy} ||= $c->user->email; } - $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); - return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 6596615c6..166f9d58e 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -100,10 +100,6 @@ sub format_problem_for_display : Private { $c->stash->{banner} = $c->cobrand->generate_problem_banner($problem); - $c->stash->{cobrand_alert_fields} = $c->cobrand->form_elements('/alerts'); - $c->stash->{cobrand_update_fields} = - $c->cobrand->form_elements('/updateForm'); - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = map { Utils::truncate_coordinate($_) } ( $problem->latitude, $problem->longitude ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index e982d6a4c..1e5825460 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -654,13 +654,15 @@ sub process_user : Private { $report->user( $user ); $report->name( $user->name ); $c->stash->{field_errors}->{name} = _('You have successfully signed in; please check and confirm your details are accurate:'); + $c->log->info($user->id . ' logged in during problem creation'); return 1; } # set the user's name, phone, and password $report->user->name( Utils::trim_text( $params{name} ) ) if $params{name}; $report->user->phone( Utils::trim_text( $params{phone} ) ); - $report->user->password( Utils::trim_text( $params{password_register} ) ); + $report->user->password( Utils::trim_text( $params{password_register} ) ) + if $params{password_register}; $report->name( Utils::trim_text( $params{name} ) ); return 1; @@ -957,10 +959,12 @@ sub save_user_and_report : Private { $report->user->phone( undef ); $report->user->password( '', 1 ); $report->user->insert(); + $c->log->info($report->user->id . ' created for this report'); } elsif ( $c->user && $report->user->id == $c->user->id ) { $report->user->update(); $report->confirm; + $c->log->info($report->user->id . ' is logged in for this report'); } else { # User exists and we are not logged in as them. @@ -971,6 +975,7 @@ sub save_user_and_report : Private { password => $report->user->password, }; $report->user->discard_changes(); + $c->log->info($report->user->id . ' exists, but is not logged in for this report'); } # If there was a photo add that too @@ -1050,6 +1055,7 @@ sub redirect_or_confirm_creation : Private { # Subscribe problem reporter to email updates $c->forward( 'create_reporter_alert' ); my $report_uri = $c->uri_for( '/report', $report->id ); + $c->log->info($report->user->id . ' was logged in, redirecting to /report/' . $report->id); $c->res->redirect($report_uri); $c->detach; } @@ -1071,6 +1077,7 @@ sub redirect_or_confirm_creation : Private { # tell user that they've been sent an email $c->stash->{template} = 'email_sent.html'; $c->stash->{email_type} = 'problem'; + $c->log->info($report->user->id . ' created ' . $report->id . ', email sent, ' . ($data->{password} ? 'password set' : 'password not set')); } sub create_reporter_alert : Private { diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index c67ca4d1f..29933e2f6 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -134,7 +134,8 @@ sub process_user : Private { $update->user->name( Utils::trim_text( $params{name} ) ) if $params{name}; - $update->user->password( Utils::trim_text( $params{password_register} ) ); + $update->user->password( Utils::trim_text( $params{password_register} ) ) + if $params{password_register}; return 1; } diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 43d46ae25..755f1e405 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -168,7 +168,7 @@ sub html_filter { my %version_hash; sub version { my ( $self, $c, $file ) = @_; - unless ($version_hash{$file}) { + unless ($version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) { my $path = FixMyStreet->path_to('web', $file); $version_hash{$file} = ( stat( $path ) )[9]; } diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm index 6fe2a2bc8..ad21820d7 100644 --- a/perllib/FixMyStreet/Cobrand.pm +++ b/perllib/FixMyStreet/Cobrand.pm @@ -84,6 +84,9 @@ sub get_class_for_moniker { return $avail if $moniker eq $avail->moniker; } + # Special case for old blank cobrand entries in fixmystreet.com. + return 'FixMyStreet::Cobrand::FixMyStreet' if $moniker eq ''; + # if none match then use the default return 'FixMyStreet::Cobrand::Default'; } diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index a12fa6d06..9791b071a 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -1,66 +1,13 @@ package FixMyStreet::Cobrand::Barnet; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -use Carp; -use URI::Escape; -use mySociety::VotingArea; - -sub site_restriction { - return ( "and council='2489'", 'barnet', { council => '2489' } ); -} - -sub problems_clause { - return { council => '2489' }; -} - -sub problems { - my $self = shift; - return $self->{c}->model('DB::Problem')->search( $self->problems_clause ); -} - -sub base_url { - my $base_url = mySociety::Config::get('BASE_URL'); - if ( $base_url !~ /barnet/ ) { - $base_url =~ s{http://(?!www\.)}{http://barnet.}g; - $base_url =~ s{http://www\.}{http://barnet.}g; - } - return $base_url; -} - -sub site_title { - my ($self) = @_; - return 'Barnet Council FixMyStreet'; -} - -sub enter_postcode_text { - my ($self) = @_; - return 'Enter a Barnet postcode, or street name and area'; -} - -sub council_check { - my ( $self, $params, $context ) = @_; - - my $councils = $params->{all_councils}; - my $council_match = defined $councils->{2489}; - if ($council_match) { - return 1; - } - my $url = 'http://www.fixmystreet.com/'; - $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape( $self->{c}->req->param('pc') ) - if $self->{c}->req->param('pc'); - my $error_msg = "That location is not covered by Barnet. -Please visit <a href=\"$url\">the main FixMyStreet site</a>."; - return ( 0, $error_msg ); -} - -# All reports page only has the one council. -sub all_councils_report { - return 0; -} +sub council_id { return 2489; } +sub council_area { return 'Barnet'; } +sub council_name { return 'Barnet Council'; } +sub council_url { return 'barnet'; } sub disambiguate_location { return { @@ -70,11 +17,5 @@ sub disambiguate_location { }; } -sub recent_photos { - my ( $self, $num, $lat, $lon, $dist ) = @_; - $num = 2 if $num == 3; - return $self->problems->recent_photos( $num, $lat, $lon, $dist ); -} - 1; diff --git a/perllib/FixMyStreet/Cobrand/Base.pm b/perllib/FixMyStreet/Cobrand/Base.pm new file mode 100644 index 000000000..42a891cb4 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/Base.pm @@ -0,0 +1,69 @@ +package FixMyStreet::Cobrand::Base; + +use strict; +use warnings; + +=head2 new + + my $cobrand = $class->new; + my $cobrand = $class->new( { c => $c } ); + +Create a new cobrand object, optionally setting the context. + +You probably shouldn't need to do this and should get the cobrand object via a +method in L<FixMyStreet::Cobrand> instead. + +=cut + +sub new { + my $class = shift; + my $self = shift || {}; + return bless $self, $class; +} + +=head2 moniker + + $moniker = $cobrand_class->moniker(); + +Returns a moniker that can be used to identify this cobrand. By default this is +the last part of the class name lowercased - eg 'F::C::SomeCobrand' becomes +'somecobrand'. + +=cut + +sub moniker { + my $class = ref( $_[0] ) || $_[0]; # deal with object or class + my ($last_part) = $class =~ m{::(\w+)$}; + $last_part = lc($last_part); + return $last_part; +} + +=head2 is_default + + $bool = $cobrand->is_default(); + +Returns true if this is the default cobrand, false otherwise. + +=cut + +sub is_default { + my $self = shift; + return $self->moniker eq 'default'; +} + +=head2 path_to_web_templates + + $path = $cobrand->path_to_web_templates( ); + +Returns the path to the templates for this cobrand - by default +"templates/web/$moniker" + +=cut + +sub path_to_web_templates { + my $self = shift; + return FixMyStreet->path_to( 'templates/web', $self->moniker ); +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index b5a1cd8d3..aeb956680 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1,4 +1,5 @@ package FixMyStreet::Cobrand::Default; +use base 'FixMyStreet::Cobrand::Base'; use strict; use warnings; @@ -10,69 +11,6 @@ use Carp; use mySociety::MaPit; use mySociety::PostcodeUtil; -=head2 new - - my $cobrand = $class->new; - my $cobrand = $class->new( { c => $c } ); - -Create a new cobrand object, optionally setting the context. - -You probably shouldn't need to do this and should get the cobrand object via a -method in L<FixMyStreet::Cobrand> instead. - -=cut - -sub new { - my $class = shift; - my $self = shift || {}; - return bless $self, $class; -} - -=head2 moniker - - $moniker = $cobrand_class->moniker(); - -Returns a moniker that can be used to identify this cobrand. By default this is -the last part of the class name lowercased - eg 'F::C::SomeCobrand' becomes -'somecobrand'. - -=cut - -sub moniker { - my $class = ref( $_[0] ) || $_[0]; # deal with object or class - my ($last_part) = $class =~ m{::(\w+)$}; - $last_part = lc($last_part); - return '' if $last_part eq 'default'; - return $last_part; -} - -=head2 is_default - - $bool = $cobrand->is_default(); - -Returns true if this is the default cobrand, false otherwise. - -=cut - -sub is_default { - my $self = shift; - return $self->moniker eq ''; -} - -=head2 path_to_web_templates - - $path = $cobrand->path_to_web_templates( ); - -Returns the path to the templates for this cobrand - by default -"templates/web/$moniker" - -=cut - -sub path_to_web_templates { - my $self = shift; - return FixMyStreet->path_to( 'templates/web', $self->moniker ); -} - =head1 country Returns the country that this cobrand operates in, as an ISO3166-alpha2 code. @@ -114,17 +52,6 @@ empty string and site key 0 if the cobrand uses all the data. sub site_restriction { return ( "", 0, {} ) } -=head2 contact_restriction - -Return a contact restriction clause if the cobrand uses a subset of the -FixMyStreet contact data. - -=cut - -sub contact_restriction { - {}; -} - =head2 restriction Return a restriction to pull out data saved while using the cobrand site. @@ -315,15 +242,6 @@ sub disambiguate_location { }; } -=head2 form_elements - -Parameters are FORM_NAME, QUERY. Return HTML for any extra needed elements for -FORM_NAME - -=cut - -sub form_elements { '' } - =head2 cobrand_data_for_generic_update Parameter is UPDATE_DATA, a reference to a hash of non-cobranded update data. @@ -422,15 +340,6 @@ Return any params to be added to responses sub header_params { return {} } -=head2 root_path_js - -Parameter is QUERY. Return some js to set the root path from which AJAX queries -should be made. - -=cut - -sub root_path_js { 'var root_path = "";' } - =head2 site_title Return the title to be used in page heads. diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm index 189daee0c..6885f6a95 100644 --- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm +++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm @@ -1,5 +1,5 @@ package FixMyStreet::Cobrand::EmptyHomes; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::FixMyStreet'; use strict; use warnings; diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm new file mode 100644 index 000000000..37fa7a16d --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -0,0 +1,10 @@ +package FixMyStreet::Cobrand::FixMyStreet; +use base 'FixMyStreet::Cobrand::Default'; + +# FixMyStreet should return all cobrands +sub restriction { + return {}; +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 12882faee..91c5e10ec 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -1,13 +1,16 @@ package FixMyStreet::Cobrand::LichfieldDC; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -use Carp; -use URI::Escape; -use mySociety::VotingArea; +sub council_id { return 2434; } +sub council_area { return 'Lichfield district'; } +sub council_name { return 'Lichfield District Council'; } +sub council_url { return 'lichfielddc'; } +# Different to councils parent due to this being a two-tier council. If we get +# more, this can be genericised in the parent. sub site_restriction { return ( "and council like '%2434%'", 'lichfield', { council => '2434' } ); } @@ -16,52 +19,6 @@ sub problems_clause { return { council => { like => '%2434%' } }; } -sub problems { - my $self = shift; - return $self->{c}->model('DB::Problem')->search( $self->problems_clause ); -} - -sub base_url { - my $base_url = mySociety::Config::get('BASE_URL'); - if ( $base_url !~ /lichfielddc/ ) { - $base_url =~ s{http://(?!www\.)}{http://lichfielddc.}g; - $base_url =~ s{http://www\.}{http://lichfielddc.}g; - } - return $base_url; -} - -sub site_title { - my ($self) = @_; - return 'Lichfield District Council FixMyStreet'; -} - -sub enter_postcode_text { - my ($self) = @_; - return 'Enter a Lichfield district postcode, or street name and area'; -} - -sub council_check { - my ( $self, $params, $context ) = @_; - - my $councils = $params->{all_councils}; - my $council_match = defined $councils->{2434}; - if ($council_match) { - return 1; - } - my $url = 'http://www.fixmystreet.com/'; - $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape( $self->{c}->req->param('pc') ) - if $self->{c}->req->param('pc'); - my $error_msg = "That location is not covered by Lichfield District Council. -Please visit <a href=\"$url\">the main FixMyStreet site</a>."; - return ( 0, $error_msg ); -} - -# All reports page only has the one council. -sub all_councils_report { - return 0; -} - # FIXME - need to double check this is all correct sub disambiguate_location { return { @@ -71,11 +28,5 @@ sub disambiguate_location { }; } -sub recent_photos { - my ( $self, $num, $lat, $lon, $dist ) = @_; - $num = 2 if $num == 3; - return $self->problems->recent_photos( $num, $lat, $lon, $dist ); -} - 1; diff --git a/perllib/FixMyStreet/Cobrand/Reading.pm b/perllib/FixMyStreet/Cobrand/Reading.pm index 8e98931fd..afc2b6ac6 100644 --- a/perllib/FixMyStreet/Cobrand/Reading.pm +++ b/perllib/FixMyStreet/Cobrand/Reading.pm @@ -1,66 +1,15 @@ package FixMyStreet::Cobrand::Reading; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; use Carp; -use URI::Escape; -use mySociety::VotingArea; -sub site_restriction { - return ( "and council='2596'", 'reading', { council => '2596' } ); -} - -sub problems_clause { - return { council => '2596' }; -} - -sub problems { - my $self = shift; - return $self->{c}->model('DB::Problem')->search( $self->problems_clause ); -} - -sub base_url { - my $base_url = mySociety::Config::get('BASE_URL'); - if ($base_url !~ /reading/) { - $base_url =~ s{http://(?!www\.)}{http://reading.}g; - $base_url =~ s{http://www\.}{http://reading.}g; - } - return $base_url; -} - -sub site_title { - my ( $self ) = @_; - return 'Reading City Council FixMyStreet'; -} - -sub enter_postcode_text { - my ( $self ) = @_; - return 'Enter a Reading postcode, or street name and area'; -} - -sub council_check { - my ( $self, $params, $context ) = @_; - - my $councils = $params->{all_councils}; - my $council_match = defined $councils->{2596}; - if ($council_match) { - return 1; - } - my $url = 'http://www.fixmystreet.com/'; - $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape_utf8($self->{c}->req->param('pc')) - if $self->{c}->req->param('pc'); - my $error_msg = "That location is not covered by Reading. -Please visit <a href=\"$url\">the main FixMyStreet site</a>."; - return ( 0, $error_msg ); -} - -# All reports page only has the one council. -sub all_councils_report { - return 0; -} +sub council_id { return 2596; } +sub council_area { return 'Reading'; } +sub council_name { return 'Reading City Council'; } +sub council_url { return 'reading'; } sub disambiguate_location { return { @@ -71,12 +20,6 @@ sub disambiguate_location { }; } -sub recent_photos { - my ($self, $num, $lat, $lon, $dist) = @_; - $num = 2 if $num == 3; - return $self->problems->recent_photos( $num, $lat, $lon, $dist ); -} - sub get_report_stats { my $self = shift; diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index 213dd533b..5bb7df3b6 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -1,66 +1,13 @@ package FixMyStreet::Cobrand::Southampton; -use base 'FixMyStreet::Cobrand::Default'; +use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -use Carp; -use URI::Escape; -use mySociety::VotingArea; - -sub site_restriction { - return ( "and council='2567'", 'southampton', { council => '2567' } ); -} - -sub problems_clause { - return { council => '2567' }; -} - -sub problems { - my $self = shift; - return $self->{c}->model('DB::Problem')->search( $self->problems_clause ); -} - -sub base_url { - my $base_url = mySociety::Config::get('BASE_URL'); - if ($base_url !~ /southampton/) { - $base_url =~ s{http://(?!www\.)}{http://southampton.}g; - $base_url =~ s{http://www\.}{http://southampton.}g; - } - return $base_url; -} - -sub site_title { - my ( $self ) = @_; - return 'Southampton City Council FixMyStreet'; -} - -sub enter_postcode_text { - my ( $self ) = @_; - return 'Enter a Southampton postcode, or street name and area'; -} - -sub council_check { - my ( $self, $params, $context ) = @_; - - my $councils = $params->{all_councils}; - my $council_match = defined $councils->{2567}; - if ($council_match) { - return 1; - } - my $url = 'http://www.fixmystreet.com/'; - $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape_utf8($self->{c}->req->param('pc')) - if $self->{c}->req->param('pc'); - my $error_msg = "That location is not covered by Southampton. -Please visit <a href=\"$url\">the main FixMyStreet site</a>."; - return ( 0, $error_msg ); -} - -# All reports page only has the one council. -sub all_councils_report { - return 0; -} +sub council_id { return 2567; } +sub council_area { return 'Southampton'; } +sub council_name { return 'Southampton City Council'; } +sub council_url { return 'southampton'; } sub disambiguate_location { return { @@ -71,11 +18,5 @@ sub disambiguate_location { }; } -sub recent_photos { - my ($self, $num, $lat, $lon, $dist) = @_; - $num = 2 if $num == 3; - return $self->problems->recent_photos( $num, $lat, $lon, $dist ); -} - 1; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm new file mode 100644 index 000000000..589abd178 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -0,0 +1,79 @@ +package FixMyStreet::Cobrand::UKCouncils; +use base 'FixMyStreet::Cobrand::FixMyStreet'; + +use strict; +use warnings; + +use Carp; +use URI::Escape; + +sub site_restriction { + my $self = shift; + return ( "and council='" . $self->council_id . "'", $self->council_url, { council => sprintf('%d', $self->council_id) } ); +} + +sub restriction { + return { cobrand => shift->moniker }; +} + +sub problems_clause { + my $self = shift; + return { council => sprintf('%d', $self->council_id) }; +} + +sub problems { + my $self = shift; + return $self->{c}->model('DB::Problem')->search( $self->problems_clause ); +} + +sub base_url { + my $self = shift; + my $base_url = mySociety::Config::get('BASE_URL'); + my $u = $self->council_url; + if ( $base_url !~ /$u/ ) { + $base_url =~ s{http://(?!www\.)}{http://$u.}g; + $base_url =~ s{http://www\.}{http://$u.}g; + } + return $base_url; +} + +sub site_title { + my ($self) = @_; + return $self->council_name . ' FixMyStreet'; +} + +sub enter_postcode_text { + my ($self) = @_; + return 'Enter a ' . $self->council_area . ' postcode, or street name and area'; +} + +sub council_check { + my ( $self, $params, $context ) = @_; + + my $councils = $params->{all_councils}; + my $council_match = defined $councils->{$self->council_id}; + if ($council_match) { + return 1; + } + my $url = 'http://www.fixmystreet.com/'; + $url .= 'alert' if $context eq 'alert'; + $url .= '?pc=' . URI::Escape::uri_escape( $self->{c}->req->param('pc') ) + if $self->{c}->req->param('pc'); + my $error_msg = "That location is not covered by " . $self->council_name . ". +Please visit <a href=\"$url\">the main FixMyStreet site</a>."; + return ( 0, $error_msg ); +} + +# All reports page only has the one council. +sub all_councils_report { + return 0; +} + +sub recent_photos { + my ( $self, $num, $lat, $lon, $dist ) = @_; + $num = 2 if $num == 3; + return $self->problems->recent_photos( $num, $lat, $lon, $dist ); +} + +1; + |