Created
July 7, 2009 03:55
-
-
Save kidpollo/141875 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarMonthsController < ApplicationController | |
caches_embedded :mini_calendar, :ttl => 60.minutes | |
def mini_calendar | |
user_id = params[:user_id] | |
@month_offset = params[:month_offset] ? params[:month_offset].to_i : 0 | |
@year = Date.today.year | |
@month = Date.today.to_time.advance(:months => @month_offset).to_date.month | |
start_date = Date.civil(@year,@month,1) | |
end_date = start_date.to_time.advance(:months => 1).to_date | |
@day_class = [] | |
(end_date - start_date).to_i.times do |idx| | |
day = idx+1 | |
#please keep in mind we are using UTC and using first only for now we should go to all cal instances :S | |
day_date = start_date.to_time.advance(:days => day).to_date | |
day_instance = CalendarInstance.find(:first, :conditions => ["? BETWEEN begin_date_time AND end_date_time", day_date]) | |
if day_instance | |
number_of_available_seconds = day_instance.end_date_time - day_instance.begin_date_time | |
logger.info "Aval before: #{number_of_available_seconds}" | |
appointments = Appointment.find(:all, :conditions => ["date_time_starts BETWEEN ? AND ?", day_instance.begin_date_time.to_time, day_instance.begin_date_time.to_time.advance(:seconds => number_of_available_seconds)] ) | |
for appointment in appointments do | |
number_of_available_seconds = number_of_available_seconds - (appointment.date_time_ends - appointment.date_time_starts) | |
logger.info "Aval during: #{number_of_available_seconds}" | |
end | |
logger.info "Aval after: #{number_of_available_seconds}" | |
if number_of_available_seconds > 3600 | |
@day_class[day] = "open" | |
elsif number_of_available_seconds > 1200 | |
@day_class[day] = "oneopen" | |
else | |
@day_class[day] = "full" | |
end | |
else | |
@day_class[day] = "nowork" | |
end | |
end | |
render :layout => false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment