diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 19 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 10 |
2 files changed, 22 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 99d7bddee..f4985915f 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -379,13 +379,30 @@ sub get_requests : Private { $c->stash->{type} = 'new_problems'; $c->stash->{search_criteria} = $criteria; $c->stash->{max_requests} = $max_requests; - # Call Controller::Rss::output + $c->stash->{query_func} = '/open311/rss_query'; $c->forward( '/rss/output' ); } else { $c->forward( 'output_requests', [ $criteria, $max_requests ] ); } } +# Based on Controller::Rss::query_main +sub rss_query : Private { + my ( $self, $c ) = @_; + + my $limit = $c->stash->{max_requests}; + $limit = $c->config->{RSS_LIMIT} + unless $limit && $limit <= $c->config->{RSS_LIMIT}; + + my $attr = { + order_by => { -desc => 'confirmed' }, + rows => $limit + }; + + my $problems = $c->cobrand->problems->search( $criteria, $attr ); + $c->stash->{query_main} = $problems; +} + # Example # http://seeclickfix.com/open311/requests/1.xml?jurisdiction_id=sfgov.org sub get_request : Private { diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 4a5b320ed..640c0bb47 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -156,7 +156,8 @@ sub output : Private { $c->detach( '/page_error_404_not_found', [ _('Unknown alert type') ] ) unless $c->stash->{alert_type}; - $c->forward( 'query_main' ); + my $query_func = $c->stash->{query_func} || 'query_main'; + $c->forward( $query_func ); # Do our own encoding $c->stash->{rss} = new XML::RSS( @@ -191,16 +192,13 @@ sub query_main : Private { my ( $site_restriction, $site_id ) = $c->cobrand->site_restriction( $c->cobrand->extra_data ); # Only apply a site restriction if the alert uses the problem table $site_restriction = '' unless $alert_type->item_table eq 'problem'; - my $search_criteria = $c->stash->{search_criteria}; # FIXME Do this in a nicer way at some point in the future... my $query = 'select * from ' . $alert_type->item_table . ' where ' . ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '') - . $alert_type->item_where . $site_restriction . - . ($search_criteria ? "and $search_criteria" : '') - . ' order by ' . $alert_type->item_order; + . $alert_type->item_where . $site_restriction . ' order by ' + . $alert_type->item_order; my $rss_limit = mySociety::Config::get('RSS_LIMIT'); - $rss_limit = $c->stash->{max_requests} if $c->stash->{max_requests}; $query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/; my $q = $c->model('DB::Alert')->result_source->storage->dbh->prepare($query); |