app/models/offerings/offering.rb
# Returns an array of Applications within this Offering that has gone through the specified status name. 
# Note that this is NOT necessarily this application's _current_ status. 
# Does not include applications that have been cancelled, unless you override that by setting +false+ as the
# second parameter.
# By default, this method does not take into consideration
# the sequence of statuses for this offering (so, for instance, if an application gets to "approved" but then later
# gets moved back to "submitted" then this application is no longer "past" the approved status.) You can override this
# by setting +true+ for the third parameter.
Returns an array of Applications within this Offering that has gone through the specified status name.
Note that this is NOT necessarily this application's _current_ status.
Does not include applications that have been cancelled, unless you override that by setting +false+ as the
second parameter.
Returns an array of Applications within this Offering that has gone through the specified status name . Note that this is NOT necessarily this application ' s _current_ status . Does not include applications that have been cancelled unless you override that by setting + false + as the second parameter .
def applications_with_status(status_name, include_cancelled = false, respect_sequence = false)
    apps = []
    if respect_sequence
      offering_status = statuses.find(:first, 
                                      :joins => :application_status_type, 
                                      :conditions => { "application_status_types.name" => status_name.to_s })
      status_sequence_mapping = {}
      for os in statuses.find(:all)
        status_sequence_mapping[os.application_status_type_id] = os.sequence
      end
    end
    app_ids = ApplicationForOffering.find(:all,
      :select => "application_for_offerings.id",
      :joins => { :statuses => :application_status_type },
      :conditions => {  :offering_id => self.id, 
                        "application_status_types.name" => status_name.to_s 
                      }
    ).collect(&:id)
    raw_apps = ApplicationForOffering.find(app_ids.uniq, 
      :select => "application_for_offerings.*",
      :include => [{:current_application_status => :application_status_type }, :person],
      :joins => :person,
      :order => "lastname, firstname"
    )
    for app in raw_apps
      next if !include_cancelled && app.current_status_name == 'cancelled'
      if respect_sequence
        current_status_sequence = status_sequence_mapping[app.current_application_status.application_status_type_id]
        next if current_status_sequence && current_status_sequence < offering_status.try(:sequence)
      end
      apps << app
    end
    apps
  end
def applications_with_status ( status_name , include_cancelled = false , respect_sequence = false ) apps = [ ] if respect_sequence offering_status = statuses . find ( :first , :joins => :application_status_type , :conditions => { "application_status_types.name" => status_name . to_s } ) status_sequence_mapping = { } for os in statuses . find ( :all ) status_sequence_mapping [ os . application_status_type_id ] = os . sequence end end app_ids = ApplicationForOffering . find ( :all , :select => "application_for_offerings.id" , :joins => { :statuses => :application_status_type } , :conditions => { :offering_id => self . id , "application_status_types.name" => status_name . to_s } ) . collect ( & :id ) raw_apps = ApplicationForOffering . find ( app_ids . uniq , :select => "application_for_offerings.*" , :include => [ { :current_application_status => :application_status_type } , :person ] , :joins => :person , :order => "lastname, firstname" ) for app in raw_apps next if ! include_cancelled && app . current_status_name == 'cancelled' if respect_sequence current_status_sequence = status_sequence_mapping [ app . current_application_status . application_status_type_id ] next if current_status_sequence && current_status_sequence < offering_status . try ( :sequence ) end apps << app end apps end
Returns an array of Applications within this Offering that has gone through the specified status name.
Returns an array of Applications within this Offering that has gone through the specified status name .
# apps = [] # raw_apps = application_for_offerings.find(:all,  #                                           :include => [{:current_application_status => :application_status_type },  #                                                        {:application_statuses => :status_type }]) # raw_apps.each do |app| #   app.application_statuses.each do |status| #     if status.status_type.name == status_name.to_s #       apps << app unless !include_cancelled && app.current_status_name == 'cancelled' #     end #   end # end # apps.uniq
status_name
include_cancelled
respect_sequence