Clase para las Noticias. Es subclase de Document, por lo que usa la tabla
documents
# File app/models/news.rb, line 133 def self.featured_4b featured_b = self.published.translated.listable.find :all, :conditions => "featured='4B'", :order => "published_at DESC" most_recent_without_featured_1a = self.most_recent_with_image.delete_if {|n| n.id == self.featured_a.id} featured_b = featured_b + most_recent_without_featured_1a[0..(4-featured_b.length-1)] if featured_b.length < 4 return featured_b end
# File app/models/news.rb, line 121 def self.featured_a featured_a = self.published.translated.listable.find :first, :conditions => "featured='1A'", :order => "published_at DESC" # Si no hay ninguna, cogemos la más reciene con foto if featured_a.nil? featured_a = self.find(self.most_recent_with_image.shift.id) if self.most_recent_with_image.length > 0 end return featured_a end
/ Para euskadi.net
# File app/models/news.rb, line 102 def self.ley_vivienda begin self.find(4597) rescue nil end end
# File app/models/news.rb, line 110 def self.most_recent self.published.translated.listable.find :all, :include => :organization, :order => "published_at DESC", :limit => 29 end
# File app/models/news.rb, line 117 def self.most_recent_with_image self.most_recent.select {|n| n.has_video? || n.has_cover_photo? || n.has_photos?} end
See thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip#comment-2415
# File app/models/news.rb, line 63 def attachment_for name @_paperclip_attachments ||= {} @_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name]) end
# File app/models/news.rb, line 89 def cuerpo(lang_code=I18n.locale) c = self.pretty_body(lang_code).dup if self.subtitle.present? c = c.gsub(/<[^<]+class="r01Subtitular".*?>#{Regexp.escape(self.subtitle(lang_code))}<\/.+?>/, '') end if self.entradilla.present? c = c.gsub(/<[^<]+class="r01Entradilla".*?>#{Regexp.escape(self.entradilla(lang_code))}<\/.+?>/, '') end return c end
Noticias que corresponden a Debate
# File app/models/news.rb, line 155 def debate_id self.debate.present? ? self.debate.id : nil end
# File app/models/news.rb, line 159 def debate_id=(d_id) if debate = Debate.find(d_id) self.debate = debate end true end
# File app/models/news.rb, line 81 def entradilla(lang_code=I18n.locale) if self.send("body_#{lang_code}").present? && m = self.send("body_#{lang_code}").match(/<.+class=\"r01Entradilla\".*?>(.+?)</) return m[1] else return "" end end
# File app/models/news.rb, line 146 def is_consejo_news !consejo_news_id.nil? && consejo_news_id != 19841984 end
# File app/models/news.rb, line 150 def is_programa_de_gobierno_news consejo_news_id == 19841984 end
Para euskadi.net
# File app/models/news.rb, line 73 def subtitle(lang_code=I18n.locale) if self.send("body_#{lang_code}").present? && m = self.send("body_#{lang_code}").match(/<.+class=\"r01Subtitular\".*?>(.+?)</) return m[1] else return "" end end
Garantiza que solo habrá cuatro noticias destacadas ‘4B’ en Irekia. Si hay más, se quitan las más antiguas Se llama before_update
# File app/models/news.rb, line 207 def check_only_four_b_featured if featured.eql?('4B') && featured_changed? if News.featured_4b.length == 4 News.featured_4b.last.update_attribute(:featured, nil) end end end
Garantiza que solo habrá una noticia destacada ‘A’ en Irekia. Se llama before_update
# File app/models/news.rb, line 200 def check_only_one_a_featured Document.update_all("featured=null", "featured='1A'") if featured.eql?('1A') && featured_changed? end
No todas las columnas de la tabla documents se utilizan en las noticias, por lo que nos aseguramos de que están vacías. Se llama desde before_save
# File app/models/news.rb, line 170 def disable_unnecessary_fields self.starts_at = nil self.ends_at = nil self.place = nil self.lat = nil self.lng = nil self.location_for_gmaps = nil self.stream_flow_id = false self.journalist_alert_version = 0 self.staff_alert_version = 0 end
# File app/models/news.rb, line 215 def nullify_empty_featured self.featured = nil if self.featured == '' end
Programa el auto-tweeteo de las noticias publicadas en irekia, con fecha igual a la fecha de publicacion en la web. Se llama desde before_save
# File app/models/news.rb, line 184 def schedule_tweets # Si ha pasado más de un mes desde su publicación, no lo twitteamos if self.published_at && self.published_at >= 1.month.ago # Primero borramos los tweets pendientes de este evento, por si ha cambiado la fecha DocumentTweet.delete_all(["document_id= ? AND tweeted_at IS NULL", self.id]) Event::LANGUAGES.each do |l| if self.published? && self.translated_to?(l.to_s) && !DocumentTweet.exists?(:document_id => self.id, :tweet_locale => l.to_s) self.tweets.build(:tweet_account => "irekia_news", :tweet_at => self.published_at, :tweet_locale => l.to_s) end end end end