aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/info_request.rb
diff options
context:
space:
mode:
authorfrancis <francis>2008-03-31 19:14:47 +0000
committerfrancis <francis>2008-03-31 19:14:47 +0000
commitfaf4fe328dc7cb5b1716330e11e0dd0e31dde198 (patch)
tree6f17a80f790b82be6d922a169e019aeb7fc0c4b8 /app/models/info_request.rb
parentd3ac447e87c8530293cebd49a55cf9d80dad88d5 (diff)
Column for calculated state of an event.
Diffstat (limited to 'app/models/info_request.rb')
-rw-r--r--app/models/info_request.rb40
1 files changed, 21 insertions, 19 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index d1b96bcc3..59889bea1 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -22,7 +22,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.75 2008-03-31 17:49:27 francis Exp $
+# $Id: info_request.rb,v 1.76 2008-03-31 19:14:47 francis Exp $
require 'digest/sha1'
@@ -78,26 +78,10 @@ class InfoRequest < ActiveRecord::Base
info_request = InfoRequest.find(id, :lock =>true)
do_index = (info_request.prominence != 'backpage')
- # Fill in any missing event states for first response before a
- # description was made.
- events = info_request.info_request_events.find(:all, :order => "created_at")
- curr_state = nil
- for event in events.reverse
- if event.described_state.nil?
- if not curr_state.nil? and event.event_type == 'response'
- event.described_state = curr_state
- curr_state = nil
- end
- else
- if event.event_type == 'response'
- curr_state = nil
- else
- curr_state = event.described_state
- end
- end
- end
+ info_request.calculate_event_states
# index all the events
+ events = info_request.info_request_events.find(:all, :order => "created_at")
for event in events
if do_index and event.indexed_by_solr
event.solr_save
@@ -250,6 +234,24 @@ public
return self.described_state
end
+ # Fill in any missing event states for first response before a
+ # description was made.
+ def calculate_event_states
+ events = self.info_request_events.find(:all, :order => "created_at")
+ curr_state = nil
+ for event in events.reverse
+ if not event.described_state.nil?
+ curr_state = event.described_state
+ end
+
+ if not curr_state.nil? and event.event_type == 'response'
+ event.calculated_state = curr_state
+ curr_state = nil
+ event.save!
+ end
+ end
+ end
+
# Calculate date by which response is required by law.
#
# ... "working day” means any day other than a Saturday, a Sunday, Christmas