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-04-13 07:24:19 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
|
|
|
PAYMENT_TYPES = @site_valid_locales
|
|
|
|
|
|
|
|
>>>>>>> archive checkbox
|
2012-04-23 07:53:58 +00:00
|
|
|
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
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
|
|
|
|
|
|
|
|
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
|