summaryrefslogtreecommitdiff
path: root/app/models/conference_invitee.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/models/conference_invitee.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'app/models/conference_invitee.rb')
-rw-r--r--app/models/conference_invitee.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/conference_invitee.rb b/app/models/conference_invitee.rb
new file mode 100644
index 0000000..7de20de
--- /dev/null
+++ b/app/models/conference_invitee.rb
@@ -0,0 +1,39 @@
+class ConferenceInvitee < ActiveRecord::Base
+ attr_accessible :pin, :speaker, :moderator, :phone_number, :phone_number_attributes
+
+ belongs_to :conference
+ belongs_to :phone_book_entry
+ has_one :phone_number, :as => :phone_numberable, :dependent => :destroy
+ accepts_nested_attributes_for :phone_number
+
+ validates_presence_of :conference_id
+ validates_presence_of :conference
+ validates_presence_of :phone_number
+ validates_numericality_of :pin, :only_integer => true,
+ :greater_than => 0,
+ :allow_nil => true,
+ :allow_blank => true
+ validates_length_of :pin, :minimum => MINIMUM_PIN_LENGTH,
+ :allow_nil => true,
+ :allow_blank => true
+
+ validates_inclusion_of :speaker, :in => [true, false]
+ validates_inclusion_of :moderator, :in => [true, false]
+
+ validate :uniqueness_of_phone_number_in_the_parent_conference
+ validates_uniqueness_of :phone_book_entry_id, :scope => :conference_id, :allow_nil => true
+
+ def to_s
+ "ID #{self.id}"
+ end
+
+ private
+
+ def uniqueness_of_phone_number_in_the_parent_conference
+ if self.conference.conference_invitees.where('id != ?', self.id).count > 0 &&
+ self.conference.conference_invitees.where('id != ?', self.id).map{|x| x.phone_number.number}.
+ include?(self.phone_number.number)
+ errors.add(:base, 'Phone number is not unique within the conference.')
+ end
+ end
+end