# == Schema Information # Schema version: 52 # # Table name: track_things # # id :integer not null, primary key # tracking_user_id :integer not null # track_query :string(255) not null # info_request_id :integer # tracked_user_id :integer # public_body_id :integer # track_medium :string(255) not null # track_type :string(255) not null # created_at :datetime # updated_at :datetime # # models/track_thing.rb: # When somebody is getting alerts for something. # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # # $Id: track_thing.rb,v 1.10 2008-04-21 16:44:06 francis Exp $ class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' validates_presence_of :track_query validates_presence_of :track_type belongs_to :info_request belongs_to :public_body belongs_to :tracked_user, :class_name => 'User' has_many :track_things_sent_emails validates_inclusion_of :track_type, :in => [ 'request_updates', ] validates_inclusion_of :track_medium, :in => [ 'email_daily', 'feed' ] def TrackThing.create_track_for_request(info_request) track_thing = TrackThing.new track_thing.track_type = 'request_updates' track_thing.info_request = info_request track_thing.track_query = "request:" + info_request.url_title return track_thing end # Return hash of text parameters describing the request etc. include LinkToHelper def params if @params.nil? if self.track_type == 'request_updates' @params = { # Website :set_title => "How would you like to track the request '" + CGI.escapeHTML(self.info_request.title) + "'?", :list_description => "'" + CGI.escapeHTML(self.info_request.title) + "', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how # Email :title_in_email => "New updates for the request '" + self.info_request.title + "'", :title_in_rss => "New updates for the request '" + self.info_request.title + "'", # Authentication :web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.", :email_subject => "Confirm you want to follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", # Other :feed_sortby => 'described', # for RSS, as newest would give a date for responses possibly days before description } else raise "unknown tracking type " + self.track_type end end return @params end # When constructing a new track, use this to avoid duplicates / double posting def TrackThing.find_by_existing_track(tracking_user_id, track_query) return TrackThing.find(:first, :conditions => [ 'tracking_user_id = ? and track_query = ?', tracking_user_id, track_query ] ) end end