function userpoints_action_grant_points in User Points 7.2
Same name and namespace in other branches
- 5.3 userpoints_workflow_ng.module \userpoints_action_grant_points()
- 6 userpoints_rules.rules.inc \userpoints_action_grant_points()
- 7 userpoints_rules.rules.inc \userpoints_action_grant_points()
Rules action - grant points to a user.
File
- userpoints_rules/
userpoints_rules.rules.inc, line 157 - Provide better integration into the rules group
Code
function userpoints_action_grant_points($params) {
// The passed in $entity is the unwrapped object. To get type and id, we need
// the wrapped version of it.
$state = $params['state'];
$entity = $state->currentArguments['entity'];
$transaction = userpoints_grant_points($params['operation'], $params['points'], $params['type']->name)
->setUid(is_object($params['user']->uid) ? $params['user']
->getIdentifier() : $params['user']->uid)
->setTid($params['tid'])
->setDescription($params['description'])
->setReference($params['reference'])
->setDisplay($params['display']);
if ($entity) {
$transaction
->setEntity($entity
->type(), $entity
->getIdentifier());
}
if ($params['moderate'] != 'default') {
if ($params['moderate'] == 'approved') {
$transaction
->approve();
}
else {
$transaction
->pending();
}
}
if ($params['expirydate']) {
$transaction
->setExpiryDate($params['expirydate']);
}
$transaction
->save();
}