From fb0e41d0c1851af7d304e07811eed4b2f838942f Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Mon, 29 Dec 2014 03:02:20 +0800 Subject: [PATCH] =?UTF-8?q?Add=20API:=20=E5=8F=96=E5=BE=97=E6=AD=A4?= =?UTF-8?q?=E6=B4=BB=E5=8B=95=E4=B8=AD=E6=89=80=E6=9C=89=E7=9A=84=E6=A8=99?= =?UTF-8?q?=E7=9A=84=E8=B3=87=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/api/v2/index.php | 64 ++++++++++++++++++++++++++++++++ htdocs/lib/Database/DBTarget.php | 12 +++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 28cb381..5b8eae6 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -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.'/Study/StudyActivity.php'; require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php'; +require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php'; use UElearning\User; use UElearning\Study; +use UElearning\Target; use UElearning\Exception; $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) { // 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' => '沒有此學習活動' + )); + } + }); + }); // ============================================================================ diff --git a/htdocs/lib/Database/DBTarget.php b/htdocs/lib/Database/DBTarget.php index 2213c53..039432f 100644 --- a/htdocs/lib/Database/DBTarget.php +++ b/htdocs/lib/Database/DBTarget.php @@ -146,13 +146,17 @@ class DBTarget extends Database { public function queryAllTargetByTheme($thID) { $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 ". "FROM `".$this->table('TBelong')."` AS Belong ". "LEFT JOIN `".$this->table('Target')."` as Target ". "ON Belong.`TID` = Target.`TID` ". "LEFT JOIN `".$this->table('Area')."` as Area ". "ON Area.`AID` = Target.`AID` ". + "LEFT JOIN `".$this->table('Hall')."` as Hall ". + "ON Area.`HID` = Hall.`HID`". "WHERE `ThID` = ".$this->connDB->quote($thID); $query = $this->connDB->prepare($sqlString); @@ -169,8 +173,12 @@ class DBTarget extends Database { array( 'theme_id' => $thisResult['ThID'], 'target_id' => $thisResult['TID'], 'weights' => $thisResult['Weights'], - 'area_id' => $thisResult['AID'], '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'], 'name' => $thisResult['TName'], 'map_url' => $thisResult['TMapID'],