新增Study\StudyActivity功能: 查詢此標的是否已學過&進出標的

This commit is contained in:
Yuan Chiu 2015-01-17 03:31:16 +08:00
parent 5b7feb1332
commit c0cd1e8d0c
3 changed files with 98 additions and 13 deletions

View File

@ -79,10 +79,14 @@ function login($user_id = null) {
$user = $session->getUser($loginToken);
$sessionInfo = $session->getTokenInfo($loginToken);
//取得現在時間,用字串的形式
$nowDate = date("Y-m-d H:i:s");
// 輸出結果
$app->render(201,array(
'user_id' => $user_id,
'token' => $loginToken,
'browser' => $browser,
'user_id' => $user_id,
'token' => $loginToken,
'browser' => $browser,
'user' => array(
'id' => $user->getId(),
'user_id' => $user->getId(),
@ -101,10 +105,11 @@ function login($user_id = null) {
'email' => $user->getEmail(),
'memo' => $user->getMemo(),
),
'login_time' => $sessionInfo['login_date'],
'error' => false,
'msg' => '\''.$user_id.'\' is logined',
'msg_cht' => '\''.$user_id.'\'使用者已登入'
'login_time' => $sessionInfo['login_date'],
'current_time' => $nowDate,
'error' => false,
'msg' => '\''.$user_id.'\' is logined',
'msg_cht' => '\''.$user_id.'\'使用者已登入'
));
}
catch (Exception\UserNoFoundException $e) {
@ -932,15 +937,14 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
$sct = new Study\StudyManager();
// 進入學習點
try{
$sid = $sct->toInTarget($saId, $tId, $is_entity);
$sid = $sact->toInTarget($tId, $is_entity);
}
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
catch (Exception\InLearningException $e) {
$sct->toOutTarget($saId, $tId);
$sid = $sct->toInTarget($saId, $tId, $is_entity);
$sact->toOutTarget($tId);
$sid = $sact->toInTarget($tId, $is_entity);
}
// 噴出結果
@ -996,9 +1000,8 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
$sct = new Study\StudyManager();
// 離開學習點
$sct->toOutTarget($saId, $tId);
$sact->toOutTarget($tId);
// 噴出結果
$app->render(201,array(
@ -1058,9 +1061,14 @@ else {
// API首頁
$app->get('/', 'APIrequest', function () use ($app) {
//取得現在時間,用字串的形式
$nowDate = date("Y-m-d H:i:s");
$app->render(200, array(
'title' => '',
'version' => '2.0',
'current_time' => $nowDate,
'error' => false,
));
});

View File

@ -8,6 +8,7 @@ namespace UElearning\Study;
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
require_once UELEARNING_LIB_ROOT.'/User/User.php';
require_once UELEARNING_LIB_ROOT.'/Study/Theme.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
use UElearning\Exception;
@ -422,4 +423,61 @@ class StudyActivity {
return $this->queryResultArray['material_mode'];
}
// ========================================================================
/**
* 此標的是否已學習過
*
* @param string $target_id 標的編號
* @return bool 是否已學習過
*/
public function isTargetLearned($target_id) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
return $sct->isTargetLearned($saId, $target_id);
}
/**
* 進入標的
*
* @param int $target_id 標的編號
* @param bool $is_entity 是否為現場學習
* @throw UElearning\Exception\InLearningException
* return int 進出紀錄編號
*/
public function toInTarget($target_id, $is_entity) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
// 進入學習點
try{
return $sct->toInTarget($saId, $target_id, $is_entity);
}
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
catch (Exception\InLearningException $e) {
throw $e;
}
}
/**
* 離開標的
*
* @param int $target_id 標的編號
*/
public function toOutTarget($target_id) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
// 離開學習點
$sct->toOutTarget($saId, $target_id);
}
}

View File

@ -43,6 +43,25 @@ class StudyManager {
return $db->getCurrentInStudyId($activity_id);
}
/**
* 此標的是否已學習過
*
* @param int $activity_id 活動編號
* @param string $target_id 標的編號
* @return bool 是否已學習過
*/
public function isTargetLearned($activity_id, $target_id) {
$db = new Database\DBStudy();
$query = $db->getAllStudyIdByTargetId($activity_id, $target_id);
if(count($query) > 0) {
return true;
}
else {
return false;
}
}
/**
* 進入標的
*