X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fartist.rb;h=fa455cd9ff24985d32b3d654d418911a7f7adcf3;hb=84a5b0cfc30cd42930ee80551ba389b223643dc3;hp=63a1f20fcc644775eb8b2c18378bb17b2210ad91;hpb=93b359296a4d2da735cf200bea2476c2dffcee3f;p=pettanr%2Fpettanr.git diff --git a/app/models/artist.rb b/app/models/artist.rb index 63a1f20f..fa455cd9 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -1,105 +1,60 @@ -class Artist < ActiveRecord::Base - belongs_to :author +class Artist < Peta::Owner + load_manifest + belongs_to :user has_many :original_pictures has_many :pictures has_many :resource_pictures validates :name, :presence => true, :length => {:maximum => 30} - validates :author_id, :numericality => {:allow_blank => true} + validates :user_id, :numericality => true, :existence => {:both => false} + validates :provider_id, :numericality => {:allow_nil => true} - def supply_default - self.name = 'no name' if self.name.blank? - end - - def overwrite au - return false unless au - self.author_id = au.id + def self.visible_count_options + {:conditions => ['artists.author_id is not null']} end - def own? author - return false unless author - self.author_id == author.id - end - - def visible? author - true + def supply_default + self.name = 'no name' if self.name.blank? end def self.find_by_author author Artist.find( :first, :conditions => ['author_id = ?', author.id]) end - def self.default_page_size - 25 - end - - def self.max_page_size - 100 - end - - def self.page prm = nil - page = prm.to_i - page = 1 if page < 1 - page - end - - def self.page_size prm = self.default_page_size - page_size = prm.to_i - page_size = self.max_page_size if page_size > self.max_page_size - page_size = self.default_page_size if page_size < 1 - page_size + def self.list_where + 'artists.provider_id is null' end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list page = 1, page_size = self.default_page_size - opt = {} - opt.merge!(Artist.list_opt) - opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 - opt.merge!({:order => 'created_at desc'}) - Artist.find(:all, opt) + def self.list_order + 'artists.created_at desc' end def self.list_opt - {:include => {:author => {}, :original_pictures => {}, :pictures => {}, :resource_pictures => {}} } + {:user => {:author => {}} } end def self.list_json_opt - {:include => {:author => {}, :original_pictures => {}, :pictures => {}, :resource_pictures => {}} } - end - - def self.show aid, au - opt = {} - opt.merge!(Artist.show_opt) - res = Artist.find(aid, opt) - raise ActiveRecord::Forbidden unless res.visible?(au) - res - end - - def self.edit sid, au - opt = {} - opt.merge!(Artist.show_opt) - res = Artist.find sid, opt - raise ActiveRecord::Forbidden unless res.own?(au) - res + {:include => {:user => {:author => {}}} } end def self.show_opt - {:include => {:author => {}, :original_pictures => {}, :pictures => {}, :resource_pictures => {}} } + {:include => {:user => {:author => {}}} } end def self.show_json_opt - {:include => {:author => {}, :original_pictures => {}, :pictures => {}, :resource_pictures => {}} } + {:include => {:user => {:author => {}}} } end - def self.visible_count - Artist.count + def self.export(dt = nil) + opt = {} + cond = if dt + ['artists.artists.provider = 0 and artists.updated_at >= ?', dt] + else + 'artists.artists.provider = 0' + end + opt.merge!({:conditions => cond}) + opt.merge!({:order => 'id'}) + Artist.find(:all, opt) end end