| Class | Ma::NewsController |
| In: |
app/controllers/ma/news_controller.rb
|
| Parent: | Ma::BaseController |
# File app/controllers/ma/news_controller.rb, line 60
60: def archive
61: @title = t('documents.News_archive')
62: @news = News.in_agencia.published.translated.paginate :page => params[:page], :per_page => 50,
63: :include => [:organization => :icon],
64: :order => 'published_at DESC'
65: end
# File app/controllers/ma/news_controller.rb, line 67
67: def feed
68: @title = t('documents.News')
69: @news = News.in_agencia.published.translated.find :all, :limit => 10,
70: :order => 'published_at DESC'
71:
72: respond_to do |format|
73: format.html
74: format.rss {render :action => "myfeed", :layout => false}
75: end
76: end
# File app/controllers/ma/news_controller.rb, line 6
6: def home
7: @title_for_head = t('documents.News')
8: flash.delete(:notice)
9:
10: @news = News.in_agencia.published.translated.find :all, :include => [:organization => :icon],
11: :conditions => "organization_id in (#{@organization_ids.join(',')})",
12: :order => 'published_at DESC', :limit => 15
13:
14: if @news.length == 0
15: redirect_to ma_news_index_path and return
16: end
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 + 3.days], :limit => 4)
21:
22: @events = (@today_events + @future_events).uniq
23:
24: @streaming = StreamFlow.find_by_show_in_agencia(true)
25: end
# File app/controllers/ma/news_controller.rb, line 46
46: def index
47: @title = t('documents.News')
48: @news = News.in_agencia.translated.published.paginate :page => params[:page], :per_page => 15,
49: :include => [:organization => :icon],
50: :order => 'published_at DESC'
51:
52: @category = Category.find(params[:category_id]) if params[:category_id]
53:
54: respond_to do |format|
55: format.html
56: format.rss {render :layout => false}
57: end
58: end
# File app/controllers/ma/news_controller.rb, line 27
27: def myfeed
28: if params[:u] && params[:p]
29: user = Journalist.authenticate_from_url(params[:u], params[:p])
30: end
31:
32: if user
33: #department_ids = user.department_ids.length > 0 ? user.department_ids : [0]
34: organization_ids = user.organization_ids.length > 0 ? user.organization_ids : [0]
35: @news = News.in_agencia.published.translated.find :all,
36: :conditions => "organization_id in (#{organization_ids.join(',')})",
37: :order => 'published_at DESC', :limit => 10
38:
39: respond_to do |format|
40: format.html {render :action => "home"}
41: format.rss {render :action => "myfeed", :layout => false}
42: end
43: end
44: end
# File app/controllers/ma/news_controller.rb, line 93
93: def search
94: if params[:q].blank?
95: flash[:notice] = t('site.search_empty')
96: redirect_to s_ma_news_path and return
97: end
98:
99: q = params[:q].gsub('-', '')
100: @q = q.to_ferret_search_string
101: logger.info "Agencia: Termino de busqueda limpio: #{@q}"
102:
103: today_epoch = (Date.today - Date.parse('2009-03-01')).to_s.to_i
104:
105: @breadcrumbs_info = [['Agencia', ma_news_index_path], [t('site.busqueda'), s_ma_news_path]]
106:
107: sf_date = Ferret::Search::SortField.new(:published_month_year_for_ferret, :type => :integer, :reverse => true)
108:
109: # @search_results = ActsAsFerret.paginate_search("#{@q} AND show_in_agencia:true AND starts_at_in_agencia_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
110: # [News, Event],
111: # :sort => [sf_date, Ferret::Search::SortField::SCORE],
112: # :page => params[:page] || 1, :per_page => 20)
113:
114: candidates = ActsAsFerret.find("#{@q} AND show_in_agencia:true AND starts_at_in_agencia_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
115: [News, Event])
116:
117: candidates.each do |c|
118: date_score = ((1.0-((today_epoch - c.days_from_epoch_for_ferret)/today_epoch.to_f)) * 0.65)
119: # logger.info "BBBBBBBB ((1-((#{today_epoch} - #{c.days_from_epoch_for_ferret})/#{today_epoch.to_f})) * 0.65) : #{date_score.round(2)}"
120: c.ef_score = c.ferret_score + date_score
121: end
122:
123: candidates.sort! {|a, b| b.ef_score <=> a.ef_score}
124:
125: page, per_page, total = (params[:page]||1).to_i, 20, candidates.length
126: @search_results = WillPaginate::Collection.create(page, per_page, total) do |pager|
127: pager.replace candidates[(page-1)*per_page..(page*per_page)-1]
128: end
129:
130: end
# File app/controllers/ma/news_controller.rb, line 78
78: def show
79: begin
80: @news = News.in_agencia.published.find(params[:id])
81: rescue ActiveRecord::RecordNotFound
82: if can_edit?("news")
83: @news = News.in_agencia.find(params[:id])
84: else
85: raise ActiveRecord::RecordNotFound
86: end
87: end
88: @title_for_head = @news.title
89: @category = Category.find(params[:category_id]) if params[:category_id]
90: end