Add API: 取得此活動中所有的標的資料

This commit is contained in:
Yuan Chiu 2014-12-29 03:02:20 +08:00
parent 8593d6327f
commit fb0e41d0c1
2 changed files with 74 additions and 2 deletions

View File

@ -7,8 +7,10 @@ require_once UELEARNING_LIB_ROOT.'/User/UserSession.php';
require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php'; require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php'; require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php'; require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php';
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
use UElearning\User; use UElearning\User;
use UElearning\Study; use UElearning\Study;
use UElearning\Target;
use UElearning\Exception; use UElearning\Exception;
$app = new \Slim\Slim(array( $app = new \Slim\Slim(array(
@ -700,6 +702,68 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
$app->get('/:token/will/:swid', function ($token, $swId) use ($app) { $app->get('/:token/will/:swid', function ($token, $swId) use ($app) {
// TODO: 學習中狀況資料 // TODO: 學習中狀況資料
}); });
// ------------------------------------------------------------------------
/*
* 取得此活動中所有的標的資料
* GET http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points
*/
$app->get('/:token/activitys/:said/points', function ($token, $saId) use ($app) {
try {
// 查詢使用者
$session = new User\UserSession();
$user_id = $session->getUserId($token);
// 取得開始後的學習活動資訊
$sact = new Study\StudyActivity($saId);
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
// 取得此活動的主題
$tid = $sact->getThemeId();
// 取得主題內所有的標的資訊
$target_manager = new Target\TargetManager();
$all_targets = $target_manager->getAllTargetInfoByTheme($tid);
// 噴出結果
$app->render(200,array(
'token' => $token,
'user_id' => $user_id,
'activity_id' => $sact->getId(),
'targets' => $all_targets,
'error' => false
));
}
// 若非本人所有,則視同無此活動
else {
throw new Exception\StudyActivityNoFoundException($saId);
}
}
catch (Exception\LoginTokenNoFoundException $e) {
$app->render(401,array(
'token' => $token,
'error' => true,
'msg' => 'No \''.$token.'\' session. Please login again.',
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
'substatus' => 204
));
}
catch (Exception\StudyActivityNoFoundException $e) {
$app->render(404,array(
'token' => $token,
'error' => true,
'msg' => 'No found this activity.',
'msg_cht' => '沒有此學習活動'
));
}
});
}); });
// ============================================================================ // ============================================================================

View File

@ -146,13 +146,17 @@ class DBTarget extends Database {
public function queryAllTargetByTheme($thID) { public function queryAllTargetByTheme($thID) {
$sqlString = "SELECT `ThID`, Target.`TID`, `Weights`, ". $sqlString = "SELECT `ThID`, Target.`TID`, `Weights`, ".
"Target.`AID`, Area.`HID`, `TNum`, `TName`, `TMapID`, `TLearnTime`, ". "Area.`HID`, Hall.`HName`, ".
"Target.`AID`, Area.`AName`, Area.`AFloor`, Area.`ANum`, ".
"`TNum`, `TName`, `TMapID`, `TLearnTime`, ".
"`PLj`, `Mj`, `S`, IF(`Mj` >= `PLj`, 1, 0) AS Fj ". "`PLj`, `Mj`, `S`, IF(`Mj` >= `PLj`, 1, 0) AS Fj ".
"FROM `".$this->table('TBelong')."` AS Belong ". "FROM `".$this->table('TBelong')."` AS Belong ".
"LEFT JOIN `".$this->table('Target')."` as Target ". "LEFT JOIN `".$this->table('Target')."` as Target ".
"ON Belong.`TID` = Target.`TID` ". "ON Belong.`TID` = Target.`TID` ".
"LEFT JOIN `".$this->table('Area')."` as Area ". "LEFT JOIN `".$this->table('Area')."` as Area ".
"ON Area.`AID` = Target.`AID` ". "ON Area.`AID` = Target.`AID` ".
"LEFT JOIN `".$this->table('Hall')."` as Hall ".
"ON Area.`HID` = Hall.`HID`".
"WHERE `ThID` = ".$this->connDB->quote($thID); "WHERE `ThID` = ".$this->connDB->quote($thID);
$query = $this->connDB->prepare($sqlString); $query = $this->connDB->prepare($sqlString);
@ -169,8 +173,12 @@ class DBTarget extends Database {
array( 'theme_id' => $thisResult['ThID'], array( 'theme_id' => $thisResult['ThID'],
'target_id' => $thisResult['TID'], 'target_id' => $thisResult['TID'],
'weights' => $thisResult['Weights'], 'weights' => $thisResult['Weights'],
'area_id' => $thisResult['AID'],
'hall_id' => $thisResult['HID'], 'hall_id' => $thisResult['HID'],
'hall_name' => $thisResult['HName'],
'area_id' => $thisResult['AID'],
'area_name' => $thisResult['AName'],
'floor' => $thisResult['AFloor'],
'area_number' => $thisResult['ANum'],
'target_number' => $thisResult['TNum'], 'target_number' => $thisResult['TNum'],
'name' => $thisResult['TName'], 'name' => $thisResult['TName'],
'map_url' => $thisResult['TMapID'], 'map_url' => $thisResult['TMapID'],