Class PeerGroupMembership
In: app/models/peer_group_membership.rb
Parent: ActiveRecord::Base

Users can be a member of one or more PeerGroups.

This relationship is modelled by this class.

Methods

Public Class methods

Returns the power that the founding-member starts with

[Source]

    # File app/models/peer_group_membership.rb, line 56
56:   def self.admin_power
57:     return GlobalConfig.admin_power
58:   end

Returns the power that members start with.

(Only in the general PeerGroup)

[Source]

    # File app/models/peer_group_membership.rb, line 44
44:   def self.anonymous_power
45:     return GlobalConfig.anonymous_power
46:   end

Drops the membership of users that receive less than 0.10 daily voting power.

[Source]

    # File app/models/peer_group_membership.rb, line 79
79:   def self.drop_the_powerless
80:     PeerGroupMembership.find_each(
81:         :conditions => 'peer_group_id != ' + PeerGroup.public.id.to_s +
82:         ' AND power <= ' + PeerGroupMembership.member_power.to_s +
83:         ' AND updated_at > "' + GlobalConfig.powerless_age.days.ago.to_s(:db) +
84:         '"') do |membership|
85:       membership.destroy
86:     end
87:   end

Returns the power that members start with.

[Source]

    # File app/models/peer_group_membership.rb, line 50
50:   def self.member_power
51:     return GlobalConfig.member_power
52:   end

Recalculates the daily_power_earnings percentiles.

[Source]

    # File app/models/peer_group_membership.rb, line 64
64:   def self.recalculate_percentiles
65:     PeerGroup.find_each do |peer_group|
66:       count = peer_group.memberships.count.to_f
67:       counter = count
68:       peer_group.memberships.order_by_power.each do |membership|
69:         membership.percentile = (counter / count) * 100
70:         membership.save
71:         counter -= 1
72:       end
73:     end
74:   end

Public Instance methods

Sets the default settings for new admins

[Source]

     # File app/models/peer_group_membership.rb, line 95
 95:   def admin_settings=(give_admin_settings)
 96:     if give_admin_settings
 97:       if self.role == Const::PeerGroupMembership::MEMBER or self.new_record?
 98:         if !self.new_record?
 99:           self.power -= PeerGroupMembership.member_power
100:         end
101:         self.role = Const::PeerGroupMembership::ADMIN
102:         self.power = self.power + PeerGroupMembership.admin_power
103:       end
104:     else
105:       if self.role == Const::PeerGroupMembership::ADMIN or self.new_record?
106:         if !self.new_record?
107:           self.power -= PeerGroupMembership.admin_power
108:         end
109:         self.role = Const::PeerGroupMembership::MEMBER
110:         self.power = self.power + PeerGroupMembership.member_power
111:       end
112:     end
113:   end

Caps the percentile, so < 10 and > 99 do not occur.

[Source]

     # File app/models/peer_group_membership.rb, line 119
119:   def capped_percentile
120:     if self.percentile < 20
121:       return 20
122:     elsif self.percentile > 99
123:       return 99
124:     else
125:       return self.percentile
126:     end
127:   end

Protected Instance methods

Called from user. Checks that the membership is not the only admin admin, and if it is, the User.admin user is made admin-member of this group.

[Source]

     # File app/models/peer_group_membership.rb, line 137
137:   def pass_on_admin_role
138:     if self.peer_group and 
139:         self.peer_group.memberships.select_by_role(Const::PeerGroupMembership::ADMIN).size == 1
140:       self.peer_group.memberships.create(:user => User.admin,
141:           :role => Const::PeerGroupMembership::ADMIN, :power => PeerGroupMembership.admin_power)
142:     end
143:     return true
144:   end

[Validate]