From 7c4bf21d93756eacf98fbc68ef2bb73c8080dee9 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Mon, 26 Jan 2015 16:11:21 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20API:=20=E9=87=8D=E8=A4=87=E9=80=B2?= =?UTF-8?q?=E5=85=A5=E6=A8=99=E7=9A=84=E6=99=82=EF=BC=8C=E6=9C=83=E5=B0=87?= =?UTF-8?q?=E4=B8=8A=E5=80=8B=E5=B7=B2=E9=80=B2=E5=85=A5=E7=B4=80=E9=8C=84?= =?UTF-8?q?=E6=A8=99=E7=A4=BA=E7=82=BA=E9=9B=A2=E9=96=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/api/v2/index.php | 39 +++++++++++++++++++++--------- htdocs/lib/Study/StudyActivity.php | 14 +++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 930761e..2b82909 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -1033,21 +1033,37 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { // 進入學習點 try{ $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) { - $sact->toOutTarget($tId); - $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 - )); + // 查詢目前所在的標的 + $inTId = $sact->getCurrentInTarget(); + + // 登記離開此標的 + $sact->toOutTarget($inTId); + + // 重新登記進入此標的 + $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 + )); + } } // 若非本人所有,則視同無此活動 @@ -1192,6 +1208,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { $result_recommand_total = $recommandTotal; } // 是否已經學完了 + // TODO: 改以取得已學習標的數來判定 if($recommandTotal <= 0) { $isEnd = true; } else { $isEnd = false; } diff --git a/htdocs/lib/Study/StudyActivity.php b/htdocs/lib/Study/StudyActivity.php index 86d7f47..de99a18 100644 --- a/htdocs/lib/Study/StudyActivity.php +++ b/htdocs/lib/Study/StudyActivity.php @@ -438,6 +438,20 @@ class StudyActivity { // ======================================================================== + /** + * 取得目前已進入的學習點 + * + * @return int 標的編號,若無則null + */ + public function getCurrentInTarget() { + + // 活動編號 + $saId = $this->id; + + $sct = new StudyManager(); + return $sct->getCurrentInTargetId($saId); + } + /** * 此標的是否已學習過 *