function userpoints_action_grant_points in User Points 7
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.2 userpoints_rules/userpoints_rules.rules.inc \userpoints_action_grant_points()
Rules action - grant points to a user.
File
- ./
userpoints_rules.rules.inc, line 175 - 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'];
// Map $moderate value to the actual value used by the API.
$moderate_mapping = array(
'default' => NULL,
'approved' => FALSE,
'moderated' => TRUE,
);
$params = array(
// User id might be a int or a EntityValueWrapper.
'uid' => is_object($params['user']->uid) ? $params['user']
->getIdentifier() : $params['user']->uid,
'entity_type' => $entity ? $entity
->type() : NULL,
'entity_id' => $entity ? $entity
->getIdentifier() : NULL,
'moderate' => $moderate_mapping[$params['moderate']],
// Rules defaults to FALSE if the date format can not be parsed.
// Use NULL instead since FALSE means no expiration.
'expirydate' => $params['expirydate'] ? $params['expirydate'] : NULL,
) + $params;
unset($params['state']);
unset($params['user']);
unset($params['entity']);
unset($params['settings']);
userpoints_userpointsapi($params);
}