OSDN Git Service

classname rename to module_name
[pettanr/pettanr.git] / app / models / comic_story.rb
1 class ComicStory < Peta::Leaf
2   load_manifest
3   belongs_to :author
4   belongs_to :comic
5   belongs_to :story
6   
7   validates :comic_id, :presence => true, :numericality => true, :existence => {:both => false}
8   validates :story_id, :presence => true, :numericality => true, :existence => {:both => false}
9   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
11   
12   def supply_default
13     self.comic_id = nil
14     self.story_id = nil
15     self.t = nil
16   end
17   
18   def overwrite operators
19     return false unless operators.author
20     self.author_id = operators.author.id
21   end
22   
23   def disp_t
24     self.t + 1
25   end
26   
27   def disp_t_by_text
28     I18n.t('comic_stories.show.t', :t => self.disp_t)
29   end
30   
31   def title
32     self.disp_t_by_text + ':' + self.story.title
33   end
34   
35   def self.public_list_where
36     'comics.visible > 0'
37   end
38   
39   def self.by_author_list_includes
40     {
41       :comic => {
42         :author => {}
43       }
44     }
45   end
46   
47   def self.show_opt
48     {:include => {
49       :comic => {
50         :author => {}
51       }
52     }}
53   end
54   
55   def allow? operators
56     return nil if self.story_id == nil or self.comic_id == nil
57     self.comic.own?(operators) and self.story.own?(operators)
58   end
59   
60 end