Fix Lib StudyManager: 若離開學習點時沒有進去資料,則送出例外。 API: 如果離開學習點時,沒有進入資料,則當成進去一次之後馬上出來
This commit is contained in:
parent
1d27342152
commit
66a7d03b4d
@ -1100,7 +1100,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
||||
});
|
||||
|
||||
/*
|
||||
* 進入此學習點
|
||||
* 離開此學習點
|
||||
* POST http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}/toout
|
||||
*/
|
||||
$app->post('/:token/activitys/:said/points/:tid/toout', function ($token, $saId, $tId) use ($app) {
|
||||
@ -1117,15 +1117,32 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
||||
if($sact->getUserId() == $user_id) {
|
||||
|
||||
// 離開學習點
|
||||
$sact->toOutTarget($tId);
|
||||
try {
|
||||
$sact->toOutTarget($tId);
|
||||
|
||||
// 噴出結果
|
||||
$app->render(201,array(
|
||||
'token' => $token,
|
||||
'user_id' => $user_id,
|
||||
'activity_id' => $sact->getId(),
|
||||
'error' => false
|
||||
));
|
||||
// 噴出結果
|
||||
$app->render(201,array(
|
||||
'token' => $token,
|
||||
'user_id' => $user_id,
|
||||
'activity_id' => $sact->getId(),
|
||||
'error' => false
|
||||
));
|
||||
}
|
||||
// 如果此標的尚未登記為已進入
|
||||
catch (Exception\NoInLearningException $e) {
|
||||
// 當作進去此標的
|
||||
// TODO: 這邊先暫時當成是以實體方式進入,之後要修成Client發出離開訊息時,也一併帶入剛剛的為實體or虛擬
|
||||
$sact->toInTarget($tId, true);
|
||||
$sact->toOutTarget($tId);
|
||||
|
||||
// 噴出結果
|
||||
$app->render(201,array(
|
||||
'token' => $token,
|
||||
'user_id' => $user_id,
|
||||
'activity_id' => $sact->getId(),
|
||||
'error' => false
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
// 若非本人所有,則視同無此活動
|
||||
|
@ -39,7 +39,7 @@ class StudyNoFoundException extends \UnexpectedValueException {
|
||||
}
|
||||
|
||||
/**
|
||||
* 正在學習中例外(難道使用者有分身?)
|
||||
* 正在學習點內學習中例外(難道使用者有分身?)
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
@ -55,6 +55,23 @@ class InLearningException extends \UnexpectedValueException {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不在學習點內的例外
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
class NoInLearningException extends \UnexpectedValueException {
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param int $id 輸入的標的ID
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('NoInLearning');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 沒有找到此活動
|
||||
* @since 2.0.0
|
||||
|
@ -485,7 +485,7 @@ class StudyActivity {
|
||||
try{
|
||||
return $sct->toInTarget($saId, $target_id, $is_entity);
|
||||
}
|
||||
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
|
||||
// 若狀態為正在標的內學習時,送出例外
|
||||
catch (Exception\InLearningException $e) {
|
||||
throw $e;
|
||||
}
|
||||
@ -496,6 +496,7 @@ class StudyActivity {
|
||||
* 離開標的
|
||||
*
|
||||
* @param int $target_id 標的編號
|
||||
* @throw UElearning\Exception\NoInLearningException
|
||||
*/
|
||||
public function toOutTarget($target_id) {
|
||||
|
||||
|
@ -100,6 +100,7 @@ class StudyManager {
|
||||
*
|
||||
* @param int $activity_id 活動編號
|
||||
* @param int $target_id 標的編號
|
||||
* @throw UElearning\Exception\NoInLearningException
|
||||
*/
|
||||
public function toOutTarget($activity_id, $target_id) {
|
||||
|
||||
@ -124,5 +125,8 @@ class StudyManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception\NoInLearningException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user