function votingapi_vote_handler in Voting API 5
File
- ./
votingapi_actions.inc, line 154
Code
function votingapi_vote_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
// 'function' => 'average', // a single aggregate function
// '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;
}
}
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'),
);
$form['tag'] = array(
'#type' => 'select',
'#options' => _votingapi_distinct_values('tag'),
);
$form['comparison'] = array(
'#type' => 'select',
'#options' => array(
'==' => 'Is',
'!=' => 'Is not',
'<' => 'Is less than',
'>' => 'Is greater than',
),
);
$form['value'] = array(
'#type' => 'textfield',
'#maxlength' => 10,
);
return $form;
}
else {
if ($op == 'name') {
return array(
'votingapi_vote_handler' => 'Individual vote properties',
);
}
}
}
}