OSDN Git Service

fix:server
[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 :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
10   
11   def supply_default
12     self.comic_id = nil
13     self.story_id = nil
14     self.t = nil
15   end
16   
17   def overwrite operators
18     return false unless operators.author
19   end
20   
21   def disp_t
22     self.t + 1
23   end
24   
25   def disp_t_by_text
26     I18n.t('comic_stories.show.t', :t => self.disp_t)
27   end
28   
29   def title
30     self.disp_t_by_text + ':' + self.story.title
31   end
32   
33   def self.public_list_where list
34     'comics.visible > 0'
35   end
36   
37   def self.by_author_list_includes
38     {
39       :comic => {
40         :author => {}
41       }
42     }
43   end
44   
45   def self.show_opt
46     {:include => {
47       :comic => {
48         :author => {}
49       }
50     }}
51   end
52   
53   def allow? operators
54     return nil if self.story_id == nil or self.comic_id == nil
55     self.comic.own?(operators) and self.story.own?(operators)
56   end
57   
58 end