Fix API: 重複進入標的時,會將上個已進入紀錄標示為離開

This commit is contained in:
Yuan Chiu 2015-01-26 16:11:21 +08:00
parent 8ba983a999
commit 7c4bf21d93
2 changed files with 42 additions and 11 deletions

View File

@ -1033,21 +1033,37 @@ $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);
$sid = $sact->toInTarget($tId, $is_entity);
}
// 噴出結果 // 查詢目前所在的標的
$app->render(200,array( $inTId = $sact->getCurrentInTarget();
'token' => $token,
'user_id' => $user_id, // 登記離開此標的
'activity_id' => $sact->getId(), $sact->toOutTarget($inTId);
'study_id' => $sid,
'error' => false // 重新登記進入此標的
)); $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; $result_recommand_total = $recommandTotal;
} }
// 是否已經學完了 // 是否已經學完了
// TODO: 改以取得已學習標的數來判定
if($recommandTotal <= 0) { $isEnd = true; } if($recommandTotal <= 0) { $isEnd = true; }
else { $isEnd = false; } else { $isEnd = false; }

View File

@ -438,6 +438,20 @@ class StudyActivity {
// ======================================================================== // ========================================================================
/**
* 取得目前已進入的學習點
*
* @return int 標的編號若無則null
*/
public function getCurrentInTarget() {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
return $sct->getCurrentInTargetId($saId);
}
/** /**
* 此標的是否已學習過 * 此標的是否已學習過
* *