Account Management System:Achievements Plugin Hooks

 


This page contains the hooks for Achievements plugin developed for AMS.

Global Variables:

$global_name = array();

This variable will contain the Achievements data and will be returned after going through all hooks.

Local Variables:

$local_name = array();

This variable will contains the data which are going to be used in hook actions and storing POST and GET data or other server requests.

Global Hooks:

Now, here comes the Global hooks working in Achievements plugin with description.

 

/**
 * Display hook for Achievements plugin
 */
function achievements_hook_display()
 {
    global $global_name;
     // to display plugin name in menu bar
    $global_name['menu_display'] = 'Achievements';

     }
/**
 * Global Hook to interact with the REST api
 * Pass the variables in the REST object to
 * make request
 *
 * variables REST object expects
 * url --> on which request is to be made
 * appkey --> app key for authentication
 * host --> host from which request have been sent
 * items–> Data which you want to send

 */
function achievements_hook_call_rest()
 {
    // defined the variables
    global $local_name;
     global $global_name;
    
     if  request is sent from server to interact with REST
        call local hook  to set data getting through request
        hook_local_name();
      .........................................
         // here we have created the REST connection
        $object  = new REST class();
    ............................................
        //sending data using REST by calling it's request function
         $(Response from REST) =  $(REST object) -> (REST function request)( 'url' , 'app_key' , 'host' , 'items'  );
     ............................................
        // here we store the response we get from the server
        $global_name[ identifier ] = $Response is then set to global variable ;
         }
    }
/**
 * Global Hook to interact with the database
 */
function achievements_hook_get_db()
 {
    global $global_name;
   ............................................
      if (session is set for  user)
         {
        //creating object for the database
        $(Object name) = new  Database class('database you want to access')
         // getting content for selecting characters
       
 $statement object = $(object name) -> (select function from Database
 class)( 'field to select', 'table name', array( data to use with WHERE 
clause ) , 'WHERE clause' );
    ........statements.......................
         set all the data fetched to the Global variable
         }
    }
/**
 * Global Hook to return global variables which contains
 * the content to use in the smarty templates
 */
function achievements_hook_return_global()
 {
    global $global_name;
     return global variable;
     }

 

Local Hooks:

Here , we have written pseudo code for local Hooks

/**
 * 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
 * 
 */
function hook_get_db_content( $data )
 {
    create an object to the Database layer;
                    ....
    queries to get the key wrt user;

    ............statements................... 
  
    return the data;
     }
/**
 * Local Hook to get database content by
 * passing a parameter from Global Hook. *
 * This hook returns the id of the character 
 * whose achievements we have to get
 */
function hook_get_char_id( $data )
 {
    create an object to the Database layer;
                    ....
    queries to get the key wrt user;

    ............statements................... 
  
    return the data;
    
     }
/**
 * 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
 */
function hook_get_player_stat( $data )
 {   create an object to the Database layer;
                    ....
    queries to get the key wrt user;

    ............statements................... 
  
    return the data;
   
     }
/**
 * Local Hook to set variables which contains
 * the content to use during the plugin functionality.
 */
function hook_variable_set()
 {
    global $global_name;
     global $local_name;             Adding character  to the local variable.
.................statements
         
        call local hook to get the character id and store it in local variable.
..................statements..................
       
        call local hook to get the character details from database.
..................statements..................
       access key automatically taken from the database wrt user and character
      
.................statements...................
        
       here you can set the host where this plugin is set
         $local_name['host'] = 'Host of the website';
        
       here we get the stats of the character
        $local_name =call local hook to get player stats (character );
        
        here we have set items that are required to get the achievements
        these are player stats from webig->players table
        $local_name['items'] = json_encode( data )
        
         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)
        $local_name['url'] = 'http://url to the application/?search=achievements&&format=json';
      
    else
        return response;         
    }