module for automatically vote
anrn - May 23, 2009 - 20:09
| Project: | Voting API |
| Version: | 6.x-2.0-rc2 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
I create a module for automatically vote after comment. I use votingapi module for check and storage data, but results don’t register to content (don’t storage for every comment).
Example of code:
<?php
// it’s form validation for insert vote
function tcomment_vote($form, &$form_state, $nid) {
$clicked = $form_state['clicked_button']['#value'];
switch ($clicked) {
case 'yes':
$votes[] = array(
'content_type' => 'comment',
'content_id' => $cid, 'value_type' => 'points',
'value' => 1,
);
break;
case 'no':
$votes[] = array(
'content_type' => 'comment',
'content_id' => $cid,
'value_type' => 'points',
'value' => -1,
);
break;
}
votingapi_set_votes($votes);
$criteria = array(
'content_type' => 'comment',
'content_id' => $cid,
'value_type' => 'points',
);
}
// check results (after hook form)
function tcomment_select_votes() {
$criteria = array(
'content_type' => 'comment',
'content_id' => $cid,
'value_type' => 'points',
);
$results = (int)votingapi_select_single_result_value($criteria);
drupal_set_message('RESULT' . $results);
}
// Only last result had here, one for every comment
?>Please, help, what I wrong?
