| Class | Ma::NewsController |
| In: |
app/controllers/ma/news_controller.rb
|
| Parent: | Ma::BaseController |
Controlador para las noticias de la Agencia Multimedia Sólo para el "staff" y los periodistas
Archivo de noticias antiguas
# File app/controllers/ma/news_controller.rb, line 70
70: def archive
71: @title = t('documents.News_archive')
72: @news = News.in_agencia.published.translated.paginate :page => params[:page], :per_page => 50,
73: :include => [:organization => :icon],
74: :order => 'published_at DESC'
75: end
Feed RSS común con las noticias de todos los departamentos
# File app/controllers/ma/news_controller.rb, line 78
78: def feed
79: if params[:u] && params[:p]
80: user = Journalist.authenticate_from_url(params[:u], params[:p])
81: end
82:
83: if user
84: @title = t('documents.News')
85: @news = News.in_agencia.published.translated.find :all, :limit => 10,
86: :order => 'published_at DESC'
87:
88: respond_to do |format|
89: format.html
90: format.rss {render :action => "myfeed", :layout => false}
91: end
92: else
93: flash[:notice] = t('site.info_acceso_agencia')
94: ma_access_denied
95: end
96: end
Página home de la Agencia Multimedia
# File app/controllers/ma/news_controller.rb, line 9
9: def home
10: @title_for_head = t('documents.News')
11: flash.delete(:notice)
12:
13: @news = News.published.in_agencia.translated.leading.find :all, :include => [:organization => :icon],
14: :conditions => "organization_id in (#{@organization_ids.join(',')})",
15: :order => 'published_at DESC', :limit => 15
16:
17:
18: # Se cogen los eventos del día y de los tres días siguientes.
19: @today_events = Event.in_agencia.published.translated.current.find(:all, :conditions => "organization_id in (#{@organization_ids.join(',')})")
20: @future_events = Event.in_agencia.published.translated.future.find(:all, :conditions => ["organization_id in (#{@organization_ids.join(',')}) AND starts_at <= ?", Time.zone.now + Event::AM_INTERVAL]) - @today_events
21:
22: @events = (@today_events + @future_events[0..3]).uniq.map {|e| e if e.between?(Time.zone.now.at_beginning_of_day.to_date, (Time.zone.now.at_beginning_of_day + Event::AM_INTERVAL).to_date )}.compact
23:
24: # @streaming = StreamFlow.find_by_show_in_agencia(true)
25: # @announced_streaming = StreamFlow.find_by_announced_in_agencia(true)
26: @streaming = StreamFlow.find(:first, :conditions => {:show_in_agencia => true}, :order => 'updated_at')
27: @announced_streaming = StreamFlow.find(:first, :conditions => {:announced_in_agencia => true}, :order => 'updated_at')
28: end
Listado de noticias
# File app/controllers/ma/news_controller.rb, line 55
55: def index
56: @title = t('documents.News')
57: @news = News.in_agencia.translated.published.paginate :page => params[:page], :per_page => 15,
58: :include => [:organization => :icon],
59: :order => 'published_at DESC'
60:
61: @category = Category.find(params[:category_id]) if params[:category_id]
62:
63: respond_to do |format|
64: format.html
65: format.rss {render :layout => false}
66: end
67: end
Feed RSS personal de las noticias de un periodista. Cada periodista recibe sólo las noticias de los departamentos a los que está suscrito.
# File app/controllers/ma/news_controller.rb, line 32
32: def myfeed
33: if params[:u] && params[:p]
34: user = Journalist.authenticate_from_url(params[:u], params[:p])
35: end
36:
37: if user
38: #department_ids = user.department_ids.length > 0 ? user.department_ids : [0]
39: organization_ids = user.organization_ids.length > 0 ? user.organization_ids : [0]
40: @news = News.in_agencia.published.translated.find :all,
41: :conditions => "organization_id in (#{organization_ids.join(',')})",
42: :order => 'published_at DESC', :limit => 10
43:
44: respond_to do |format|
45: format.html {render :action => "home"}
46: format.rss {render :action => "myfeed", :layout => false}
47: end
48: else
49: flash[:notice] = t('site.info_acceso_agencia')
50: ma_access_denied
51: end
52: end
Búsqueda con Ferret por los contenidos de la Agencia Multimedia
# File app/controllers/ma/news_controller.rb, line 114
114: def search
115: if params[:q].blank?
116: flash[:notice] = t('site.search_empty')
117: redirect_to s_ma_news_path and return
118: end
119:
120: q = params[:q].gsub('-', '')
121: @q = q.to_ferret_search_string
122: logger.info "Agencia: Termino de busqueda limpio: #{@q}"
123:
124: today_epoch = (Date.today - Date.parse('2009-03-01')).to_s.to_i
125:
126: @breadcrumbs_info = [['Agencia', ma_news_index_path], [t('site.busqueda'), s_ma_news_path]]
127:
128: sf_date = Ferret::Search::SortField.new(:published_month_year_for_ferret, :type => :integer, :reverse => true)
129:
130: # @search_results = ActsAsFerret.paginate_search("#{@q} AND show_in_agencia:true AND starts_at_in_agencia_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
131: # [News, Event],
132: # :sort => [sf_date, Ferret::Search::SortField::SCORE],
133: # :page => params[:page] || 1, :per_page => 20)
134:
135: candidates = ActsAsFerret.find("#{@q} AND show_in_agencia:true AND starts_at_in_agencia_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
136: [News, Event])
137:
138: candidates.each do |c|
139: date_score = ((1.0-((today_epoch - c.days_from_epoch_for_ferret)/today_epoch.to_f)) * 0.65)
140: # logger.info "BBBBBBBB ((1-((#{today_epoch} - #{c.days_from_epoch_for_ferret})/#{today_epoch.to_f})) * 0.65) : #{date_score.round(2)}"
141: c.ef_score = c.ferret_score + date_score
142: end
143:
144: candidates.sort! {|a, b| b.ef_score <=> a.ef_score}
145:
146: page, per_page, total = (params[:page]||1).to_i, 20, candidates.length
147: @search_results = WillPaginate::Collection.create(page, per_page, total) do |pager|
148: pager.replace candidates[(page-1)*per_page..(page*per_page)-1]
149: end
150:
151: end
Vista de una noticia
# File app/controllers/ma/news_controller.rb, line 99
99: def show
100: begin
101: @news = News.in_agencia.published.find(params[:id])
102: rescue ActiveRecord::RecordNotFound
103: if can_edit?("news")
104: @news = News.in_agencia.find(params[:id])
105: else
106: raise ActiveRecord::RecordNotFound
107: end
108: end
109: @title_for_head = @news.title
110: @category = Category.find(params[:category_id]) if params[:category_id]
111: end