Module | Tools::Calendar::ClassMethods
In: | app/models/tools/calendar.rb

### Methods

month_events month_events_by_day month_events_by_day4cal

### Public Instance methods

month_events(month, year)

Devuelve la lista de eventos del mes y año indicados.

[Source]

        # File app/models/tools/calendar.rb, line 90
    90:     def month_events(month, year)
    91:       start_day = Time.parse("#{month}/01/#{year}")
    92:       end_day = start_day.end_of_month
    93:       # self.find(:all, :conditions => ['starts_at >= ? AND starts_at <= ?', start_day, end_day],
    94:       #                 :order => "starts_at")
    95:       self.find(:all, :conditions => ['starts_at <= :end_day AND (ends_at >= :start_day)', {:start_day => start_day, :end_day => end_day}],
    96:                       :order => "starts_at")
    97:
    98:     end

month_events_by_day(month, year)

Devuelve una lista con los eventos para cada día del mes y año indicados. Para los eventos que abarcan más de un día hay una entrada para cada día del evento.

[Source]

         # File app/models/tools/calendar.rb, line 102
    102:     def month_events_by_day(month, year)
    103:       events = self.month_events(month, year)
    104:       events4day = events.group_by  {|e| e.first_day(month, year)}
    105:       events.each do |evt|
    106:         if !evt.one_day?
    107:           evt.days(month, year).each do |day|
    108:             events4day[day] = [] if events4day[day].blank?
    109:             events4day[day].push(evt) unless events4day[day].include?(evt)
    110:           end
    111:         end
    112:       end
    113:
    114:       events4day
    115:     end

month_events_by_day4cal(month, year)

Prepara la lista de eventos del mes y año indicadas para usarla en el calendario del mes.

[Source]

         # File app/models/tools/calendar.rb, line 118
    118:     def month_events_by_day4cal(month, year)
    119:       events = {}
    120:
    121:       first_day = Date.civil(year, month, 1)
    122:       last_day = Date.civil(year, month, -1)
    123:
    124:       self.find(:all, :conditions => [ "(starts_at <= :end_of_day) and (ends_at >= :beginning_of_day)",
    125:                                        {:beginning_of_day => (first_day-6.days).beginning_of_day,
    126:                                         :end_of_day => (last_day + 6.days).end_of_day}],
    127:                        :order => "starts_at").each do |evt|
    128:          if evt.one_day?
    129:            events[evt.month] = {} if events[evt.month].blank?
    130:            events[evt.month][evt.day] = [] if events[evt.month][evt.day].blank?
    131:            events[evt.month][evt.day].push(evt) unless events[evt.month][evt.day].include?(evt)
    132:          else
    133:            logger.debug ".......................... more than one day event #{evt.pretty_dates}"
    134:
    135:            if (evt.starts_at.month > evt.ends_at.month)
    136:              if (month >= evt.starts_at.month)
    137:                prev_year = year
    138:                next_year= year + 1
    139:              else
    140:                prev_year = year - 1
    141:                next_year = year
    142:              end
    143:              (evt.starts_at.month .. 12).each do |m|
    144:                events[m] = {} if events[m].blank?
    145:                evt.days(m, prev_year).each do |day|
    146:                  events[m][day] = [] if events[m][day].blank?
    147:                  events[m][day].push(evt) unless events[m][day].include?(evt)
    148:                end
    149:              end
    150:               start_month = 1
    151:            else
    152:              prev_year = year - 1
    153:              next_year= year
    154:              start_month = evt.starts_at.month
    155:            end
    156:
    157:            (start_month .. evt.ends_at.month).each do |m|
    158:              events[m] = {} if events[m].blank?
    159:              evt.days(m, next_year).each do |day|
    160:                events[m][day] = [] if events[m][day].blank?
    161:                events[m][day].push(evt) unless events[m][day].include?(evt)
    162:              end
    163:            end
    164:
    165:          end
    166:          # logger.debug ".............. events months: #{events.keys.join(",")}"
    167:          # logger.debug "............. by now for month #{month}"
    168:          # if events[month]
    169:          #   events[month].each do |day, evts|
    170:          #     logger.debug "day: #{day}"
    171:          #     logger.debug "eventos: #{evts.map {|e| e.pretty_dates}.join('\n')}"
    172:          #   end
    173:          # end
    174:       end
    175:
    176:       events
    177:     end

[Validate]