3 self.abstract_class = true
9 return nil if self._skip_load?
11 pm = Manifest.manifest.models[self.my_peta.parent_model_name].classify
12 define_singleton_method("parent_model") do
15 pfk = self.my_peta.parent_model_name + '_id'
16 define_singleton_method("binder_key") do
31 self.__send__ self.class.root_model.item_name
35 self.root.own? operators
38 # super return if my item
39 def visible? operators
40 return false if super == false
41 self.root.visible? operators
44 def self.play_list_where cid
45 ['scroll_panels.scroll_id = ?', cid]
48 def self.play_list_order
52 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
53 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
56 def self.play_sheet_where sid
57 ['story_sheets.story_id = ?', sid]
60 def self.play_sheet story, operators, page = 1
61 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
64 Sheet.show(ss.sheet.id, operators)
73 def self.play_paginate story, page
74 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
77 def self.new_t binder_id
78 r = self.max_t(binder_id)
79 r.blank? ? 0 : r.to_i + 1
82 def self.max_t binder_id
83 self.maximum(:t, :conditions => [self.binder_key + ' = ?', binder_id])
86 def self.find_t binder_id, t
87 self.find(:first, :conditions => [self.binder_key + ' = ? and t = ?', binder_id, t])
90 def self.collect_t binder_id
91 r = self.find(:all, :conditions => [self.binder_key + ' = ?', binder_id], :order => 't')
95 def self.top_sheet story, author
96 StorySheet.play_list(story, author).first
101 ary.compact.sort.each do |t|
102 break false unless t == i
105 ary.compact.size == i
108 def self.validate_t binder_id
109 self.serial?(self.collect_t(binder_id))
113 self.class.binder_key
117 self.attributes[self.binder_key]
121 self.class.update_all('t = t + 1',
122 [self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]
126 def lesser_shift old_t
127 self.t = 0 if self.t < 0
128 self.class.update_all('t = t + 1',
129 [self.binder_key + ' = ? and (t >= ? and t < ?)', self.binder_id, self.t, old_t]
133 def higher_shift old_t
134 nf = self.class.find_t(self.binder_id, self.t)
135 max_t = self.class.max_t(self.binder_id).to_i
136 self.t = max_t if self.t > max_t
137 self.class.update_all('t = t - 1',
138 [self.binder_key + ' = ? and (t > ? and t <= ?)', self.binder_id, old_t, self.t]
142 def update_shift old_t
150 def rotate old_t = nil
153 self.t = self.class.new_t self.binder_id
160 self.update_shift old_t
165 def destroy_and_shorten
167 self.class.transaction do
168 self.class.update_all('t = t - 1',
169 [self.binder_key + ' = ? and (t > ?)', self.binder_id, self.t]
171 raise ActiveRecord::Rollback unless self.destroy