Class: Absence

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
UserSystem
Defined in:
app/models/absence.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_week(year, week, user = current_user) ⇒ Object

Return an array of either an absence or nil for each day of the given week.



17
18
19
20
21
22
23
24
25
# File 'app/models/absence.rb', line 17

def self.find_by_week(year, week, user = current_user)
  first_date = Date.commercial(year, week, 1)
  last_date = first_date + 6
  results = self.find(:all, :conditions => ['"on" BETWEEN ? AND ? AND user_id = ?', first_date, last_date, user && user.id], :order => '"on"')
  (0..6).each do |day|
    results.insert(day, nil) if results[day] && results[day].on > first_date + day
  end
  results
end

Instance Method Details

#validateObject



10
11
12
13
14
# File 'app/models/absence.rb', line 10

def validate
  if PublicHoliday.exists? :on => on
    errors.add :on, "You cannot mark absence on a public holiday."
  end
end