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 scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
49 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
52 def self.play_sheet_where sid
53 ['story_sheets.story_id = ?', sid]
56 def self.play_sheet story, operators, page = 1
57 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
60 Sheet.show(ss.sheet.id, operators)
69 def self.play_paginate story, page
70 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
73 def self.new_t binder_id
74 r = self.max_t(binder_id)
75 r.blank? ? 0 : r.to_i + 1
78 def self.max_t binder_id
79 self.maximum(:t, :conditions => [self.binder_key + ' = ?', binder_id])
82 def self.find_t binder_id, t
83 self.find(:first, :conditions => [self.binder_key + ' = ? and t = ?', binder_id, t])
86 def self.collect_t binder_id
87 r = self.find(:all, :conditions => [self.binder_key + ' = ?', binder_id], :order => 't')
91 def self.top_sheet story, author
92 StorySheet.play_list(story, author).first
97 ary.compact.sort.each do |t|
98 break false unless t == i
101 ary.compact.size == i
104 def self.validate_t binder_id
105 self.serial?(self.collect_t(binder_id))
109 self.class.binder_key
113 self.attributes[self.binder_key]
117 self.class.update_all('t = t + 1',
118 [self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]
122 def lesser_shift old_t
123 self.t = 0 if self.t < 0
124 self.class.update_all('t = t + 1',
125 [self.binder_key + ' = ? and (t >= ? and t < ?)', self.binder_id, self.t, old_t]
129 def higher_shift old_t
130 nf = self.class.find_t(self.binder_id, self.t)
131 max_t = self.class.max_t(self.binder_id).to_i
132 self.t = max_t if self.t > max_t
133 self.class.update_all('t = t - 1',
134 [self.binder_key + ' = ? and (t > ? and t <= ?)', self.binder_id, old_t, self.t]
138 def update_shift old_t
146 def rotate old_t = nil
149 self.t = self.class.new_t self.binder_id
156 self.update_shift old_t
161 def destroy_and_shorten
163 self.class.transaction do
164 self.class.update_all('t = t - 1',
165 [self.binder_key + ' = ? and (t > ?)', self.binder_id, self.t]
167 raise ActiveRecord::Rollback unless self.destroy