-class ScrollPanel < ActiveRecord::Base
+class ScrollPanel < Peta::Element
+ load_manifest
belongs_to :author
belongs_to :panel
belongs_to :scroll
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ def tag_attributes column = nil, opt = {}
+ {
+ }
+ end
+
def supply_default
self.scroll_id = nil
self.panel_id = nil
self.t = nil
end
- def overwrite au
- return false unless au
- self.author_id = au.id
+ def overwrite operators
+ return false unless operators.author
+ self.author_id = operators.author.id
end
- def own? roles
- roles = [roles] unless roles.respond_to?(:each)
- au = ScrollPanel.get_author_from_roles roles
- return false unless au
- self.author_id == au.id
- end
-
- def visible? roles
- if MagicNumber['run_mode'] == 0
- return false unless guest_role_check(roles)
- else
- return false unless reader_role_check(roles)
- end
- return true if self.scroll.own?(roles)
- self.scroll.visible? roles
- end
-
- def self.default_panel_size
- 30
- end
-
- def self.max_panel_size
- 200
- end
-
- def self.offset cnt, prm = nil
- offset = prm.to_i
- offset = cnt - 1 if offset >= cnt
- offset = cnt - offset.abs if offset < 0
- offset = 0 if offset < 0
- offset
- end
-
- def self.panel_count cnt, prm = self.default_panel_size
- count = prm.to_i
- count = self.max_panel_size if count > self.max_panel_size
- count = self.default_panel_size if count < 1
- count
- end
-
- def self.default_page_size
- 25
- end
-
- def self.max_page_size
- 100
- end
-
- def self.page prm = nil
- page = prm.to_i
- page = 1 if page < 1
- page
- end
-
- def self.page_size prm = self.default_page_size
- page_size = prm.to_i
- page_size = self.max_page_size if page_size > self.max_page_size
- page_size = self.default_page_size if page_size < 1
- page_size
- end
-
- def self.play_list_where cid
- ['scroll_panels.scroll_id = ?', cid]
+ def visible? operators
+ return false unless super
+ self.owner_model.visible? operators
end
def self.list_order
'scrolls.visible > 0'
end
- def self.mylist_where au
- ['scroll_panels.author_id = ?', au.id]
- end
-
- def self.himlist_where au
- ['scroll_panels.author_id = ? and scrolls.visible > 0', au.id]
+ def self.play_list_where cid
+ ['scroll_panels.scroll_id = ?', cid]
end
def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
end
- def self.list page = 1, page_size = self.default_page_size
- ScrollPanel.where(self.list_where()).includes(ScrollPanel.list_opt).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
- def self.mylist au, page = 1, page_size = Author.default_scroll_panel_page_size
- ScrollPanel.where(self.mylist_where(au)).includes(ScrollPanel.list_opt).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
- def self.himlist au, page = 1, page_size = Author.default_scroll_panel_page_size
- ScrollPanel.where(self.himlist_where(au)).includes(ScrollPanel.list_opt).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
- def self.list_paginate page = 1, page_size = self.default_page_size
- Kaminari.paginate_array(Array.new(ScrollPanel.where(self.list_where()).includes(ScrollPanel.list_opt).count, nil)).page(page).per(page_size)
- end
-
- def self.mylist_paginate au, page = 1, page_size = Author.default_scroll_panel_page_size
- Kaminari.paginate_array(Array.new(ScrollPanel.where(self.mylist_where(au)).includes(ScrollPanel.list_opt).count, nil)).page(page).per(page_size)
- end
-
- def self.himlist_paginate au, page = 1, page_size = Author.default_scroll_panel_page_size
- Kaminari.paginate_array(Array.new(ScrollPanel.where(self.himlist_where(au)).includes(ScrollPanel.list_opt).count, nil)).page(page).per(page_size)
- end
-
- def self.list_by_scroll_where scroll_id
- ['scroll_panels.scroll_id = ?', scroll_id]
- end
-
- def self.list_by_scroll scroll_id, roles, page = 1, page_size = self.default_page_size
- self.where(self.list_by_scroll_where(scroll_id)).includes(self.list_opt).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
- def self.list_by_panel_where panel_id
- ['scroll_panels.panel_id = ?', panel_id]
- end
-
- def self.list_by_panel panel_id, roles, page = 1, page_size = self.default_page_size
- self.where(self.list_by_panel_where(panel_id)).includes(self.list_opt).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
def self.list_opt
{
:author => {},
}}
end
- def self.show spid, roles
- opt = {}
- opt.merge!(ScrollPanel.show_opt)
- res = ScrollPanel.find spid, opt
- raise ActiveRecord::Forbidden unless res.visible?(roles)
- res
- end
-
- def self.edit spid, au
- opt = {}
- opt.merge!(ScrollPanel.show_opt)
- res = ScrollPanel.find spid, opt
- raise ActiveRecord::Forbidden unless res.own?(au)
- res
- end
-
def self.show_opt
{:include => {
:author => {},
end
end
- def allow?
+ def allow? operators
return nil if self.scroll_id == nil or self.panel_id == nil
- self.scroll.own?(self.author) and self.panel.usable?(self.author)
+ self.scroll.own?(operators) and self.panel.usable?(operators)
end
- def store old_t = nil
+ def store operators, old_t = nil
res = false
ScrollPanel.transaction do
- case self.allow?
+ case self.allow? operators
when true
self.rotate old_t
when false