Skip to content

Instantly share code, notes, and snippets.

@chadb
Created April 24, 2012 12:41
Show Gist options
  • Save chadb/2479303 to your computer and use it in GitHub Desktop.
Save chadb/2479303 to your computer and use it in GitHub Desktop.
pending ids
def self.pending_multi_deployment_ids( user, date = Time.zone.now.to_date )
end_date = date - user.off_cycle_delta
SurveyDeployment.select_ids.active.start_on_lte( date ).end_on_gte( end_date ).group_ids_in( user.group_ids ).multi.type_null.map(&:id)
end
def self.pending_single_deployment_ids( user, date = Time.zone.now.to_date )
end_date = date - user.off_cycle_delta
singles = SurveyDeployment.select_ids.active.single.start_on_lte( date ).end_on_gte( end_date ).group_ids_in( user.group_ids ).type_null
return [] if singles.empty?
taken = SurveyResponse.select_distinct_survey_deployment_ids.survey_deployment_ids_in( singles.map(&:id) ).user_id_is( user.id )
singles.map(&:id) - taken.map(&:survey_deployment_id)
end
def self.pending_evaluation_deployment_ids( user, date = Time.zone.now.to_date )
ids = []
Evaluation.evaluator_group_id_is_any( user.group_ids ).each do |evaluation|
evaluatee_with_max_program_start_date = User.groups_id_is_any( evaluation.evaluatee_group_id ).descend_by_program_start_date.first
if evaluatee_with_max_program_start_date
end_date = date - [user.off_cycle_delta, evaluatee_with_max_program_start_date.off_cycle_delta].max
else
end_date = date - user.off_cycle_delta
end
evaluation.deployments.start_on_lte( date ).end_on_gte( end_date ).active.group_ids_in( user.group_ids ).each do |deployment|
ids << deployment.id if deployment.pending_evaluatees?( user )
end
end
ids
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment