OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / artist.rb
1 class Artist < Peta::Owner
2   load_manifest
3   belongs_to :user
4   has_many :original_pictures
5   has_many :pictures
6   has_many :resource_pictures
7   
8   validates :name, :presence => true, :length => {:maximum => 30}
9   validates :user_id, :numericality => true, :existence => {:both => false}
10   validates :provider_id, :numericality => {:allow_nil => true}
11   
12   def self.visible_count_options
13     {:conditions => ['artists.author_id is not null']}
14   end
15   
16   def supply_default
17     self.name = 'no name' if self.name.blank?
18   end
19   
20   def self.find_by_author author
21     Artist.find( :first, :conditions => ['author_id = ?', author.id])
22   end
23   
24   def self.list_where
25     'artists.provider_id is null'
26   end
27   
28   def self.list_order
29     'artists.created_at desc'
30   end
31   
32   def self.list_opt
33     {:user => {:author => {}} }
34   end
35   
36   def self.list_json_opt
37     {:include => {:user => {:author => {}}} }
38   end
39   
40   def self.show_opt
41     {:include => {:user => {:author => {}}} }
42   end
43   
44   def self.show_json_opt
45     {:include => {:user => {:author => {}}} }
46   end
47   
48   def self.export(dt = nil)
49     opt = {}
50     cond = if dt
51       ['artists.artists.provider = 0 and artists.updated_at >= ?', dt]
52     else
53       'artists.artists.provider = 0'
54     end
55     opt.merge!({:conditions => cond}) 
56     opt.merge!({:order => 'id'})
57     Artist.find(:all, opt)
58   end
59   
60 end