User/Person models merge

This commit is contained in:
Stella Rouzi 2014-06-23 19:07:50 +03:00
parent 66b84e3660
commit 23bf55b66c
80 changed files with 1064 additions and 1221 deletions

View file

@ -1,18 +1,18 @@
class Event < ActiveRecord::Base
include ActiveRecord::Transitions
has_paper_trail
attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :people_attributes, :person, :proposal_additional_speakers, :track_id, :media_id, :media_type, :require_registration, :difficulty_level_id
attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :users_attributes, :user, :proposal_additional_speakers, :track_id, :media_id, :media_type, :require_registration, :difficulty_level_id
acts_as_commentable
after_create :set_week
has_many :event_people, :dependent => :destroy
has_many :event_users, :dependent => :destroy
has_many :event_attachments, :dependent => :destroy
has_many :people, :through => :event_people
has_many :speakers, :through => :event_people, :source => :person
has_many :users, :through => :event_users
has_many :speakers, :through => :event_users, :source => :user
has_many :votes
has_many :voters, :through => :votes, :source => :person
has_many :voters, :through => :votes, :source => :user
belongs_to :event_type
has_and_belongs_to_many :registrations
@ -22,9 +22,9 @@ class Event < ActiveRecord::Base
belongs_to :difficulty_level
belongs_to :conference
accepts_nested_attributes_for :event_people, :allow_destroy => true
accepts_nested_attributes_for :event_users, :allow_destroy => true
accepts_nested_attributes_for :event_attachments, :allow_destroy => true, :reject_if => :all_blank
accepts_nested_attributes_for :people
accepts_nested_attributes_for :users
before_create :generate_guid
validate :abstract_limit
@ -63,10 +63,10 @@ class Event < ActiveRecord::Base
end
end
def voted?(event, person)
event.votes.where("person_id = ?", person).first
def voted?(event, user)
event.votes.where("user_id = ?", user).first
end
def average_rating
@total_rating = 0
self.votes.each do |vote|
@ -77,18 +77,18 @@ class Event < ActiveRecord::Base
end
def submitter
result = self.event_people.where(:event_role => "submitter").first
result = self.event_users.where(:event_role => "submitter").first
if !result.nil?
result.person
result.user
else
person = nil
# Perhaps the event_people haven't been saved, if this is a new proposal
self.event_people.each do |p|
user = nil
# Perhaps the event_users haven't been saved, if this is a new proposal
self.event_users.each do |p|
if p.event_role == "submitter"
person = p.person
user = p.user
end
end
person
user
end
end
@ -122,7 +122,7 @@ class Event < ActiveRecord::Base
def process_confirmation
if self.conference.email_settings.send_on_confirmed_without_registration?
if self.conference.registrations.where(:person_id => self.submitter.id).first.nil?
if self.conference.registrations.where(:user_id => self.submitter.id).first.nil?
Mailbot.confirm_reminder_mail(self).deliver
end
end
@ -194,7 +194,7 @@ class Event < ActiveRecord::Base
def biography_exists
if self.submitter.biography_word_count == 0
errors.add(:person_biography, "must be filled out")
errors.add(:user_biography, "must be filled out")
end
end