diff options
Diffstat (limited to 'app/models/info_request_event.rb')
-rw-r--r-- | app/models/info_request_event.rb | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index a6f67c4fd..20340e540 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -16,7 +16,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request_event.rb,v 1.25 2008-03-24 09:35:23 francis Exp $ +# $Id: info_request_event.rb,v 1.26 2008-03-31 17:20:59 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -47,6 +47,63 @@ class InfoRequestEvent < ActiveRecord::Base 'requires_admin' ] + # Full text search indexing + acts_as_solr :fields => [ + { :solr_text_main => :text }, + { :title => :text }, + { :status => :string }, + { :requested_by => :string }, + { :requested_from => :string }, + { :created_at => :date }, + { :variety => :string } + ], :if => "$do_solr_index" + def status # for name in Solr queries + self.info_request.calculate_status + end + def requested_by + if self.event_type == 'sent' + self.info_request.user.url_name + else + nil + end + end + def requested_from + if self.event_type == 'sent' + self.info_request.public_body.url_name + else + nil + end + end + def solr_text_main + text = '' + if self.event_type == 'sent' + text = text + self.outgoing_message.body_without_salutation + "\n\n" + elsif self.event_type == 'followup_sent' + text = text + self.outgoing_message.body_without_salutation + "\n\n" + elsif self.event_type == 'response' + text = text + self.incoming_message.get_text_for_indexing + "\n\n" + else + # nothing + end + return text + end + def title + if self.event_type == 'sent' + return self.info_request.title + end + return '' + end + def indexed_by_solr + if ['sent', 'followup_sent', 'response'].include?(self.event_type) + return true + else + return false + end + end + def variety + self.event_type + end + # We store YAML version of parameters in the database def params=(params) self.params_yaml = params.to_yaml @@ -59,7 +116,7 @@ class InfoRequestEvent < ActiveRecord::Base # XXX search for the find below and call this function more instead def incoming_message if not ['response'].include?(self.event_type) - raise "only call incoming_message for response events" + return nil end if not self.params[:incoming_message_id] @@ -73,7 +130,7 @@ class InfoRequestEvent < ActiveRecord::Base # XXX search for the find below and call this function more instead def outgoing_message if not [ 'edit_outgoing', 'sent', 'resent', 'followup_sent' ].include?(self.event_type) - raise "only call outgoing_message for appropriate event types" + return nil end if not self.params[:outgoing_message_id] @@ -83,6 +140,33 @@ class InfoRequestEvent < ActiveRecord::Base return OutgoingMessage.find(self.params[:outgoing_message_id].to_i) end + # Display version of status + def display_status + if incoming_message.nil? + raise "display_status only works for incoming messages right now" + end + status = self.described_state + raise status.to_s + if status == 'waiting_response' + "Acknowledgement" + elsif status == 'waiting_clarification' + "Clarification request" + elsif status == 'not_held' + "Information not held" + elsif status == 'rejected' + "Rejection" + elsif status == 'partially_successful' + "Partially successful response" + elsif status == 'successful' + "Successful response" + elsif status == 'requires_admin' + "Unusual response" + else + raise "unknown status " + status + end + end + + end |