Achievements plugin integrated with ams
This commit is contained in:
parent
b756f128ba
commit
c23e441881
3 changed files with 223 additions and 0 deletions
|
@ -0,0 +1,8 @@
|
|||
PluginName = Achievements
|
||||
Description = Returns the achivements of a user with respect to the character =.
|
||||
Version = 1.0.0
|
||||
TemplatePath = ../../../ams_lib/plugins/Achievements/templates/index.tpl
|
||||
Type = Manual
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Global and Local Hooks for the Achievements plugin
|
||||
* Global Hooks are defined with the prefix(name of the plugin)
|
||||
* Local Hooks are defined with normal function name
|
||||
*
|
||||
* All the Global Hooks are called during the page load
|
||||
* and Local Hooks are called according to conditions
|
||||
*
|
||||
* Here, we request to the Achievements url using REST
|
||||
* to get the contents and will display with this plugin.
|
||||
*
|
||||
* @author shubham meena mentored by Matthew Lagoe
|
||||
*/
|
||||
|
||||
|
||||
// Global variables to store the data
|
||||
$return_set = array();
|
||||
$var_set = array();
|
||||
|
||||
|
||||
/**
|
||||
* Display hook for Achievements plugin
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @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 set variables which contains
|
||||
* the content to use during the plugin functionality.
|
||||
*/
|
||||
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 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 data
|
||||
*/
|
||||
function achievements_hook_call_rest()
|
||||
{
|
||||
// defined the variables
|
||||
global $var_set;
|
||||
global $return_set;
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global Hook to return global variables which contains
|
||||
* the content to use in the smarty templates extracted from
|
||||
* the database
|
||||
*
|
||||
* @return $return_set global array returns the template data
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_set;
|
||||
return $return_set;
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
{block name=content}
|
||||
|
||||
{if isset($smarty.get.plugin_action) and $smarty.get.plugin_action eq 'get_achievements'}
|
||||
<div class="row-fluid">
|
||||
<div class="box span12">
|
||||
<div class="box-header well" data-original-title>
|
||||
<h2><i class="icon-user"></i> Achievements</h2>
|
||||
<div class="box-icon">
|
||||
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
|
||||
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
|
||||
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if isset($smarty.get.success) and $smarty.get.success eq '1'}<div class="alert alert-error"><p>Key added successfully</p></div>{/if}
|
||||
{if isset($smarty.get.success) and $smarty.get.success eq '2'}<div class="alert alert-error"><p>Key deleted successfully</p></div>{/if}
|
||||
<div class="box-content">
|
||||
<div class="row-fluid">
|
||||
{$hook_info.Achievements.char_achievements}
|
||||
</div>
|
||||
</div><!--/span-->
|
||||
</div><!--/span-->
|
||||
</div><!--/row-->
|
||||
{else}
|
||||
<div class="row-fluid">
|
||||
<div class="box span12">
|
||||
<div class="box-header well" data-original-title>
|
||||
<h2><i class="icon-user"></i> Achievements</h2>
|
||||
<div class="box-icon">
|
||||
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
|
||||
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
|
||||
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box span4">
|
||||
<div class="box-header well" data-original-title="">
|
||||
<h2><i class="icon-th"></i> Select your Character</h2>
|
||||
<div class="box-icon">
|
||||
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
|
||||
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-content">
|
||||
<div class="row-fluid">
|
||||
<form id="generateKey" class="form-vertical" method="post" action="index.php?page=layout_plugin&&name={$arrkey}&&plugin_action=get_achievements">
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group">
|
||||
<label class="control-label">Character:</label>
|
||||
<div class="controls">
|
||||
<select name="Character">
|
||||
{foreach from=$hook_info.Achievements.characters item=element}
|
||||
<option value="{$element.char_name}">{$element.char_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label"></label>
|
||||
<div class="controls">
|
||||
<button type="submit" name="get_data" value="true" class="btn btn-primary" style="margin-left:5px; margin-top:10px;">Get Achievements</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div><!--/span-->
|
||||
</div><!--/span-->
|
||||
</div><!--/row-->
|
||||
|
||||
{/if}
|
||||
{/block}
|
Loading…
Reference in a new issue