module Tools::Multimedia

Métodos compartidos entre todas las clases que tienen directorio multimedia (Noticia y Debate)

Constants

PHOTOS_SIZES

OLD_PHOTOS_SIZES = {:n85 => “85x85>”, :n120 => “120x120>”, :n320 => “320x320>”, :n700 => “700x700>”, :iphone => “70x70#”, :n189 => “189x142#”, :n95 => “95x64#”, :iframe => “610x344#”} , :n189 => “189x142#”, :n95 => “95x64#”, :iframe => “610x344#”

Attributes

audios[R]
photos[R]
videos[R]

Public Class Methods

included(base) click to toggle source
# File app/models/tools/multimedia.rb, line 24
def self.included(base)
  base.after_save :update_elasticsearch_server
  base.after_destroy :move_multimedia_files_to_trash
end

Public Instance Methods

all_audios(locale = I18n.locale) click to toggle source
# File app/models/tools/multimedia.rb, line 200
def all_audios(locale = I18n.locale)
  lsym = locale.to_sym
  self.audios[lsym] + self.attached_audios[lsym]
end
attached_audios(locale = I18n.locale) click to toggle source

Devuelve la lista de audios para este documento que se han subido como documento adjunto

Ejemplo:

attached_audios[:es]: audios en castellano NOTA: Aunque está definida como atributo, la lista de audios que coge cada vez que se llama a este método. Así ocupa menos memoría.

# File app/models/tools/multimedia.rb, line 185
def attached_audios(locale = I18n.locale)
  attached_audios = {:es => [], :eu => [], :en => [], :all => []}
  
  self.attachments.find(:all, :conditions => "((file_content_type ilike 'audio/%') OR (file_content_type ilike 'application/x-mp3'))", :order => "created_at").each do |at|
    attached_audios.keys.each do |lang|
      attached_audios[lang].push(at) if lang != :all && at.send("show_in_#{lang}?")
    end
  end
  attached_audios[:all] = attached_audios.values.flatten.uniq
  return attached_audios
end
attached_files(lang=I18n.locale) click to toggle source
# File app/models/tools/multimedia.rb, line 205
def attached_files(lang=I18n.locale)
  attached_files = []
  self.attachments.find(:all, :conditions => "((file_content_type not ilike 'audio/%') AND (file_content_type not ilike 'application/x-mp3'))", :order => "created_at").each do |at|
    attached_files.push(at) if at.send("show_in_#{lang}?")
  end
  
  return attached_files
end
dir_for_deleted() click to toggle source

Directorio donde se guardan los adjuntos borrados de este documento

# File app/models/tools/multimedia.rb, line 274
def dir_for_deleted
  dummy, year, month_day_dir = self.multimedia_path.match(/^([^\/]+)\/(.+)$/).to_a
  if year && month_day_dir
    dir_for_deleted = Document::MULTIMEDIA_PATH + year + "/borradas/" + month_day_dir
  else
    dir_for_deleted = Document::MULTIMEDIA_PATH + "/borradas/"
  end
end
full_multimedia_path() click to toggle source

Construye la ruta absoluta al directorio de contenidos multimedia de un documento.

Las News y las Page de la web, tienen contenido multimedia (videos para streaming y para descarga, audios y mini-galería de fotos). Es contenido variable y se produce anterior o posteriormente a la propia noticia, y por personas diferentes a las que pueden crear el contenido de la noticia.

Además, estos contenidos pueden ser muy pesados, por lo que subirlos a la web a través de formularios podría dar problemas de timeouts con algunos proxies.

Por todo ello, este contenido se sube al servidor a través de SFTP y se enlaza con la noticia indicando en multimedia_dir el lugar donde se encuentran los ficheros (ruta relativa al home del usuario SFTP) y full_multimedia_path devuelve la ruta absoluta.

# File app/models/tools/multimedia.rb, line 44
def full_multimedia_path
  "#{Document::MULTIMEDIA_PATH}#{multimedia_path}"
end
has_audios?() click to toggle source

Indica si hay audios para este documento en el idioma actual

# File app/models/tools/multimedia.rb, line 215
def has_audios?
  audios[I18n.locale.to_sym].length + attached_audios[I18n.locale.to_sym].length > 0
end
has_files?() click to toggle source

Indica si este documento tiene documentos adjuntos

# File app/models/tools/multimedia.rb, line 240
def has_files?
  attachments.count > 0
end
has_photos?() click to toggle source

Indica si hay fotos para este documento en el idioma actual

# File app/models/tools/multimedia.rb, line 220
def has_photos?
  photos.length > 0
end
has_professional_videos?() click to toggle source
# File app/models/tools/multimedia.rb, line 133
def has_professional_videos?
  videos[:mpg][I18n.locale.to_sym].length > 0
end
has_video?(locale=I18n.locale.to_sym) click to toggle source

Indica si hay video destacado para este documento y en el idioma actual

# File app/models/tools/multimedia.rb, line 138
def has_video?(locale=I18n.locale.to_sym)
  !featured_video(locale).nil?
end
has_video_with_captions?(locale=I18n.locale) click to toggle source
# File app/models/tools/multimedia.rb, line 142
def has_video_with_captions?(locale=I18n.locale)
  self.webtv_videos.present? && self.webtv_videos.select{|a| a if a.translated_to?(locale) && a.captions_available?}.present?
end
has_videos?() click to toggle source

Indica si hay videos secundarios para este documento y en el idioma actual

# File app/models/tools/multimedia.rb, line 129
def has_videos?
  videos[:list][I18n.locale.to_sym].length > 0 || videos[:mpg][I18n.locale.to_sym].length > 0 
end
videos_flv() click to toggle source
# File app/models/tools/multimedia.rb, line 120
def videos_flv
  self.videos[:list][I18n.locale.to_sym] + [self.featured_video]
end
videos_mpg() click to toggle source
# File app/models/tools/multimedia.rb, line 124
def videos_mpg
  self.videos[:mpg][I18n.locale.to_sym]
end