2015-12-26 14:02:01 +00:00
|
|
|
class VLog
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
include OrbitModel::Impression
|
|
|
|
|
2015-12-26 18:22:26 +00:00
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitCategory::Categorizable
|
|
|
|
include Slug
|
2015-12-26 14:02:01 +00:00
|
|
|
|
|
|
|
field :create_user_id, type: BSON::ObjectId
|
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
2015-12-26 18:22:26 +00:00
|
|
|
field :subtitle, localize: true
|
|
|
|
field :type
|
|
|
|
field :display_in_profile, type: Boolean, default: false
|
|
|
|
field :youtube_link
|
2015-12-26 14:02:01 +00:00
|
|
|
|
|
|
|
mount_uploader :image, ImageUploader
|
|
|
|
|
|
|
|
has_many :v_log_files, :dependent => :destroy, :autosave => true
|
2015-12-26 18:22:26 +00:00
|
|
|
has_one :v_log_video, :dependent => :destroy, :autosave => true
|
2015-12-26 14:02:01 +00:00
|
|
|
|
|
|
|
accepts_nested_attributes_for :v_log_files, :allow_destroy => true
|
|
|
|
|
|
|
|
# scope :sort_for_frontend, ->{ order_by(:created_at => "desc") }
|
|
|
|
|
|
|
|
def thumbnail
|
|
|
|
self.image.url.nil? || self.image.url == "" ? "/assets/vlog/video-thumbnail.png" : self.image.thumb.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def youtube_thumbnail
|
|
|
|
thumb = ""
|
|
|
|
if !self.youtube_link.nil?
|
|
|
|
id = self.youtube_link.split("/").last
|
|
|
|
thumb = "http://img.youtube.com/vi/#{id}/0.jpg"
|
|
|
|
end
|
|
|
|
return thumb
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_plugin_datas_to_member(datas)
|
|
|
|
|
|
|
|
fields_to_show = [
|
|
|
|
"thumbnail",
|
|
|
|
"title"
|
|
|
|
]
|
|
|
|
|
|
|
|
pd_title = fields_to_show.collect do |t|
|
|
|
|
{
|
|
|
|
"plugin_data_title" => I18n.t("vlog.#{t}")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
plugin_datas = datas.order_by(:created_at => "desc").collect do |p|
|
|
|
|
|
|
|
|
pd_data = []
|
|
|
|
fields_to_show.collect do |t|
|
|
|
|
if t == "thumbnail"
|
|
|
|
thumbnail = (p.type == "youtube" ? p.youtube_thumbnail : p.thumbnail)
|
|
|
|
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,"vlog")}'><div class='video-thumbnail'><img src='#{thumbnail}' /><div class='video-thumbnail-overlay'></div><i class='icons-play'></i></div></a>" }
|
|
|
|
else
|
|
|
|
pd_data << { "data_title" => p.send(t) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"pd_datas" => pd_data
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return [pd_title,plugin_datas]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|