Class StreamFlow
In: app/models/stream_flow.rb
Parent: ActiveRecord::Base

Salas de streaming.

Cada sale tiene un título y un código que se usa para generar el HTML necesario para emitir en la web.

Methods

Attributes

delete_photo  [R] 

Public Class methods

[Source]

    # File app/models/stream_flow.rb, line 32
32:   def self.programmed
33:     Event.current.with_streaming.map {|evt| evt.stream_flow}.compact.uniq
34:   end

Public Instance methods

Devuelve true si el streaming está anunciado.

[Source]

     # File app/models/stream_flow.rb, line 107
107:   def announced?(subsite)
108:     self.send("announced_in_#{subsite}?") 
109:   end

Asigna evento por defecto a la sala de streaming. Primero mira si hay eventos que empiezan dentro de menos de 1 hora. Si no encuentra, coge el primer evento del día si hay eventos del día. Si la sala ya tiene asignado un evento, este no cambia

[Source]

    # File app/models/stream_flow.rb, line 74
74:   def assign_event!
75:     if self.event.nil? 
76:       if !self.on_web?
77:         evt = self.default_event
78:         self.update_attribute(:event_id, evt.id) if evt
79:       end
80:     else
81:       unless self.event.starts_at.to_date.eql?(Date.today)
82:         self.event = nil
83:         self.save
84:       end
85:     end
86:     self.event
87:   end

Eventos del día asignados a la sala de streaming.

[Source]

    # File app/models/stream_flow.rb, line 50
50:   def day_events
51:     Event.published.with_streaming.find(:all, 
52:                 :conditions => [ "(stream_flow_id = :flow_id) AND (starts_at <= :end) AND (ends_at >= :beginning)", 
53:                                {
54:                                  :flow_id => self.id,
55:                                  :beginning => Time.zone.now.at_beginning_of_day,
56:                                  :end => Time.zone.now.end_of_day
57:                                 }],
58:                 :order => 'starts_at')
59:   end

Devuelve el evento que el sistema considera que corresponde al streaming flow en este momento.

[Source]

    # File app/models/stream_flow.rb, line 67
67:   def default_event
68:     self.next_event || self.day_events.first
69:   end

Accessor para borrar la foto de la sala

[Source]

     # File app/models/stream_flow.rb, line 168
168:   def delete_photo=(value)
169:     self.photo = nil if value.to_i == 1
170:   end

El nombre del fichero con los datos del evento que se emite.

[Source]

     # File app/models/stream_flow.rb, line 186
186:   def event_info_file_name(subsite)
187:     "streamed_event#{self.id}_#{subsite}.txt"
188:   end

[Source]

     # File app/models/stream_flow.rb, line 190
190:   def event_info_file_path(subsite)
191:     File.join(RAILS_ROOT, '/public/streaming_status', self.event_info_file_name(subsite))
192:   end

[Source]

     # File app/models/stream_flow.rb, line 194
194:   def event_info_file_url(subsite)
195:     "/streaming_status/#{self.event_info_file_name(subsite)}"
196:   end

Eventos del día que empiezan dentro de un intervalo de tiempo (en minutos)

[Source]

    # File app/models/stream_flow.rb, line 37
37:   def events_to_be_emitted(time_interval)
38:     evt = Event.published.with_streaming.find(:all, 
39:                 :conditions => [ "(stream_flow_id = :flow_id) AND (starts_at <= :time_int) AND (ends_at >= :now)", 
40:                                {
41:                                  :flow_id => self.id,
42:                                  :time_int => Time.zone.now + time_interval.minutes,
43:                                  :now => Time.zone.now
44:                                 }],
45:                 :order => 'starts_at')
46:     evt
47:   end

Indica si hay foto de la sala.

[Source]

     # File app/models/stream_flow.rb, line 162
162:   def has_photo?
163:     self.photo_file_name.present?
164:   end

Devuelve el evento que toca emitir dentro de 1 hora o menos.

[Source]

    # File app/models/stream_flow.rb, line 62
62:   def next_event
63:     self.events_to_be_emitted(60).to_a.first
64:   end

Devuelve true si el streaming se está emitiendo.

[Source]

     # File app/models/stream_flow.rb, line 102
102:   def on_air?(subsite)
103:     self.send("show_in_#{subsite}?") 
104:   end

Devuelve true si el streaming está anunciado o se está emitiendo en OpenIrekia o Agencia.

[Source]

    # File app/models/stream_flow.rb, line 97
97:   def on_web?
98:     self.show_in_irekia? || self.show_in_agencia? || self.announced_in_irekia? || self.announced_in_agencia?
99:   end

El path que se usa en el image_tag con la foto de la sala de streaming.

[Source]

     # File app/models/stream_flow.rb, line 157
157:   def photo_path
158:     self.has_photo? ?  self.photo.url(:n320) : "/video/streaming.gif"
159:   end

Deluelve las fechas del evento o un string vacío si el streaming no tiene evento asignado

[Source]

     # File app/models/stream_flow.rb, line 120
120:   def pretty_dates(locale = I18n.locale)
121:     self.event.present? ? self.event.pretty_dates : "#{I18n.localize(self.updated_at.to_date, :format => :long, :locale => locale)}, #{self.updated_at.strftime('%H:%M')}"
122:   end

[Source]

     # File app/models/stream_flow.rb, line 124
124:   def start_announcing(where)
125:     if [:irekia, :agencia].include?(where)
126:       self.update_attribute("announced_in_#{where}".to_sym, true)
127:     else
128:       return false
129:     end
130:   end

[Source]

     # File app/models/stream_flow.rb, line 140
140:   def start_streaming(where)
141:     if [:irekia, :agencia].include?(where)
142:       self.update_attribute("show_in_#{where}".to_sym, true)
143:     else
144:       return false
145:     end
146:   end

El nombre del fichero con el status del streaming. Se usa para saber si hay que mostrar el player.

[Source]

     # File app/models/stream_flow.rb, line 173
173:   def status_file_name(subsite)
174:     "streaming#{self.id}_#{subsite}.txt"
175:   end

[Source]

     # File app/models/stream_flow.rb, line 177
177:   def status_file_path(subsite)
178:     File.join(RAILS_ROOT, '/public/streaming_status', self.status_file_name(subsite))
179:   end

[Source]

     # File app/models/stream_flow.rb, line 181
181:   def status_file_url(subsite)
182:     "/streaming_status/#{self.status_file_name(subsite)}"
183:   end

[Source]

     # File app/models/stream_flow.rb, line 132
132:   def stop_announcing(where)
133:     if [:irekia, :agencia].include?(where)
134:       self.update_attribute("announced_in_#{where}".to_sym, false)
135:     else
136:       return false
137:     end
138:   end

[Source]

     # File app/models/stream_flow.rb, line 148
148:   def stop_streaming(where)
149:     if [:irekia, :agencia].include?(where)
150:       self.update_attribute("show_in_#{where}".to_sym, false)
151:     else
152:       return false
153:     end
154:   end

Devuelve el status del stream flow

[Source]

     # File app/models/stream_flow.rb, line 112
112:   def streaming_status(subsite)
113:     status = 'finished'
114:     status = 'announced' if self.announced?(subsite)
115:     status = 'live' if self.on_air?(subsite)
116:     status
117:   end

Indica si el streaming está programado para dentro del tiempo indicado como time_interval (en minutos).

[Source]

    # File app/models/stream_flow.rb, line 92
92:   def to_be_shown?(time_interval=60)
93:     !self.events_to_be_emitted(time_interval).blank?
94:   end

[Validate]