XAPI和與HBase伺服器介接

This commit is contained in:
Yuan Chiu 2017-05-20 16:50:46 +08:00
parent 07ff31bdd4
commit fab273a82c
3 changed files with 47 additions and 0 deletions

View File

@ -14,6 +14,8 @@ require_once UELEARNING_LIB_ROOT.'/Database/DBInfo.php';
require_once UELEARNING_LIB_ROOT.'/Database/DBQuestion.php';
require_once UELEARNING_LIB_ROOT.'/Recommand/RecommandPoint.php';
require_once UELEARNING_LIB_ROOT.'/Log/Log.php';
require_once UELEARNING_LIB_ROOT.'/Log/XApi.php';
require_once UELEARNING_LIB_ROOT.'/Util/UEHBase.php';
use UElearning\User;
use UElearning\Study;
use UElearning\Target;
@ -21,6 +23,7 @@ use UElearning\Recommand;
use UElearning\Exception;
use UElearning\Database;
use UElearning\Log;
use UElearning\Util;
$app = new \Slim\Slim(array(
'templates.path' => './', // 設定Path
@ -94,6 +97,20 @@ function login($user_id = null) {
$db_material = new Database\DBMaterial();
$all_material_kind = $db_material->queryAllKind();
// 紀錄進HBase
if(UELEARNING_UEHBASE_ENABLE) {
$xapi = new Log\XApi();
$uname = $user->getName();
$umail = $user->getEmail();
$cname = $user->getClassName();
$lmode = $user->getLearnStyle();
$post_data = $xapi->login($nowDate,$loginToken,$uname,$umail,$cname,$lmode);
$hbase = new Util\UEHBase();
$hbase->sendLog($post_data);
}
// 輸出結果
$app->render(201,array(
'user_id' => $user_id,

View File

@ -125,3 +125,15 @@
* 這份設定檔的路徑
*/
define('UELEARNING_CONFIG_PATH', __FILE__);
// 連接HBase伺服器 =============================================================
/**
* 是否啟用介接學習歷程紀錄伺服器
*/
define('UELEARNING_UEHBASE_ENABLE', false);
/**
* 介接學習歷程紀錄伺服器紀錄模組網址
*/
define('UELEARNING_UEHBASE_URL', 'http://localhost/');

View File

@ -0,0 +1,18 @@
<?php
/**
* UEHBase.php
*/
namespace UElearning\Util;
use GuzzleHttp\Client;
class UEHBase {
public function sendLog($xapi_array)
{
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', UELEARNING_UEHBASE_URL, [
'json' => $result
]);
}
}