orbit-basic/vendor/built_in_modules/archive/app/models/archive_file.rb

66 lines
1.3 KiB
Ruby
Raw Normal View History

2012-04-13 07:24:19 +00:00
# encoding: utf-8
class ArchiveFile
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
2012-04-13 07:24:19 +00:00
2012-04-23 07:53:58 +00:00
PAYMENT_TYPES = @site_valid_locales
2012-08-20 09:14:13 +00:00
field :title, localize: true
2012-04-13 07:24:19 +00:00
has_and_belongs_to_many :tags, :class_name => "ArchiveTag"
field :create_user_id
field :update_user_id
field :is_top, :type => Boolean, :default => false
field :is_hot, :type => Boolean, :default => false
field :is_hidden, :type => Boolean, :default => false
2012-08-20 09:14:13 +00:00
scope :can_display,where(is_hidden: false)
2012-04-13 07:24:19 +00:00
belongs_to :archive_file_category
2012-04-13 07:24:19 +00:00
2012-04-23 07:53:58 +00:00
has_many :archive_file_multiples, :autosave => true, :dependent => :destroy
2012-04-23 07:53:58 +00:00
2012-04-23 07:53:58 +00:00
accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true
validates_presence_of :title
after_save :save_archive_file_multiples
2012-04-13 07:24:19 +00:00
def self.search( category_id = nil )
if category_id.to_s.size > 0
2012-04-13 07:24:19 +00:00
2012-04-23 07:53:58 +00:00
find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title )
2012-04-13 07:24:19 +00:00
else
2012-04-23 07:53:58 +00:00
find(:all).desc( :is_top, :title)
2012-04-13 07:24:19 +00:00
end
end
def self.widget_datas
2012-04-13 07:24:19 +00:00
2012-04-23 07:53:58 +00:00
where( :is_hidden => false ).desc(:is_top, :title)
2012-04-13 07:24:19 +00:00
end
def is_top?
self.is_top
end
2012-04-13 07:24:19 +00:00
2012-04-23 07:53:58 +00:00
def save_archive_file_multiples
self.archive_file_multiples.each do |t|
if t.should_destroy
t.destroy
end
2012-04-13 07:24:19 +00:00
end
end
end