OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / story.rb
1 #ストーリー
2 class Story < Peta::Binder
3   load_manifest
4   has_many :comic_stories
5   has_many :story_sheets
6   has_many :sheets, :through => :story_sheets
7   has_many :play_story_sheets, :class_name => 'StorySheet', :order => 't'
8   has_many :play_sheets, :source => 'Sheet', :through => :play_story_sheets
9   belongs_to :author
10   
11   validates :title, :presence => true, :length => {:maximum => 100}
12   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
13   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
14   
15   def supply_default
16     self.visible = 0 if self.visible.blank?
17   end
18   
19   def overwrite operators
20     return false unless operators.author
21     self.author_id = operators.author.id
22     super()
23   end
24   
25   def visible? operators
26     case super
27     when nil # super return
28       return true
29     when false
30       return false
31     else
32       self.visible > 0
33     end
34   end
35   
36   def story_sheets_count
37     StorySheet.where(['story_sheets.story_id = ?', self.id]).count
38   end
39   
40   def self.public_list_where
41     'stories.visible > 0'
42   end
43   
44   def self.list_opt
45     {:comic_stories => {:comic => {}}, :author => {} }
46   end
47   
48   def self.list_json_opt
49     {:include => {:comic_stories => {:include => {:comic => {}}}, :author => {}}}
50   end
51   
52   def self.show_opt
53     {:include => {:comic_stories => {:comic => {}}, :author => {}}}
54   end
55   
56   def self.show_json_opt
57     {:include => {:comic_stories => {:include => {:comic => {}}}, :author => {}}}
58   end
59   
60 end