class VLog include Mongoid::Document include Mongoid::Timestamps include OrbitModel::Impression include OrbitTag::Taggable include OrbitCategory::Categorizable include Slug field :create_user_id, type: BSON::ObjectId field :title, as: :slug_title, type: String, localize: true field :subtitle, localize: true field :type field :display_in_profile, type: Boolean, default: false field :youtube_link mount_uploader :image, ImageUploader mount_uploader :video, AssetUploader has_many :v_log_files, :dependent => :destroy, :autosave => true 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" => "
" } else pd_data << { "data_title" => p.send(t) } end end { "pd_datas" => pd_data } end return [pd_title,plugin_datas] end end