@ -15,10 +15,13 @@
*/
// Global variables to store the data
// Global variable to store the data which is
// returned to the templates
$return_set = array();
$var_set = array();
// Local variable to store data during
// functionalities of the hooks
$var_set = array();
/**
* Display hook for Achievements plugin
@ -28,26 +31,64 @@ function achievements_hook_display()
global $return_set;
// to display plugin name in menu bar
$return_set['menu_display'] = 'Achievements';
}
}
/**
* Local Hook to get database content
* which is called by the global hook
* by passing a parameter
*
* This hook returns the api keys registerd with
* the logged in user
*
* @param $data array with respective information
* @return $row extracted db content wrt $data
*/
function hook_get_db_content( $data )
{
$db = new DBLayer( 'lib' );
$sth = $db -> select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' );
$row = $sth -> fetchAll();
return $row;
}
/**
* Local Hook to get database content
* which is called by the global hook
* by passing a parameter
*
* This hook returns the id of the character
* whose achivements we have to get
*
* @param $data array with respective information
* @return $row extracted db content wrt $data
*/
function hook_get_char_id( $data )
{
// returns the character id with respect to the character name in the ring_tool->characters
$db = new DBLayer( 'ring' );
$sth = $db -> selectWithParameter( 'char_id', 'characters' , array( 'char_name' => $data ), 'char_name=:char_name' );
$row = $sth -> fetch();
return $row['char_id'];
}
/**
* Local Hook to get database content
* which is called by the global hook
* by passing a parameter
*
* Hook to get the player stats of the character
*
* @param $data array with respective information
* @return $row extracted db content wrt $data
*/
function hook_get_player_stat( $data )
{
// returns the character id with respect to the character name in the ring_tool->characters
$db = new DBLayer( 'webig' );
$sth = $db -> select( 'players' , array( 'name' => $data ), 'name=:name' );
$row = $sth -> fetch();
return $row;
}
/**
@ -56,27 +97,44 @@ function hook_get_db_content( $data )
*/
function hook_variable_set()
{
global $var_set;
$var_set['character'] = $_POST['Character'];
// get db content for variable set
$row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) );
// access key automatically taken from the database wrt user and character
@$var_set['app_key'] = $row['AccessToken'];
// here you can set the host where this plugin is set
$var_set['host'] = 'localhost';
// here you can set what you are looking for
// when you are requesting encoded in json
@$var_set['items'] = json_encode( array( 'Task' => 'Achievements', 'Character' => $var_set['character'] ) );
// url where we have to make request for achievements
// it sends get parameter search(what to search) and format(in which format data exchange takes place)
$var_set['url'] = 'app.domain.org?search=' . $var_set['items'] . '&&format=json';
}
global $return_set;
global $var_set;
if ( isset( $_POST['Character'] ) & & !empty( $_POST['Character'] ) )
{
$var_set['character'] = $_POST['Character'];
// get char id from ring_open table
if ( $var_set['character'] != 'All Characters' )
{
$var_set['char_id'] = hook_get_char_id( $var_set['character'] );
}
// get db content for variable set
$row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) );
// access key automatically taken from the database wrt user and character
@$var_set['app_key'] = $row['AccessToken'];
// here you can set the host where this plugin is set
$var_set['host'] = 'localhost';
// here we get the stats of the character
$ref_set = hook_get_player_stat( $var_set['character'] );
// here we have set items that are required to get the achivements
// these are player stats from webig->players table
@$var_set['items'] = json_encode( array( 'dev_shard' => $ref_set['dev_shard'] , 'name' => $ref_set['name'] , 'cid' => $ref_set['cid'] , 'lang' => 'en' , 'translater_mode' => '', 'last_played_date' => $ref_set['last_login'] ) );
// url where we have to make request for achievements
// it sends get parameter search(what to search) and format(in which format data exchange takes place)
$var_set['url'] = 'http://localhost6/?search=achievements&&format=json';
}
else
{
$return_set['no_char'] = "Please Generate key for a character before requesting for achievements";
}
}
/**
* Global Hook to interact with the REST api
@ -99,12 +157,11 @@ function achievements_hook_call_rest()
if ( isset( $_POST['get_data'] ) )
{
hook_variable_set();
$rest_api = new Rest_Api();
$ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'] );
print_r( $ach_data );
$return_set['char_achievements'] = json_decode( $ach_data );
// here we make the REST connection
$rest_api = new Rest_Api();
$ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'], $var_set['items'] );
// here we store the response we get from the server
$return_set['char_achievements'] = $ach_data ;
}
}
@ -119,14 +176,16 @@ function achievements_hook_get_db()
{
global $return_set;
$db = new DBLayer( 'lib' );
// getting content for selecting characters
$sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' );
$row = $sth -> fetchAll();
$retur_set['Character'] = $row;
}
if ( isset( $_SESSION['user'] ) )
{
$db = new DBLayer( 'lib' );
// getting content for selecting characters
$sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' );
$row = $sth -> fetch();
$return_set['Character'] = $row;
}
}
/**
* Global Hook to return global variables which contains
@ -138,5 +197,4 @@ function achievements_hook_return_global()
{
global $return_set;
return $return_set;
}
}