3 self.abstract_class = true
7 def self.play_list_where cid
8 ['scroll_panels.scroll_id = ?', cid]
11 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
12 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
15 def self.play_sheet_where sid
16 ['story_sheets.story_id = ?', sid]
19 def self.play_sheet story, operators, page = 1
20 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
23 Sheet.show(ss.sheet.id, operators)
32 def self.play_paginate story, page
33 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
36 def self.new_t binder_id
37 r = ScrollPanel.max_t(binder_id)
38 r.blank? ? 0 : r.to_i + 1
41 def self.max_t binder_id
42 self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
45 def self.find_t binder_id, t
46 self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
49 def self.collect_t scroll_panel
50 r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
54 def self.top_sheet story, author
55 StorySheet.play_list(story, author).first
58 def self.collect_t story_sheet
59 r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
65 ary.compact.sort.each do |t|
66 break false unless t == i
72 def self.validate_t scroll_panel
73 ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
77 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
80 def lesser_shift old_t
81 self.t = 0 if self.t < 0
82 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
85 def higher_shift old_t
86 nf = ScrollPanel.find_t(self.scroll_id, self.t)
87 max_t = ScrollPanel.max_t(self.scroll_id).to_i
88 self.t = max_t if self.t > max_t
89 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
92 def update_shift old_t
100 def rotate old_t = nil
103 self.t = ScrollPanel.new_t self.scroll_id
110 self.update_shift old_t
116 return nil if self.scroll_id == nil or self.panel_id == nil
117 self.scroll.own?(operators) and self.panel.usable?(operators)
120 def destroy_and_shorten
122 ScrollPanel.transaction do
123 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
124 raise ActiveRecord::Rollback unless self.destroy