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
|
2014-08-31 14:57:34 +03:00
|
|
|
|
2015-07-26 15:58:08 +03:00
|
|
|
accepts_nested_attributes_for :personal_profiles
|
2014-09-17 17:48:46 +03:00
|
|
|
|
2014-09-18 01:07:09 +03:00
|
|
|
default_scope { order id: :desc }
|
|
|
|
|
2015-05-30 18:53:14 +03:00
|
|
|
def personal_profile(conference)
|
2015-07-26 15:58:08 +03:00
|
|
|
personal_profiles.find_by(conference_id: conference.id)
|
2014-10-10 19:23:38 +03:00
|
|
|
end
|
|
|
|
|
2014-09-17 17:48:46 +03:00
|
|
|
def toggle_admin!
|
|
|
|
update admin: !admin
|
|
|
|
end
|
2015-07-26 15:58:08 +03:00
|
|
|
|
|
|
|
def clone_recent_profile(new_conference)
|
|
|
|
recent_profile = personal_profiles.order('created_at DESC').first
|
|
|
|
|
|
|
|
personal_profiles.build(conference: new_conference) do |new_profile|
|
|
|
|
if recent_profile.present?
|
|
|
|
new_profile.attributes = recent_profile.attributes.except(
|
|
|
|
"id", "created_at", "updated_at", "conference_id"
|
|
|
|
)
|
|
|
|
new_profile.remote_picture_url = recent_profile.picture.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-28 14:15:08 +03:00
|
|
|
end
|