新增Study\StudyActivity功能: 查詢此標的是否已學過&進出標的
This commit is contained in:
parent
5b7feb1332
commit
c0cd1e8d0c
@ -79,10 +79,14 @@ function login($user_id = null) {
|
|||||||
$user = $session->getUser($loginToken);
|
$user = $session->getUser($loginToken);
|
||||||
$sessionInfo = $session->getTokenInfo($loginToken);
|
$sessionInfo = $session->getTokenInfo($loginToken);
|
||||||
|
|
||||||
|
//取得現在時間,用字串的形式
|
||||||
|
$nowDate = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
|
// 輸出結果
|
||||||
$app->render(201,array(
|
$app->render(201,array(
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'token' => $loginToken,
|
'token' => $loginToken,
|
||||||
'browser' => $browser,
|
'browser' => $browser,
|
||||||
'user' => array(
|
'user' => array(
|
||||||
'id' => $user->getId(),
|
'id' => $user->getId(),
|
||||||
'user_id' => $user->getId(),
|
'user_id' => $user->getId(),
|
||||||
@ -101,10 +105,11 @@ function login($user_id = null) {
|
|||||||
'email' => $user->getEmail(),
|
'email' => $user->getEmail(),
|
||||||
'memo' => $user->getMemo(),
|
'memo' => $user->getMemo(),
|
||||||
),
|
),
|
||||||
'login_time' => $sessionInfo['login_date'],
|
'login_time' => $sessionInfo['login_date'],
|
||||||
'error' => false,
|
'current_time' => $nowDate,
|
||||||
'msg' => '\''.$user_id.'\' is logined',
|
'error' => false,
|
||||||
'msg_cht' => '\''.$user_id.'\'使用者已登入'
|
'msg' => '\''.$user_id.'\' is logined',
|
||||||
|
'msg_cht' => '\''.$user_id.'\'使用者已登入'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
catch (Exception\UserNoFoundException $e) {
|
catch (Exception\UserNoFoundException $e) {
|
||||||
@ -932,15 +937,14 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
|||||||
// 確認此學習活動是否為本人所有
|
// 確認此學習活動是否為本人所有
|
||||||
if($sact->getUserId() == $user_id) {
|
if($sact->getUserId() == $user_id) {
|
||||||
|
|
||||||
$sct = new Study\StudyManager();
|
|
||||||
// 進入學習點
|
// 進入學習點
|
||||||
try{
|
try{
|
||||||
$sid = $sct->toInTarget($saId, $tId, $is_entity);
|
$sid = $sact->toInTarget($tId, $is_entity);
|
||||||
}
|
}
|
||||||
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
|
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
|
||||||
catch (Exception\InLearningException $e) {
|
catch (Exception\InLearningException $e) {
|
||||||
$sct->toOutTarget($saId, $tId);
|
$sact->toOutTarget($tId);
|
||||||
$sid = $sct->toInTarget($saId, $tId, $is_entity);
|
$sid = $sact->toInTarget($tId, $is_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 噴出結果
|
// 噴出結果
|
||||||
@ -996,9 +1000,8 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
|||||||
// 確認此學習活動是否為本人所有
|
// 確認此學習活動是否為本人所有
|
||||||
if($sact->getUserId() == $user_id) {
|
if($sact->getUserId() == $user_id) {
|
||||||
|
|
||||||
$sct = new Study\StudyManager();
|
|
||||||
// 離開學習點
|
// 離開學習點
|
||||||
$sct->toOutTarget($saId, $tId);
|
$sact->toOutTarget($tId);
|
||||||
|
|
||||||
// 噴出結果
|
// 噴出結果
|
||||||
$app->render(201,array(
|
$app->render(201,array(
|
||||||
@ -1058,9 +1061,14 @@ else {
|
|||||||
|
|
||||||
// API首頁
|
// API首頁
|
||||||
$app->get('/', 'APIrequest', function () use ($app) {
|
$app->get('/', 'APIrequest', function () use ($app) {
|
||||||
|
|
||||||
|
//取得現在時間,用字串的形式
|
||||||
|
$nowDate = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
$app->render(200, array(
|
$app->render(200, array(
|
||||||
'title' => '',
|
'title' => '',
|
||||||
'version' => '2.0',
|
'version' => '2.0',
|
||||||
|
'current_time' => $nowDate,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ namespace UElearning\Study;
|
|||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/User/User.php';
|
require_once UELEARNING_LIB_ROOT.'/User/User.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Theme.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';
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
use UElearning\Database;
|
use UElearning\Database;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
@ -422,4 +423,61 @@ class StudyActivity {
|
|||||||
return $this->queryResultArray['material_mode'];
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,25 @@ class StudyManager {
|
|||||||
return $db->getCurrentInStudyId($activity_id);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 進入標的
|
* 進入標的
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user