function votingapi_vote_result_handler in Voting API 5
File
- ./
votingapi_actions.inc, line 26
Code
function votingapi_vote_result_handler($op, $content, $votes, $results, $rule) {
if ($op == 'process') {
// for this handler, $rule->data is an array in the following format:
//
// $value = array(
// 'value_type' => 'percent', // an array of 1-n value types.
// 'tag' => 'vote', // an array of 1-n tags
// 'comparison' = '<', // the comparison operator
// 'value' => '90', // the value to be compared
// ),
// );
//
// In the example above, any aggregate vote result in which a piece of content receives an
// average percentage vote between 75% and 90% would match. Obviously, the specific values
// will change based on the specific action. If one of the above values is NOT specified
// it will be skipped.
$data = (object) $rule->data;
$passed = FALSE;
// loop through all the result objects and see if there's one that satisfies all the conditions.
foreach ($results as $result) {
if (isset($data->value_type)) {
if ($result->value_type != $data->value_type) {
continue;
}
}
if (isset($data->tag)) {
if ($result->tag != $data->tag) {
continue;
}
}
if (isset($data->function)) {
if ($result->function != $data->function) {
continue;
}
}
switch ($data->comparison) {
case '<':
if (!($result->value < $data->value)) {
continue;
}
break;
case '<=':
if (!($result->value <= $data->value)) {
continue;
}
break;
case '==':
if (!($result->value == $data->value)) {
continue;
}
break;
case '!=':
if (!($result->value != $data->value)) {
continue;
}
break;
case '>=':
if (!($result->value >= $data->value)) {
continue;
}
break;
case '>':
if (!($result->value > $data->value)) {
continue;
}
break;
}
// if we get this far, one of the result records has passed successfully.
$passed = TRUE;
break;
}
return $passed;
}
else {
if ($op == 'form') {
$form['theme'] = 'votingapi_standard_handler_form';
$form['value_type'] = array(
'#type' => 'select',
'#options' => _votingapi_distinct_values('value_type', 'cache'),
'#default_value' => $content['value_type'],
);
$form['tag'] = array(
'#type' => 'select',
'#options' => _votingapi_distinct_values('tag', 'cache'),
'#default_value' => $content['tag'],
);
$form['function'] = array(
'#type' => 'select',
'#options' => _votingapi_distinct_values('function', 'cache'),
'#default_value' => $content['function'],
);
$form['comparison'] = array(
'#type' => 'select',
'#options' => array(
'==' => 'Is',
'!=' => 'Is not',
'<' => 'Is less than',
'>' => 'Is greater than',
),
'#default_value' => $content['comparison'],
);
$form['value'] = array(
'#type' => 'textfield',
'#maxlength' => 10,
'#default_value' => $content['value'],
);
return $form;
}
}
}