diff options
| author | Xinhui | 2017-04-27 12:40:15 +0200 |
|---|---|---|
| committer | Xinhui | 2017-04-27 12:40:24 +0200 |
| commit | ea4e77062126a22ad4032f1fd85f79caedaf4bbf (patch) | |
| tree | 3ae19af41d61d37ee2de4d1c67d754b884fea2e3 /app | |
| parent | 06a8dae926e95ab56405c91746da73ffe2bb282c (diff) | |
| download | chouette-core-ea4e77062126a22ad4032f1fd85f79caedaf4bbf.tar.bz2 | |
Wip TimeTables#update update dates associations
Refs #2899
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/time_table.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index acce96681..0b45341d6 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -40,6 +40,28 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord prefix = human_attribute_name(name).first(2) send("#{name}=", days.include?(prefix)) end + + saved_dates = Hash[self.dates.collect{ |d| [d.id, d.date]}] + cmonth = Date.parse(state['current_periode_range']) + + state['current_month'].each do |d| + date = Date.parse("#{d['mday']}-#{cmonth.strftime("%B-%Y")}") + id = saved_dates.key(date) + next unless id + + time_table_date = self.dates.find(id) + # Destroy removed date + unless d['include_date'] || d['excluded_date'] + next if time_table_date.destroy + end + # Update in_out + in_out = d['include_date'] ? true : false + if in_out != time_table_date.in_out + time_table_date.update_attributes({in_out: in_out}) + end + + end + self.save end |
