2007-12-03 03:47:21 -05:00
|
|
|
##
|
|
|
|
# This model represents a user in the system.
|
|
|
|
#
|
|
|
|
class People < ActiveRecord::Base
|
|
|
|
has_one_tuxwiki_page :owner_class => 'People'
|
2007-12-06 12:31:17 -05:00
|
|
|
belongs_to :role
|
|
|
|
attr_protected :role_id
|
2007-12-27 00:19:13 -05:00
|
|
|
has_many :created_pages, :class_name => 'Page', :foreign_key => 'created_by'
|
|
|
|
has_many :updated_pages, :class_name => 'Page', :foreign_key => 'updated_by'
|
2008-01-31 23:46:06 -05:00
|
|
|
has_many :images, :dependent => :destroy
|
|
|
|
has_many_tagged_images
|
2008-01-02 02:58:03 -05:00
|
|
|
validates_uniqueness_of :title
|
2008-02-01 02:43:40 -05:00
|
|
|
has_many :friends, :foreign_key => :source_id, :dependent => :destroy
|
|
|
|
has_many :actual_friends, :through => :friends, :source => :destination
|
2008-02-02 19:57:35 -05:00
|
|
|
has_many :experiences, :dependent => :destroy
|
|
|
|
has_many :beers, :through => :experiences
|
2008-02-03 15:16:53 -05:00
|
|
|
has_many :invitations, :dependent => :destroy,
|
|
|
|
:conditions => [ 'sent IS NULL or sent = ?', false ]
|
2007-12-27 01:13:08 -05:00
|
|
|
|
2008-01-07 02:32:07 -05:00
|
|
|
make_authenticatable
|
|
|
|
validates_length_of :password, :minimum => 8, :if => :password_required?,
|
|
|
|
:message => 'must be at least 8 characters in length'
|
|
|
|
|
2008-02-01 02:43:40 -05:00
|
|
|
##
|
|
|
|
# Used to quickly determine if the particular id of another Person is a
|
|
|
|
# Friend of this instance.
|
|
|
|
#
|
|
|
|
def friend_of?(people_id)
|
|
|
|
Friend.count([ 'source_id = ? AND destination_id = ?', people_id, id ]) > 0
|
|
|
|
end
|
|
|
|
|
2007-12-27 01:13:08 -05:00
|
|
|
##
|
|
|
|
# Finds me.
|
|
|
|
#
|
|
|
|
def self.penguincoder
|
2007-12-27 01:31:45 -05:00
|
|
|
@penguincoder ||= self.find_by_title('PenguinCoder') rescue nil
|
|
|
|
@penguincoder
|
2007-12-27 01:13:08 -05:00
|
|
|
end
|
2008-01-07 02:32:07 -05:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
##
|
|
|
|
# Determines if the password is needed.
|
|
|
|
#
|
|
|
|
def password_required?
|
|
|
|
self.encrypted_password.blank?
|
|
|
|
end
|
2007-12-03 03:47:21 -05:00
|
|
|
end
|