OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / comic.rb
1 #コミック
2 class Comic < Peta::Binder
3   load_manifest
4   has_many :comic_stories
5   belongs_to :author
6   
7   validates :title, :presence => true, :length => {:maximum => 100}
8   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
9   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10   
11   def self.visible_count_options
12     {:conditions => 'visible > 0'}
13   end
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   end
23   
24   def visible? operators
25     case super
26     when nil # super return
27       return true
28     when false
29       return false
30     else
31       self.visible > 0
32     end
33   end
34   
35   def symbol_filename
36   end
37   
38   def self.public_list_where
39     'comics.visible > 0'
40   end
41   
42   def self.list_order
43     'comics.updated_at desc'
44   end
45   
46   def self.list_opt
47     {:comic_stories => {:story => {}}, :author => {} }
48   end
49   
50   def self.list_json_opt
51     {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
52   end
53   
54   def self.show_opt
55     {:include => {:comic_stories => {:story => {}}, :author => {}}}
56   end
57   
58   def self.show_json_opt
59     {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
60   end
61   
62   def tag_attributes column = nil, opt = {}
63     {
64     }
65   end
66   
67   def scenario
68     panels.map {|panel|
69       panel.scenario
70     }.join
71   end
72   
73   def plain_scenario
74     panels.map {|panel|
75       panel.plain_scenario
76     }.join
77   end
78   
79 end