56 lines
1.8 KiB
Ruby
56 lines
1.8 KiB
Ruby
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[:unix_start].present? && params[:unix_end].present?
|
|
agenda_start = Time.at(params[:unix_start].to_i).to_s
|
|
agenda_end = Time.at(params[:unix_end].to_i).to_s
|
|
events = Event.agenda_events(agenda_start,agenda_end).where(:calendar_type_id.in => calendar_types)
|
|
end
|
|
end
|
|
render json: events.to_json
|
|
end
|
|
end |