thema doku

This commit is contained in:
Andreas Stephanides
2015-03-08 22:13:05 +01:00
parent d02b3a7e69
commit 9b46f868da

View File

@@ -8,34 +8,52 @@
# text :text # text :text
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# themengruppe_id :integer # themengruppe_id :integer ID of themengruppe
# # isdraft :boolean True if this topic is only a draft an should not be visible to public
# hidelink :boolean true if link to this topic should not be visible in the list
# hideattachment :boolean hide the attachment table in the view - doesnt hide attachments that are linked and doesn't protect them
# sticky_startpage :boolean if true topic is sticked on the start page
# sticky_intern : boolean if true this topic is sticked at the intern page
require 'uri' require 'uri'
class Thema < ActiveRecord::Base class Thema < ActiveRecord::Base
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
# Properties that should be accesible
attr_accessible :text, :title, :themengruppe_id,:isdraft, :hidelink, :hideattachment, :sticky_startpage,:sticky_intern attr_accessible :text, :title, :themengruppe_id,:isdraft, :hidelink, :hideattachment, :sticky_startpage,:sticky_intern
# Each topic has multiple questions, that are also referenced in the FAQ.
has_many :fragen has_many :fragen
# Attachments can be all data formats
has_many :attachments has_many :attachments
belongs_to :themengruppe, :foreign_key => "themengruppe_id" # attached pics can be used as title pictures
has_one :gremium has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true}
has_many :nlinks, as: :link # each topic has to belong to one group
belongs_to :themengruppe, :foreign_key => "themengruppe_id", :touch=>true
validates :themengruppe, :presence => true validates :themengruppe, :presence => true
# a topic can be linked to a gremium
has_one :gremium
# a topic can be attached to news
has_many :nlinks, as: :link
# each topic can have multiple meetings
has_many :meetings, :as=>:parent
# each topic can have multiple documents
has_many :documents, :as=>:parent
validates :title, :presence => true validates :title, :presence => true
validates :text, :presence => true validates :text, :presence => true
has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true}
has_many :meetings, :as=>:parent scope :outdated, -> {includes(:translations).where("thema_translations.updated_at<?",7.month.ago).where("thema_translations.locale"=>I18n.t.locale)}
has_many :documents, :as=>:parent
scope :public, where(:isdraft=>false).includes(:themengruppe).where("themengruppen.public"=>true) scope :public, where(:isdraft=>false).includes(:themengruppe).where("themengruppen.public"=>true)
default_scope order("themen.priority").reverse_order default_scope order("themen.priority").reverse_order
# scope :search, ->(query) {where("themen.text like ? or themen.title like ?", "%#{query}%", "%#{query}%")} # make topic searchable
resourcify
searchable do searchable do
text :text text :text
text :title, :boost=>4.0 text :title, :boost=>4.0
end end
scope :outdated, -> {includes(:translations).where("thema_translations.updated_at<?",7.month.ago).where("thema_translations.locale"=>I18n.t.locale)
} resourcify
# title and text can have
translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true
def is_outdated? def is_outdated?
unless translation.try(:updated_at).nil? unless translation.try(:updated_at).nil?
translation.updated_at < 7.month.ago translation.updated_at < 7.month.ago