OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/models/meeting.rb

81 lines
2.4 KiB

class Meeting < ActiveRecord::Base
unloadable
belongs_to :project
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_one :agenda, :dependent => :destroy, :class_name => 'MeetingAgenda'
has_one :minutes, :dependent => :destroy, :class_name => 'MeetingMinutes'
has_many :contents, :class_name => 'MeetingContent', :readonly => true
has_many :participants, :dependent => :destroy, :class_name => 'MeetingParticipant'
acts_as_watchable
acts_as_searchable :columns => ["#{table_name}.title", "#{MeetingContent.table_name}.text"],
:include => [:contents, :project],
:date_column => "#{table_name}.created_at"
acts_as_event :title => Proc.new {|o| "#{l :label_meeting}: #{o.title} (#{format_date o.start_time} #{format_time o.start_time, false}-#{format_time o.end_time, false})"},
:description => :text,
:datetime => :created_at,
:url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o}}
accepts_nested_attributes_for :participants, :reject_if => proc {|attrs| !(attrs['attended'] || attrs['invited'])}
validates_presence_of :title, :start_time, :duration
after_create :add_author_as_watcher
def self.find_time_sorted(*args)
by_start_year_month_date = ActiveSupport::OrderedHash.new
self.find(*args).group_by(&:start_year).each do |year,objs|
by_start_year_month_date[year] = ActiveSupport::OrderedHash.new
objs.group_by(&:start_month).each do |month,objs|
by_start_year_month_date[year][month] = ActiveSupport::OrderedHash.new
objs.group_by(&:start_date).each do |date,objs|
by_start_year_month_date[year][month][date] = objs.sort_by {|m| m.start_time}.reverse
end
end
end
by_start_year_month_date
end
def start_date
# the text_field + calendar_for form helpers expect a Date
start_time.to_date if start_time.present?
end
def start_month
14 years ago
start_time.month
end
def start_year
14 years ago
start_time.year
end
def end_time
start_time + duration.hours
end
def to_s
title
end
def text
agenda.text if agenda.present?
end
protected
def after_initialize
# set defaults
self.start_time ||= Date.tomorrow + 10.hours
self.duration ||= 1
end
private
def add_author_as_watcher
add_watcher(author)
end
end