2012-08-25 04:14:51 +00:00
class User < ActiveRecord :: Base
2013-01-26 09:21:41 +00:00
include Gravtastic
gravtastic :size = > 120 , :default = > " "
2012-09-02 11:12:26 +00:00
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
2012-10-14 12:46:19 +00:00
devise :database_authenticatable , :registerable ,
2012-09-02 11:12:26 +00:00
:recoverable , :rememberable , :trackable , :validatable
# Setup accessible (or protected) attributes for your model
2013-02-12 08:58:17 +00:00
attr_accessible :email , :password , :password_confirmation , :remember_me , :name , :admin , :instructor , :member , :emergency_name , :emergency_phone , :current_skills , :desired_skills , :waiver , :emergency_email , :phone , :payment_method , :orientation , :member_level , :certifications , :hidden , :marketing_source , :payee , :accountant #TODO: make admin/instructor/member/etc not accessible
2012-08-25 04:14:51 +00:00
2012-10-14 12:46:19 +00:00
has_many :cards
2013-01-25 10:50:53 +00:00
has_many :user_certifications
has_many :certifications , :through = > :user_certifications
2013-02-12 08:58:17 +00:00
has_many :payments
2013-01-25 13:01:02 +00:00
2013-02-01 11:44:05 +00:00
after_create :send_new_user_email
2013-02-12 08:58:17 +00:00
def name_with_payee_and_member_level
if payee . blank? then
" #{ name } - #{ member_level_string } "
else
" #{ payee } for #{ name } - #{ member_level_string } "
end
end
2013-02-01 11:44:05 +00:00
2013-02-12 08:58:17 +00:00
def member_level_string
case self . member_level . to_i
when 0
" None "
when 1
" Unable "
when 10 .. 24
" Volunteer "
when 25 .. 49
" Associate ($25) "
when 50 .. 99
" Basic ($50) "
when 100 .. 999
" Plus ($100) "
2013-01-26 04:11:01 +00:00
end
2013-02-12 08:58:17 +00:00
end
2013-01-26 04:11:01 +00:00
2013-02-12 08:58:17 +00:00
def member_status
case self . member_level . to_i
when 0
if self . payments . count > 0 then
2
else
- 1
2013-01-26 04:11:01 +00:00
end
2013-02-12 08:58:17 +00:00
when 1
1
when 10 .. 24
10
when 25 .. 999
if self . payments . count > 0 then
2013-02-19 06:29:06 +00:00
if self . payments . last . date < ( DateTime . now - 45 . days )
2013-02-12 08:58:17 +00:00
3
else
case self . member_level . to_i
when 25 .. 49
25
when 50 .. 99
50
when 100 .. 999
100
end
end
else
return 0
2013-01-26 04:11:01 +00:00
end
2013-02-12 08:58:17 +00:00
end
end
def member_status_symbol
case self . member_level . to_i
when 0
if self . payments . count > 0 then
2013-02-19 06:29:06 +00:00
" <span class='hoverinfo' title='Former Member ( #{ ( DateTime . now - self . payments . last . date ) . to_i } days ago)'>:(</span> "
2013-02-12 08:58:17 +00:00
else
" <!-- Not a member --> "
2013-01-26 04:11:01 +00:00
end
2013-02-12 08:58:17 +00:00
when 1
" Unable "
when 10 .. 24
" <span class='hoverinfo' title='Volunteer'>& # 9684;</span> "
when 25 .. 999
if self . payments . count > 0 then
2013-02-19 06:29:06 +00:00
if self . payments . last . date < ( DateTime . now - 45 . days )
" <span class='hoverinfo' title='Recently Lapsed ( #{ ( DateTime . now - self . payments . last . date ) . to_i } days ago)'>& # 9676;</span> "
2013-02-12 08:58:17 +00:00
else
case self . member_level . to_i
when 25 .. 49
" <span class='hoverinfo' title=' #{ member_level_string } '>& # 9681;</span> "
when 50 .. 99
" <span class='hoverinfo' title=' #{ member_level_string } '>& # 9685;</span> "
when 100 .. 999
" <span class='hoverinfo' title=' #{ member_level_string } '>& # 9679;</span> "
end
end
else
" <span class='hoverinfo' title='No Payments'>?</span> "
2013-01-26 04:11:01 +00:00
end
2013-01-25 13:01:02 +00:00
end
end
2013-02-01 11:44:05 +00:00
private
def send_new_user_email
Rails . logger . info UserMailer . new_user_email ( self ) . deliver
end
2012-08-25 04:14:51 +00:00
end