2014-07-28 14:15:08 +03:00
|
|
|
class User < ActiveRecord::Base
|
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
# :lockable, :timeoutable and :omniauthable
|
|
|
|
devise :database_authenticatable, :registerable, :confirmable,
|
|
|
|
:recoverable, :rememberable, :trackable, :validatable
|
2014-08-30 17:31:29 +03:00
|
|
|
|
2015-05-30 18:53:14 +03:00
|
|
|
has_many :personal_profiles, dependent: :destroy
|
2014-08-30 17:31:29 +03:00
|
|
|
has_many :lectures
|
|
|
|
has_many :workshops
|
2014-09-30 13:34:09 +03:00
|
|
|
has_many :events
|
2015-08-05 17:17:04 +03:00
|
|
|
|
2015-08-15 08:01:48 +03:00
|
|
|
def find_or_build_personal_profile(conference, params = {})
|
|
|
|
current_profile = personal_profile(conference)
|
|
|
|
if current_profile.present?
|
|
|
|
current_profile.assign_attributes params
|
|
|
|
current_profile
|
|
|
|
else
|
|
|
|
build_personal_profile(conference, params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-15 01:57:17 +03:00
|
|
|
def build_personal_profile(conference, params = {})
|
2015-08-15 08:01:48 +03:00
|
|
|
new_personal_profile = personal_profiles.last.try(:dup) || personal_profiles.build
|
2015-08-15 01:57:17 +03:00
|
|
|
new_personal_profile.conference = conference
|
|
|
|
new_personal_profile.assign_attributes params
|
|
|
|
new_personal_profile
|
2015-08-05 17:17:04 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def personal_profile(conference)
|
|
|
|
personal_profiles.find_by(conference_id: conference.id)
|
|
|
|
end
|
2014-08-31 14:57:34 +03:00
|
|
|
|
2014-09-18 01:07:09 +03:00
|
|
|
default_scope { order id: :desc }
|
|
|
|
|
2014-09-17 17:48:46 +03:00
|
|
|
def toggle_admin!
|
|
|
|
update admin: !admin
|
|
|
|
end
|
2014-07-28 14:15:08 +03:00
|
|
|
end
|