I am trying to use the Voting API module to add a vote through a menu item. Meaning that when someone visits a menu item [the/menu/item
] a vote is added to the database.
There is already the Voting API functions that does that. I don't understand what the votingapi_set_votes
function in the Voting API module does.
I have read the website documentation however I don't understand what it does and how can I use it. And couldn't find an example of usage either.
I have tried the follwing to add a vote:
$items['the/menu/path/1'] = array
(
'title' => 'Some title',
'page callback' => 'my_page',
'access callback' => TRUE
);
return $items;
}
function my_page(){
$votes = array();
$votes[] = array(
'content_type' => 'news',
'content_id' => 1025,
'value_type' => 'points',
'value' => '1',
);
$criteria = array(
'content_type' => 'news',
'content_id' => 1025,
'function' => 'sum',
'value_type' => 'points',
);
if (TRUE) {
if (module_exists('votingapi')) {
// die("test");
votingapi_set_votes($votes);
die();
$result = (votingapi_select_results($criteria));
print 'result is: '.$result[0][value];
$result = '';
}
}
return "true";
}
But it gives me an SQL error like so:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content_type' in 'where clause': SELECT votingapi_vote.* FROM {votingapi_vote} votingapi_vote WHERE (content_type = :db_condition_placeholder_0) AND (content_id = :db_condition_placeholder_1) AND (value_type = :db_condition_placeholder_2) AND (uid = :db_condition_placeholder_3) ; Array ( [:db_condition_placeholder_0] => news [:db_condition_placeholder_1] => 1025 [:db_condition_placeholder_2] => points [:db_condition_placeholder_3] => 130 ) in votingapi_votingapi_storage_select_votes() (line 225 of C:\Users\tarek.ismail\public\egyptinnovate\sites\all\modules\contrib\votingapi\votingapi.module).