Merge branch 'develop' of github.com:CHU-TDAP/E-learning-Server-v2 into develop

Conflicts:
	htdocs/api/v2/index.php
This commit is contained in:
Yuan Chiu 2015-02-05 15:34:12 +08:00
commit 345e83e160
2 changed files with 120 additions and 32 deletions

View File

@ -10,12 +10,12 @@ require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php'; require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php';
require_once UELEARNING_LIB_ROOT.'/Target/Target.php'; require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php'; require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
require_once UELEARNING_LIB_ROOT.'/Recommand/RecommandPoint.php'; require_once UELEARNING_LIB_ROOT.'/Database/DBInfo.php';
use UElearning\User; use UElearning\User;
use UElearning\Study; use UElearning\Study;
use UElearning\Target; use UElearning\Target;
use UElearning\Recommand;
use UElearning\Exception; use UElearning\Exception;
use UElearning\Database;
$app = new \Slim\Slim(array( $app = new \Slim\Slim(array(
'templates.path' => './', // 設定Path 'templates.path' => './', // 設定Path
@ -1033,27 +1033,12 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
// 進入學習點 // 進入學習點
try{ try{
$sid = $sact->toInTarget($tId, $is_entity); $sid = $sact->toInTarget($tId, $is_entity);
// 噴出結果
$app->render(200,array(
'token' => $token,
'user_id' => $user_id,
'activity_id' => $sact->getId(),
'study_id' => $sid,
'error' => false
));
} }
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入 // 若狀態為正在標的內學習時,強制當成離開標的,重新進入
catch (Exception\InLearningException $e) { catch (Exception\InLearningException $e) {
$sact->toOutTarget($tId);
// 查詢目前所在的標的
$inTId = $sact->getCurrentInTarget();
// 登記離開此標的
$sact->toOutTarget($inTId);
// 重新登記進入此標的
$sid = $sact->toInTarget($tId, $is_entity); $sid = $sact->toInTarget($tId, $is_entity);
}
// 噴出結果 // 噴出結果
$app->render(200,array( $app->render(200,array(
@ -1063,7 +1048,6 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
'study_id' => $sid, 'study_id' => $sid,
'error' => false 'error' => false
)); ));
}
} }
// 若非本人所有,則視同無此活動 // 若非本人所有,則視同無此活動
@ -1191,8 +1175,8 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
$currentTId = (int)$currentTId; $currentTId = (int)$currentTId;
$tid = $sact->getThemeId(); // 取得此活動的主題 // 取得此活動的主題
$maxItemTotal = $sact->getLearnStyle(); // 取得最大推薦數 $tid = $sact->getThemeId();
// 取得本次採用的教材風格 // 取得本次採用的教材風格
$materialMode = $sact->getMaterialStyle(); $materialMode = $sact->getMaterialStyle();
@ -1229,8 +1213,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
'user_id' => $user_id, 'user_id' => $user_id,
'activity_id' => $sact->getId(), 'activity_id' => $sact->getId(),
'current_target_id' => $currentTId, 'current_target_id' => $currentTId,
'is_end' => $isEnd, 'recommand_total' => $recommand_total,
'recommand_total' => $result_recommand_total,
'recommand_target' => $output_targets, 'recommand_target' => $output_targets,
'error' => false 'error' => false
)); ));
@ -1274,6 +1257,26 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
// ============================================================================ // ============================================================================
/*
* 推薦學習點
* GET http://localhost/api/v2/info
*/
$app->get('/info', 'APIrequest', function () use ($app) {
$db = new Database\DBInfo();
$placeInfoResult = $db->queryAllPlaceInfo();
$placeMapResult = $db->queryALLPlaceMap();
// 噴出結果
$app->render(200,array(
'place_info' => $placeInfoResult,
'place_map' => $placeMapResult,
'error' => false
));
});
// ============================================================================
// 取得Client要求的格式 // 取得Client要求的格式
$requestType = $app->request->headers->get('Accept'); $requestType = $app->request->headers->get('Accept');
// 若要求網頁版 // 若要求網頁版

View File

@ -0,0 +1,85 @@
<?php
/**
* DBTarget.php
*
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料庫查詢用。
*/
namespace UElearning\Database;
use UElearning\Exception;
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
/**
* 學習標的資料表
*
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料表進行操作。
*
*
* @author Yuan Chiu <chyuaner@gmail.com>
* @version 2.0.0
* @package UElearning
* @subpackage Database
*/
class DBInfo extends Database {
public function queryAllPlaceInfo() {
$sqlString = "SELECT * FROM `".$this->table('PlaceInfo')."` WHERE 1";
$query = $this->connDB->prepare($sqlString);
$query->execute();
$queryResultAll = $query->fetchAll();
// return $queryResultAll;
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
// 製作回傳結果陣列
$result = array();
foreach($queryResultAll as $key => $thisResult) {
array_push($result,
array( 'id' => $thisResult['IID'],
'name' => $thisResult['IName'],
'content' => $thisResult['IContent']
));
}
return $result;
}
// 若都沒查到的話
else {
return null;
}
}
public function queryALLPlaceMap() {
$sqlString = "SELECT * FROM `".$this->table('PlaceMap')."` WHERE 1";
$query = $this->connDB->prepare($sqlString);
$query->execute();
$queryResultAll = $query->fetchAll();
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
// 製作回傳結果陣列
$result = array();
foreach($queryResultAll as $key => $thisResult) {
array_push($result,
array( 'id' => $thisResult['PID'],
'name' => $thisResult['PName'],
'url' => $thisResult['PURL']
));
}
return $result;
}
// 若都沒查到的話
else {
return null;
}
}
}