OSDN Git Service

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