class CalendarsController < ApplicationController # GET /events # GET /events.json def index { "extras" => { "page_id" => OrbitHelper.params[:page_id] } } end def events page = Page.find_by(:page_id => params[:page_id]) rescue nil events =[] if !page.nil? categories = page.categories if categories.first == "all" calendar_types = CalendarType.all.collect{|ct| ct.id.to_s } else calendar_types = CalendarType.where(:category_id.in => categories).collect{|ct| ct.id.to_s } rescue [] end if params[:start].present? && params[:end].present? sdt = Time.at(params[:start].to_i) edt = Time.at(params[:end].to_i) events = Event.monthly_event(sdt,edt).where(:calendar_type_id.in => calendar_types) end end respond_to do |format| format.html # index.html.erb format.json { render json: events.to_json } end end def agenda # re = Event.recurring_event(Time.at(params[:unix_start].to_i), Time.at(params[:unix_end].to_i)) # @events = @events.inject(re, :<<) page = Page.find_by(:page_id => params[:page_id]) rescue nil events =[] if !page.nil? categories = page.categories if categories.first == "all" calendar_types = CalendarType.all.collect{|ct| ct.id.to_s } else calendar_types = CalendarType.where(:category_id.in => categories).collect{|ct| ct.id.to_s } rescue [] end if params[:agenda_start].present? && params[:agenda_end].present? agenda_start = Date.strptime(params[:agenda_start], '%m/%d/%Y') agenda_end = Date.strptime(params[:agenda_end], '%m/%d/%Y') events = Event.agenda_events(agenda_start,agenda_end).where(:calendar_type_id.in => calendar_types) end end render json: events.to_json end end