Hi,
I'm using 6, where workflow_ng has been superceded by Rules, so I knocked together the code below. It's very basic, it just duplicates the workflow_ng functionality that's available with UserPoints for 5.x - it could do with some conditions, and would be good if User Points itsself had some Rules events, but it's all I needed for now. Just whack it in userpoints.rules.inc and you'll be able to add points based on Rules events.

//userpoints.rules.inc

/**
 * Rules hook implementation.
 */
function userpoints_rules_action_info() {
   $actions = array();
   $actions['userpoints_action_grant_points'] = array(
      'label' => t('Grant points to a user'),
      'arguments' => array(
        'user' => array('type' => 'user','label' => t('User') )
       ),
      'module' => 'Userpoints',
	  'eval input' => array('points')
  );
  return $actions;
}

/**
 * Rules action - grant points to a user
 */
function userpoints_action_grant_points($user,$settings){
	userpoints_userpointsapi(array('uid' => $user->uid, 'points' => $settings['points']));
}

/**
 * Rules form configuration - allow number of points to be set by the rule
 */
function userpoints_action_grant_points_form($settings = array(), &$form) {

  $form['settings']['points'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of points'),
    '#default_value' => isset($settings['points']) ? $settings['points'] : '',
	'#description' => t('The number of points to award')
  );
}

Comments

kbahey’s picture

@jredding

This would be nice to have in the 6.x version, replacing the workflow_ng one.

But in the past you expressed concern about workflow_ng being in the API tarball.

So, whenever we spin off the userpoints_basic to its own module for D6, I think workflow_ng should go out of the window, and this rules code should be included with userpoints_basic.

If this is going to take some time, then we can take out workflow now and include this, while the spilt is pending.

Any other ideas?

erman_yazid’s picture

But where should i whack this split of code exactly, i can't find the file userpoints.rules.inc

jredding’s picture

wow sorry this slipped by me.

Is rules code better in userpoints_basic? or in with the API?
it seems to me that you'd want it with the API as you could then create rules for anything in the actions/workflows/rules flow.

My concern with having it in the API was that it wasn't maintained and the API is. I'm shooting for a solidly maintained core.

Lucretia9’s picture

Where do I put this file exactly? I've put it in the root of the userpoints module, does seem to be showing up anywhere?

Luke.

pebosi’s picture

StatusFileSize
new1.07 KB
new186 bytes

Nice work, i just created a new module file and inserted your code, after enabling this new module it works :)
See attached files. (remove .txt)

regards

kbahey’s picture

Committed, thanks.

kbahey’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.