This commit is contained in:
HausdorffHimself
2013-08-24 04:17:03 +02:00
25 changed files with 131 additions and 43 deletions

View File

@@ -15,4 +15,5 @@ class Calendar < ActiveRecord::Base
has_and_belongs_to_many :calentries
mount_uploader :picture, PictureUploader
resourcify
scope :public, -> { where(:public => :true) }
end

View File

@@ -16,14 +16,21 @@ class Calentry < ActiveRecord::Base
has_and_belongs_to_many :calendars
validates :start, :presence => true
validates :typ, :presence => true
before_save :get_public
belongs_to :object, polymorphic: true
validate do |entry|
if entry.ende.nil?
errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein")
end
end
belongs_to :object, polymorphic: true
resourcify
def get_public
self.public = (self.try(:object).nil?)? (self.calendars.public.count>0) : object.try(:public)
true
end
def start_time
start
end
@@ -33,5 +40,6 @@ class Calentry < ActiveRecord::Base
def name
summary
end
scope :public, -> { where(:public => :true) }
scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 8.days.from_now) }
end

View File

@@ -14,14 +14,30 @@
class Neuigkeit < ActiveRecord::Base
attr_accessible :datum, :text, :title, :rubrik_id, :author_id
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture
belongs_to :author, :class_name =>'User'
belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id"
validates :rubrik, :presence=>true
validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
scope :published, -> {where("datum >= ?", Time.now.to_date)}
scope :recent, -> { where("updated_at >= ? ",Time.now - 7.days)}
has_one :calentry, :as => :object
mount_uploader :picture, PictureUploader
scope :published, -> {where("datum >= ? AND datum IS NOT NULL", Time.now.to_date)}
scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum
end
def public
self.rubrik.public && self.datum >=Time.now.to_date
end
def publish
self.datum = Time.now
end
def reverse_publish
self.datum = nil
end
def text_first_words
md = /<p>(?<text>[\w\s,\.!\?]*)/.match self.text
md[:text].split(" ")[1..100].join(" ")+ " ..."
end
end

View File

@@ -13,6 +13,7 @@
class Rubrik < ActiveRecord::Base
attr_accessible :desc, :name, :prio
has_many :neuigkeiten, :class_name => "Neuigkeit"
has_many :calentries, :through => :neuigkeiten, :as=>:object
resourcify
def moderator
u=User.with_role(:newsmoderator).first