- r = {}
- scroll_panels.each do |scroll_panel|
- r.merge!(scroll_panel.panel.licensed_pictures) if scroll_panel.panel
- end
- r
- end
-
- def self.new_t scroll_id
- r = ScrollPanel.max_t(scroll_id)
- r.blank? ? 0 : r.to_i + 1
- end
-
- def self.max_t scroll_id
- ScrollPanel.maximum(:t, :conditions => ['scroll_id = ?', scroll_id])
- end
-
- def self.find_t scroll_id, t
- ScrollPanel.find(:first, :conditions => ['scroll_id = ? and t = ?', scroll_id, t])
- end
-
- def self.collect_t scroll_panel
- r = ScrollPanel.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
- r.map {|sp| sp.t}
- end
-
- def self.serial? ary
- i = 0
- ary.compact.sort.each do |t|
- break false unless t == i
- i += 1
- end
- ary.compact.size == i
- end
-
- def self.validate_t scroll_panel
- ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
- end
-
- def insert_shift
- ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
- end
-
- def lesser_shift old_t
- self.t = 0 if self.t < 0
- ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
- end
-
- def higher_shift old_t
- nf = ScrollPanel.find_t(self.scroll_id, self.t)
- max_t = ScrollPanel.max_t(self.scroll_id).to_i
- self.t = max_t if self.t > max_t
- ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
- end
-
- def update_shift old_t
- if self.t > old_t
- higher_shift old_t
- else
- lesser_shift old_t
- end
- end
-
- def rotate old_t = nil
- if self.new_record?
- if self.t.blank?
- self.t = ScrollPanel.new_t self.scroll_id
- else
- self.insert_shift
- end
- else
- if self.t.blank?
- else
- self.update_shift old_t
- end
- end