function apps_vote_for_app in Apps 7
Menu callback - this will be hit via an AJAX call to a menu hook
Parameters
$server is the machine name of the server:
$app is the machine name of the app:
$vote is a number between 0 and 100 representing the percentage vote:
1 string reference to 'apps_vote_for_app'
- apps_menu in ./
apps.module - Implements hook_menu().
File
- ./
apps.voting.inc, line 16 - Adds voting component for Apps. Each client site will be able to submit one vote, which is tied to their site cliet id. Has a corresponding file and component in the Appserver module.
Code
function apps_vote_for_app($server, $app, $vote) {
apps_include('manifest');
//get out client id
$id = apps_client_id();
//get our appserver url
$server = apps_servers($server);
$url = $server['manifest'];
//unfortunately server includes the full url, which we don't actuall need, so we need to just get the domain
$parts = parse_url($url);
if ($parts) {
$port = isset($parts['port']) ? ':' . $parts['port'] : '';
$url = $parts['scheme'] . '://' . $parts['host'] . $port;
$url .= APPS_VOTING_PATH . $app . '/' . $vote;
$result = drupal_http_request($url, array(
'data' => 'client_id=' . $id,
));
if ($result->code == '200') {
$output = json_decode($result->data);
//record our vote
if (lock_acquire('apps_voting_config')) {
$user_votes = variable_get('apps_user_ratings', array());
$user_votes[$server['name']][$app] = $vote;
variable_set('apps_user_ratings', $user_votes);
lock_release('apps_voting_config');
}
}
else {
$output = array(
'error' => 'Server connection failed, vote could not be saved.',
);
}
}
else {
$output = array(
'error' => 'Server URL failed to parse: ' . $url,
);
}
drupal_json_output($output);
}