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

82 lines
1.6 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
include Mongoid::Sortable
include Sunspot::Mongo
include OrbitCategory::Categorizable
include OrbitModel::LanguageRestrict
include OrbitModel::Status
include OrbitModel::TimeFrame
include OrbitTag::Taggable
# BelongsToCategory = :archive_file_category
2012-04-13 07:24:19 +00:00
# PAYMENT_TYPES = @site_valid_locales
2012-08-20 09:14:13 +00:00
2013-04-26 03:18:57 +00:00
2012-08-20 09:14:13 +00:00
field :title, localize: true
2012-04-13 07:24:19 +00:00
field :create_user_id
field :update_user_id, :class_name => "User"
2013-11-05 03:23:37 +00:00
scope :can_display,where(is_hidden: false)
2013-03-07 09:59:53 +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 :title, :at_least_one => true
2012-04-23 07:53:58 +00:00
after_save :save_archive_file_multiples
2012-04-13 07:24:19 +00:00
2013-06-05 10:03:09 +00:00
# searchable do
# text :titles do
# title_translations.to_a.collect{|t| t[1]}
# end
2013-06-05 10:03:09 +00:00
# boolean :frontend_search do
# !is_hidden
# end
# end
2013-06-05 10:03:09 +00:00
2012-04-13 07:24:19 +00:00
def self.search( category_id = nil )
2012-04-13 07:24:19 +00:00
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
2012-04-13 07:24:19 +00:00
end
def self.widget_datas
2012-04-13 07:24:19 +00:00
2013-03-07 09:59:53 +00:00
where( :is_hidden => false ).desc(:is_top, :title)
2012-04-13 07:24:19 +00:00
end
2013-03-07 09:59:53 +00:00
def get_file_icon( file_data )
2013-03-21 06:38:04 +00:00
file_icon = "<span class=\"o-archives-file-type\">#{file_data.split('.')[-1]}</span>".html_safe
2013-03-07 09:59:53 +00:00
end
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