Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

................................................................................................................................................................................
/**
 * 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

 *  * @return $return_set global array returns the template dataitems–> 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

        $db = new DBLayer( 'lib' );

        

$(Object name) = new  Database class('database you want to access')

         // 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;

         }

    }

 $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

 *

 * @return $return_set global array returns the template data

 */

function achievements_hook_return_global()

 {

    global $return$global_setname;

     return $return_setglobal 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
 *
 * @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;
     }
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 from Global Hook.

 *
 * 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'];
     }
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
 *
 * @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;
     }   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 $return$global_setname;
     global $var$local_setname;
     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'] ) );
        
         //

        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
        @$var_set['app_key'] = $row['AccessToken'];
        
         //      
.................statements...................

      
       here you can set the host where this plugin is set        $var

         $local_setname['host'] = 'localhostHost of the website';
        
         //        here we get the stats of the character

        $ref$local_set name =call local hook _to get _ player _stat( $var_set['character'] stats (character );
        
         //         here we have set items that are required to get the achivementsachievements
        // these are player stats from webig->players table

        @$var$local_setname['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'] ) );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)

        $var$local_setname['url'] = 'http://localhost6url to the application/?search=achievements&&format=json';
         }      
    else
         {
        $return_set['no_char'] = "Please Generate key for a character before requesting for achievements";
         }
    }         return response;        
    }

................................................................................................................................................................................