| Class | VideosController |
| In: |
app/controllers/videos_controller.rb
|
| Parent: | ApplicationController |
Nuevo diseño de la página de un canal
# File app/controllers/videos_controller.rb, line 18
18: def cat
19: @web_tv = WebTv.new
20:
21: if params[:id]
22: if Category.exists?(params[:id].to_i)
23: @channel = Category.find(params[:id])
24: else
25: if @dept = Department.find_by_label(params[:id])
26: @channel = @web_tv.department_channel(@dept)
27: end
28: end
29: end
30:
31: if @channel
32: @title = t('videos.web_tv')+": #{@channel.name}"
33: finder = @channel.videos
34: else
35: if params[:id].eql?('depts')
36: @title = t('videos.web_tv')+": #{t('shared.TodosDepts')}"
37: finder = Video.published.translated.tagged_with(Department.tag_names)
38: else
39: flash[:notice] = t('videos.no_hay') if params[:id].present?
40: redirect_to videos_path and return
41: end
42: end
43:
44: @videos = finder.paginate(:per_page => 12, :order => "published_at DESC, matching_tag_counter DESC", :page => params[:page] || 1)
45: end
Videos dentro de una categoría (departamento) OBSOLETO
# File app/controllers/videos_controller.rb, line 180
180: def cat_old
181: @category = Category.find(params[:id])
182:
183: private_tags = @category.tags.private.collect {|t| t.name_es}
184: all_videos = private_tags.length > 0 ? Video.published.translated.paginate_by_tag(private_tags, :per_page => 10, :order => "matching_tag_counter DESC, published_at DESC", :page => params[:p]) : []
185:
186: if all_videos.length == 0
187: flash[:notice] = t('videos.no_hay')
188: redirect_to videos_path and return
189: end
190:
191: @total_n_videos = ((all_videos.total_pages - 1) * 10) + 5
192:
193: @vid = all_videos.sort {|a, b| b.published_at <=> a.published_at}.first
194: @parent = @vid
195:
196: @comments = @vid.comments.approved.paginate :page => params[:page], :per_page => 50
197:
198: @p = params[:p] ? params[:p].to_i : 1
199: if @p == 1
200: @videos = all_videos - [@vid]
201: @title_for_head = @category.name
202: render :action => "show"
203: else
204: @title_for_head = "#{@category.name} :: #{t('videos.relacionados')}"
205: @videos = all_videos
206: render :action => "list"
207: end
208:
209: end
Nuevo diseño de la página de inicio
# File app/controllers/videos_controller.rb, line 6
6: def index
7: @web_tv = WebTv.new
8:
9: @title = t('videos.web_tv')
10: @featured_video = Video.featured
11: @videos = Video.published.translated.find :all,
12: :conditions => @featured_video ? ["id!=?", @featured_video.id]: nil,
13: :limit => 10,
14: :order => "published_at DESC"
15: end
Listado de videos OBSOLETO
# File app/controllers/videos_controller.rb, line 93
93: def index_old
94: @title_for_head = t('videos.web_tv')
95:
96: @videos = Video.published.translated.paginate :page => params[:p], :per_page => 10, :order => "published_at DESC"
97: @total_n_videos = Video.published.translated.count
98:
99: @parent = @videos.first
100: @comments = @parent.comments.approved.paginate :page => params[:page], :per_page => 50 if @parent
101:
102: # Pagination de los videos
103: @p = params[:p] ? params[:p].to_i : 1
104:
105: respond_to do |format|
106: format.html {
107:
108: if @p == 1
109: private_tags = @parent.tags.private.collect {|t| t.name_es}
110: render :action => "index.html", :content_type => 'text/html'
111: else
112: render :action => "list"
113: end
114: }
115: format.xml {
116: headers["Status"] = "301 Moved Permanently"
117: redirect_to podcast_path(:format => :xml) and return
118: }
119: end
120: end
# File app/controllers/videos_controller.rb, line 123
123: def podcast
124: @videos = Video.published.translated.find :all, :limit => 100, :order => "published_at DESC"
125: # respond_to do |format|
126: # format.any(:html, :xml) {logger.info "ZZZZZZZZZZZ";render :action => "podcast.xml", :layout => false, :content_type => 'application/xml'}
127: # end
128:
129: render :action => "podcast.xml", :layout => false, :content_type => 'application/xml'
130: end
Página de un video
# File app/controllers/videos_controller.rb, line 48
48: def show
49: @web_tv = WebTv.new
50:
51: begin
52: @video = Video.published.find(params[:id])
53: rescue ActiveRecord::RecordNotFound
54: if can_edit?("videos")
55: @video = Video.find(params[:id])
56: else
57: raise ActiveRecord::RecordNotFound
58: end
59: end
60:
61:
62: @page_title_for_head = @video.title
63: @title = t('videos.web_tv')
64:
65: @channel = Category.exists?(params[:category_id].to_i) ? Category.find(params[:category_id]) : @video.channels.first
66:
67: if @channel
68: # Comprobar que la categoria y el documento estan relacionados
69: if @video.tags.private.collect(&:name_es) & @channel.tags.private.collect(&:name_es) == []
70: logger.info "Categoria y video no relacionados"
71: raise ActiveRecord::RecordNotFound
72: end
73: @title += ": #{@channel.name}"
74: end
75:
76: # Comments
77: @parent = @video
78: @comments = @video.comments.approved.paginate :page => params[:page], :per_page => 50
79:
80: # # Same channel videos
81: # private_tags = @video.tags.private.collect {|t| t.name_es}
82: #
83: # if private_tags.length > 0
84: # @related_videos = Video.published.translated.tagged_with(private_tags).recent.find(:all, :conditions => "videos.id <> #{@video.id}")
85: # end
86:
87: @related_videos = (Video.published.translated.find_tagged_with(@video.tag_list, :order => "matching_tag_counter DESC, published_at DESC ") - [@video])[0..10]
88:
89: end
Vista de un video OBSOLETO
# File app/controllers/videos_controller.rb, line 134
134: def show_old
135: @vid = Video.published.find(params[:id])
136: @video = @vid
137: @parent = @video
138: @title_for_head = @video.title
139:
140: if @category
141: # Comprobar que la categoria y el documento estan relacionados
142: if @video.tags.private.collect(&:name_es) & @category.tags.private.collect(&:name_es) == []
143: logger.info "Categoria y video no relacionados"
144: raise ActiveRecord::RecordNotFound
145: end
146: end
147:
148: # Comments
149: @comments = @video.comments.approved.paginate :page => params[:page], :per_page => 50
150:
151: # @same_tag_videos = Video.published.find_tagged_with(@video.tag_list,
152: # :scope => :private,
153: # :order => "matching_tag_counter DESC, published_at DESC", :limit => limit) - [@video]
154:
155: # Same channel videos
156: private_tags = @video.tags.private.collect {|t| t.name_es}
157:
158: if private_tags.length > 0
159: @videos = Video.published.paginate_by_tag(private_tags,
160: :order => "matching_tag_counter DESC, published_at DESC",
161: :conditions => "videos.id <> #{@vid.id}",
162: :per_page => 10, :page => params[:p])
163:
164: @total_n_videos = ((@videos.total_pages - 1) * 10) + 5
165: end
166:
167: @p = params[:p] ? params[:p].to_i : 1
168: if @p == 1
169: @title_for_head = @video.title
170: render :action => "show"
171: else
172: @title_for_head = "#{@video.title} :: #{t('videos.relacionados')}"
173: render :action => "list"
174: end
175:
176: end