Class: Reputation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/reputation.rb

Class Method Summary collapse

Class Method Details

.add(name, *users) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/reputation.rb', line 5

def self.add(name,*users)
  reputation_action = ReputationAction.where(:name=>name).first
  if reputation_action.present? and users
    users.each do |user|
      if user.present?
        self.create(:user_id=>user.id,:reputation_action_id=>reputation_action.id,:value=>reputation_action.value)
        self.update_user_rep(user,reputation_action.value)
      end
    end
  end
end

.update_user_rep(user, value) ⇒ Object



17
18
19
20
21
22
23
# File 'app/models/reputation.rb', line 17

def self.update_user_rep(user,value)
  if SocialEngineYetting.reputation["update_user_model"]
    rep_field = SocialEngineYetting.reputation["user_model_rep_field_name"].to_s.to_sym
    new_rep_value = user.send(rep_field).to_i + value
    user.update_attributes(rep_field=>new_rep_value)
  end
end