Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def get_events
# TODO: remove - this is for testing and benchmarking the two implementations
if false
(conditions ||= []) << "user_id IN (#{params[:employee_ids].split('-').map{|i| i.to_i}.join(',')})" unless params[:employee_ids].blank?
(conditions ||= []) << "client_id IN (#{params[:client_ids].split('-').map{|i| i.to_i}.join(',')})" unless params[:client_ids].blank?
(conditions ||= []) << "group_id IN (#{params[:group_ids].split('-').map{|i| i.to_i}.join(',')})" unless params[:group_ids].blank?
@events = conditions.blank? ? [] : Event.all(:conditions => ["(starts_on >= ? AND ends_on <= ?) AND (#{conditions.join(' OR ')})", Time.at(params[:start].to_i), Time.at(params[:end].to_i)], :include => :group)
render :json => { :events => @events.map {|e| e.attrs_for_json(params[:employee_ids], params[:client_ids]) } }
else
start_time = Time.at(params[:start].to_i); end_time = Time.at(params[:end].to_i);
employee_events = (params[:employee_ids].present? ? Event.between(start_time, end_time, :user_id, params[:employee_ids].split('-')) : [])
client_events = (params[:client_ids].present? ? Event.between(start_time, end_time, :client_id, params[:client_ids].split('-')) : [])
group_events = (params[:group_ids].present? ? Event.between(start_time, end_time, :group_id, params[:group_ids].split('-')) : [])
@events = (employee_events + client_events + group_events).uniq
render :json => { :events => @events.map {|e| e.attrs_for_json(params[:employee_ids], params[:client_ids]) } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.