Merge branch 'develop' of https://github.com/CHU-TDAP/E-learning-Server-v2 into develop
This commit is contained in:
commit
c75ad9a358
@ -7,6 +7,7 @@ require_once UELEARNING_LIB_ROOT.'/User/UserSession.php';
|
|||||||
require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
|
require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
|
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
|
||||||
use UElearning\User;
|
use UElearning\User;
|
||||||
@ -806,6 +807,233 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 取得此標的資料
|
||||||
|
* GET http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}
|
||||||
|
*/
|
||||||
|
$app->get('/:token/activitys/:said/points/:tid', function ($token, $saId, $tId) use ($app) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查詢使用者
|
||||||
|
$session = new User\UserSession();
|
||||||
|
$user_id = $session->getUserId($token);
|
||||||
|
|
||||||
|
// 取得開始後的學習活動資訊
|
||||||
|
$sact = new Study\StudyActivity($saId);
|
||||||
|
|
||||||
|
// 確認此學習活動是否為本人所有
|
||||||
|
if($sact->getUserId() == $user_id) {
|
||||||
|
|
||||||
|
// 取得此活動的主題
|
||||||
|
$thid = $sact->getThemeId();
|
||||||
|
|
||||||
|
// 取得本次採用的教材風格
|
||||||
|
$materialMode = $sact->getMaterialStyle();
|
||||||
|
|
||||||
|
// 取得主題內所有的標的資訊
|
||||||
|
$target = new Target\Target($thid);
|
||||||
|
$materialUrl = $target->getMaterialUrl(true, $materialMode);
|
||||||
|
$virtualMaterialUrl = $target->getMaterialUrl(false, $materialMode);
|
||||||
|
|
||||||
|
// 處理噴出結果
|
||||||
|
$output_targets = array(
|
||||||
|
'theme_id' => $thid,
|
||||||
|
'target_id' => $target->getId(),
|
||||||
|
'hall_id' => $target->getHallId(),
|
||||||
|
//'hall_name' => $thisTargetArray['hall_name'],
|
||||||
|
'area_id' => $target->getAreaId(),
|
||||||
|
//'area_name' => $thisTargetArray['area_name'],
|
||||||
|
//'floor' => $thisTargetArray['floor'],
|
||||||
|
//'area_number' => $thisTargetArray['area_number'],
|
||||||
|
'target_number' => $target->getNumber(),
|
||||||
|
'name' => $target->getName(),
|
||||||
|
'map_url' => $target->getMapUrl(),
|
||||||
|
'material_url' => $materialUrl,
|
||||||
|
'virtual_material_url' => $virtualMaterialUrl,
|
||||||
|
'learn_time' => $target->getLearnTime(),
|
||||||
|
'PLj' => $target->getPLj(),
|
||||||
|
'Mj' => $target->getMj(),
|
||||||
|
'S' => $target->getS(),
|
||||||
|
'Fj' => $target->getFj()
|
||||||
|
);
|
||||||
|
|
||||||
|
// 噴出結果
|
||||||
|
$app->render(200,array(
|
||||||
|
'token' => $token,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'activity_id' => $sact->getId(),
|
||||||
|
'target' => $output_targets,
|
||||||
|
'error' => false
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
// 若非本人所有,則視同無此活動
|
||||||
|
else {
|
||||||
|
throw new Exception\StudyActivityNoFoundException($saId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception\LoginTokenNoFoundException $e) {
|
||||||
|
$app->render(401,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No \''.$token.'\' session. Please login again.',
|
||||||
|
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
|
||||||
|
'substatus' => 204
|
||||||
|
));
|
||||||
|
}
|
||||||
|
catch (Exception\StudyActivityNoFoundException $e) {
|
||||||
|
$app->render(404,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No found this activity.',
|
||||||
|
'msg_cht' => '沒有此學習活動'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 進入此學習點
|
||||||
|
* POST http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}/toin
|
||||||
|
*/
|
||||||
|
$app->post('/:token/activitys/:said/points/:tid/toin', function ($token, $saId, $tId) use ($app) {
|
||||||
|
|
||||||
|
// 取得帶來的參數
|
||||||
|
$cType = $app->request->getContentType();
|
||||||
|
if($cType == 'application/x-www-form-urlencoded') {
|
||||||
|
$is_entity = isset($_POST['is_entity']) ? $_POST['is_entity'] : true;
|
||||||
|
}
|
||||||
|
else /*if($cType == 'application/json')*/ {
|
||||||
|
$postData = $app->request->getBody();
|
||||||
|
$postDataArray = json_decode($postData);
|
||||||
|
$is_entity = isset($postDataArray->is_entity)
|
||||||
|
? $postDataArray->is_entity : true;
|
||||||
|
}
|
||||||
|
/*else {
|
||||||
|
$app->render(400, array(
|
||||||
|
'Content-Type'=> $cType,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => '',
|
||||||
|
'msg_cht' => '輸入參數的Content-Type不在支援範圍內 或是沒有輸入',
|
||||||
|
'substatus' => 102
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查詢使用者
|
||||||
|
$session = new User\UserSession();
|
||||||
|
$user_id = $session->getUserId($token);
|
||||||
|
|
||||||
|
// 取得開始後的學習活動資訊
|
||||||
|
$sact = new Study\StudyActivity($saId);
|
||||||
|
|
||||||
|
// 確認此學習活動是否為本人所有
|
||||||
|
if($sact->getUserId() == $user_id) {
|
||||||
|
|
||||||
|
$sct = new Study\StudyManager();
|
||||||
|
// 進入學習點
|
||||||
|
try{
|
||||||
|
$sid = $sct->toInTarget($saId, $tId, $is_entity);
|
||||||
|
}
|
||||||
|
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
|
||||||
|
catch (Exception\InLearningException $e) {
|
||||||
|
$sct->toOutTarget($saId, $tId);
|
||||||
|
$sid = $sct->toInTarget($saId, $tId, $is_entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 噴出結果
|
||||||
|
$app->render(200,array(
|
||||||
|
'token' => $token,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'activity_id' => $sact->getId(),
|
||||||
|
'study_id' => $sid,
|
||||||
|
'error' => false
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
// 若非本人所有,則視同無此活動
|
||||||
|
else {
|
||||||
|
throw new Exception\StudyActivityNoFoundException($saId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception\LoginTokenNoFoundException $e) {
|
||||||
|
$app->render(401,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No \''.$token.'\' session. Please login again.',
|
||||||
|
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
|
||||||
|
'substatus' => 204
|
||||||
|
));
|
||||||
|
}
|
||||||
|
catch (Exception\StudyActivityNoFoundException $e) {
|
||||||
|
$app->render(404,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No found this activity.',
|
||||||
|
'msg_cht' => '沒有此學習活動'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 進入此學習點
|
||||||
|
* POST http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}/toout
|
||||||
|
*/
|
||||||
|
$app->post('/:token/activitys/:said/points/:tid/toout', function ($token, $saId, $tId) use ($app) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查詢使用者
|
||||||
|
$session = new User\UserSession();
|
||||||
|
$user_id = $session->getUserId($token);
|
||||||
|
|
||||||
|
// 取得開始後的學習活動資訊
|
||||||
|
$sact = new Study\StudyActivity($saId);
|
||||||
|
|
||||||
|
// 確認此學習活動是否為本人所有
|
||||||
|
if($sact->getUserId() == $user_id) {
|
||||||
|
|
||||||
|
$sct = new Study\StudyManager();
|
||||||
|
// 離開學習點
|
||||||
|
$sct->toOutTarget($saId, $tId);
|
||||||
|
|
||||||
|
// 噴出結果
|
||||||
|
$app->render(201,array(
|
||||||
|
'token' => $token,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'activity_id' => $sact->getId(),
|
||||||
|
'error' => false
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
// 若非本人所有,則視同無此活動
|
||||||
|
else {
|
||||||
|
throw new Exception\StudyActivityNoFoundException($saId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception\LoginTokenNoFoundException $e) {
|
||||||
|
$app->render(401,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No \''.$token.'\' session. Please login again.',
|
||||||
|
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
|
||||||
|
'substatus' => 204
|
||||||
|
));
|
||||||
|
}
|
||||||
|
catch (Exception\StudyActivityNoFoundException $e) {
|
||||||
|
$app->render(404,array(
|
||||||
|
'token' => $token,
|
||||||
|
'error' => true,
|
||||||
|
'msg' => 'No found this activity.',
|
||||||
|
'msg_cht' => '沒有此學習活動'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
391
htdocs/lib/Database/DBStudy.php
Normal file
391
htdocs/lib/Database/DBStudy.php
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* DBStudy.php
|
||||||
|
*
|
||||||
|
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料庫查詢用。
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace UElearning\Database;
|
||||||
|
|
||||||
|
use UElearning\Exception;
|
||||||
|
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 學習點記錄資料表
|
||||||
|
*
|
||||||
|
* 範例:
|
||||||
|
*
|
||||||
|
* require_once __DIR__.'/../config.php';
|
||||||
|
* require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
|
||||||
|
* use UElearning\Database;
|
||||||
|
*
|
||||||
|
* $db = new Database\DBStudy();
|
||||||
|
* // 查詢'yuan'的所有活動
|
||||||
|
* $data = $db->queryAllStudyByUserId('yuan');
|
||||||
|
* echo '<pre>';print_r($data);echo '</pre>';
|
||||||
|
*
|
||||||
|
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||||
|
* @version 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Database
|
||||||
|
*/
|
||||||
|
class DBStudy extends Database {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 內部使用的查詢動作
|
||||||
|
* @param string $where 查詢語法
|
||||||
|
* @return array 查詢結果陣列
|
||||||
|
*/
|
||||||
|
protected function queryByWhere($where) {
|
||||||
|
|
||||||
|
$sqlString = "SELECT `SID`, `SaID`, ".
|
||||||
|
"`TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime` ".
|
||||||
|
"FROM `".$this->table('Study')."` ".
|
||||||
|
"WHERE ".$where;
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$queryResultAll = $query->fetchAll();
|
||||||
|
// 如果有查到一筆以上
|
||||||
|
if( count($queryResultAll) >= 1 ) {
|
||||||
|
// 製作回傳結果陣列
|
||||||
|
$result = array();
|
||||||
|
foreach($queryResultAll as $key => $thisResult) {
|
||||||
|
|
||||||
|
if($thisResult['IsEntity'] != '0') {
|
||||||
|
$output_entity = true;
|
||||||
|
}
|
||||||
|
else { $output_entity = false; }
|
||||||
|
|
||||||
|
array_push($result,
|
||||||
|
array( 'study_id' => (int)$thisResult['SID'],
|
||||||
|
'activity_id' => (int)$thisResult['SaID'],
|
||||||
|
'target_id' => (int)$thisResult['TID'],
|
||||||
|
'is_entity' => $output_entity,
|
||||||
|
'in_target_time' => $thisResult['In_TargetTime'],
|
||||||
|
'out_target_time' => $thisResult['Out_TargetTime']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
// 若都沒查到的話
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以活動編號查詢所有進出標的資料
|
||||||
|
*
|
||||||
|
* @return array 進出標的資料陣列,格式為:
|
||||||
|
*
|
||||||
|
* array(
|
||||||
|
* array(
|
||||||
|
* 'study_id' => <流水編號>,
|
||||||
|
* 'activity_id' => <活動編號>,
|
||||||
|
* 'target_id' => <標的編號>,
|
||||||
|
* 'is_entity' => <是否為現場學習>,
|
||||||
|
* 'in_target_time' => <進入時間>,
|
||||||
|
* 'out_target_time' => <離開時間>
|
||||||
|
* )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function queryById($id) {
|
||||||
|
$queryResultAll = $this->queryByWhere("`SID`=".$this->connDB->quote($id));
|
||||||
|
|
||||||
|
// 如果有查到一筆以上
|
||||||
|
if( count($queryResultAll) >= 1 ) {
|
||||||
|
return $queryResultAll[0];
|
||||||
|
}
|
||||||
|
// 若都沒查到的話
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以活動編號查詢所有進出標的資料
|
||||||
|
*
|
||||||
|
* @return array 進出標的資料陣列,格式為:
|
||||||
|
*
|
||||||
|
* array(
|
||||||
|
* array(
|
||||||
|
* 'study_id' => <流水編號>,
|
||||||
|
* 'activity_id' => <活動編號>,
|
||||||
|
* 'target_id' => <標的編號>,
|
||||||
|
* 'is_entity' => <是否為現場學習>,
|
||||||
|
* 'in_target_time' => <進入時間>,
|
||||||
|
* 'out_target_time' => <離開時間>
|
||||||
|
* )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function queryByActivityId($id) {
|
||||||
|
|
||||||
|
return $this->queryByWhere("`SID`=".$this->connDB->quote($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查詢所有進出標的資料
|
||||||
|
*
|
||||||
|
* @return array 進出標的資料陣列,格式為:
|
||||||
|
*
|
||||||
|
* array(
|
||||||
|
* array(
|
||||||
|
* 'study_id' => <流水編號>,
|
||||||
|
* 'activity_id' => <活動編號>,
|
||||||
|
* 'target_id' => <標的編號>,
|
||||||
|
* 'is_entity' => <是否為現場學習>,
|
||||||
|
* 'in_target_time' => <進入時間>,
|
||||||
|
* 'out_target_time' => <離開時間>
|
||||||
|
* )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function queryAll() {
|
||||||
|
|
||||||
|
return $this->queryByWhere("1");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建立學習點進出記錄
|
||||||
|
*
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @param string $target_id 標的編號
|
||||||
|
* @param string $is_entity 是否為現場學習
|
||||||
|
* @param int $in_target_time 進入時間
|
||||||
|
* @param int $out_target_time 離開時間
|
||||||
|
*
|
||||||
|
* @return int 剛新增的記錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function insert($activity_id, $target_id,
|
||||||
|
$is_entity, $in_target_time, $out_target_time)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!isset($is_entity)) {
|
||||||
|
$is_entity = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 寫入
|
||||||
|
$sqlString = "INSERT INTO `".$this->table('Study').
|
||||||
|
"` (`SaID`, `TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
|
||||||
|
VALUES ( :said , :tid , :entity , :intime , :outtime )";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->bindParam(":tid", $target_id);
|
||||||
|
$query->bindParam(":entity", $is_entity);
|
||||||
|
$query->bindParam(":intime", $in_target_time);
|
||||||
|
$query->bindParam(":outtime", $out_target_time);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
// 取得剛剛加入的ID
|
||||||
|
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||||
|
$query = $this->connDB->query($sqlString);
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
$resultId = $queryResult[0];
|
||||||
|
|
||||||
|
return $resultId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除一筆進出標的資料
|
||||||
|
* @param int $id 進出標的編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function delete($id) {
|
||||||
|
|
||||||
|
$sqlString = "DELETE FROM ".$this->table('Study').
|
||||||
|
" WHERE `SID` = :id ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":id", $id);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除此學習活動的所有進出標的資料
|
||||||
|
* @param int $id 學習活動編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function deleteByActivityId($id) {
|
||||||
|
|
||||||
|
$sqlString = "DELETE FROM ".$this->table('Study').
|
||||||
|
" WHERE `SaID` = :id ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":id", $id);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 進入學習點
|
||||||
|
*
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @param string $target_id 標的編號
|
||||||
|
* @param string $is_entity 是否為現場學習
|
||||||
|
* @return int 剛新增的記錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function toInTaeget($activity_id, $target_id, $is_entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!isset($is_entity)) {
|
||||||
|
$is_entity = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 寫入
|
||||||
|
$sqlString = "INSERT INTO `".$this->table('Study').
|
||||||
|
"` (`SaID`, `TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
|
||||||
|
VALUES ( :said , :tid , :entity , NOW() , NULL )";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->bindParam(":tid", $target_id);
|
||||||
|
$query->bindParam(":entity", $is_entity);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
// 取得剛剛加入的ID
|
||||||
|
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||||
|
$query = $this->connDB->query($sqlString);
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
$resultId = $queryResult[0];
|
||||||
|
|
||||||
|
return $resultId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 離開學習點
|
||||||
|
*
|
||||||
|
* @param string $study_id 此記錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function toOutTaeget($study_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 寫入
|
||||||
|
$sqlString = "UPDATE `".$this->table('Study').
|
||||||
|
"` SET `Out_TargetTime` = NOW()
|
||||||
|
WHERE `SID` = :id ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":id", $study_id);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此活動內離開所有學習點
|
||||||
|
*
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function allToOutTaeget($activity_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 寫入
|
||||||
|
$sqlString = "UPDATE `".$this->table('Study').
|
||||||
|
"` SET `Out_TargetTime` = NOW()
|
||||||
|
WHERE `SaID` = :id ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":id", $activity_id);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前正在進行的標的編號
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @return int 標的編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getCurrentInTargetId($activity_id) {
|
||||||
|
|
||||||
|
$sqlString = "SELECT `TID` FROM `".$this->table('Study')."` ".
|
||||||
|
"WHERE `Out_TargetTime` IS NULL AND `SaID` = :said ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
// 如果有查到一筆以上
|
||||||
|
if( count($queryResult) >= 1 ) {
|
||||||
|
return (int)$queryResult[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前正在進行的紀錄編號
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @return int 進出紀錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getCurrentInStudyId($activity_id) {
|
||||||
|
|
||||||
|
$sqlString = "SELECT `SID` FROM `".$this->table('Study')."` ".
|
||||||
|
"WHERE `Out_TargetTime` IS NULL AND `SaID` = :said ";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
// 如果有查到一筆以上
|
||||||
|
if( count($queryResult) >= 1 ) {
|
||||||
|
return (int)$queryResult[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得所有在此標的的記錄編號
|
||||||
|
*
|
||||||
|
* 正常來說只會有一個,但考量使用者可能在這次活動內同一標的進出兩次以上,故還是以二維陣列輸出。
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @param int $target_id 標的編號
|
||||||
|
* @return array 所有進出記錄資訊陣列
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getAllStudyIdByTargetId($activity_id, $target_id) {
|
||||||
|
|
||||||
|
$queryResultAll = $this->queryByWhere(
|
||||||
|
"`TID` = ".$this->connDB->quote($target_id).
|
||||||
|
" AND `SaID` = ".$this->connDB->quote($activity_id));
|
||||||
|
|
||||||
|
return $queryResultAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得在此標學習中的記錄編號
|
||||||
|
*
|
||||||
|
* 正常來說只會有一個,但考量使用者可能在這次活動內同一標的進出兩次以上,故還是以陣列輸出。
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @param int $target_id 標的編號
|
||||||
|
* @return array 所有進出記錄資訊陣列
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getInStudyIdByTargetId($activity_id, $target_id) {
|
||||||
|
|
||||||
|
$queryResultAll = $this->queryByWhere(
|
||||||
|
"`TID` = ".$this->connDB->quote($target_id).
|
||||||
|
" AND `SaID` = ".$this->connDB->quote($activity_id).
|
||||||
|
" AND `Out_TargetTime` IS NULL");
|
||||||
|
|
||||||
|
return $queryResultAll;
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,8 @@ class DBStudyActivity extends Database {
|
|||||||
* @param bool $learnStyle_force 拒絕前往非推薦的學習點
|
* @param bool $learnStyle_force 拒絕前往非推薦的學習點
|
||||||
* @param bool $enable_virtual 是否啟用虛擬教材
|
* @param bool $enable_virtual 是否啟用虛擬教材
|
||||||
* @param string $materialMode 教材模式
|
* @param string $materialMode 教材模式
|
||||||
|
*
|
||||||
|
* @return int 剛新增的活動編號
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function insertActivity($userId, $themeId, $startTime, $endTime,
|
public function insertActivity($userId, $themeId, $startTime, $endTime,
|
||||||
@ -408,6 +410,8 @@ class DBStudyActivity extends Database {
|
|||||||
* @param bool $enable_virtual 是否啟用虛擬教材
|
* @param bool $enable_virtual 是否啟用虛擬教材
|
||||||
* @param string $materialMode 教材模式
|
* @param string $materialMode 教材模式
|
||||||
* @param string $isLock 是否鎖定不讓學生更改
|
* @param string $isLock 是否鎖定不讓學生更改
|
||||||
|
*
|
||||||
|
* @return int 剛新增的活動編號
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function insertWillActivity($userId, $themeId, $startTime, $expiredTime,
|
public function insertWillActivity($userId, $themeId, $startTime, $expiredTime,
|
||||||
|
@ -7,6 +7,54 @@ namespace UElearning\Exception;
|
|||||||
|
|
||||||
// TODO: 將以下類別濃縮
|
// TODO: 將以下類別濃縮
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 沒有找到此標的進出記錄
|
||||||
|
* @since 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Study
|
||||||
|
*/
|
||||||
|
class StudyNoFoundException extends \UnexpectedValueException {
|
||||||
|
/**
|
||||||
|
* 指定的學習活動ID
|
||||||
|
* @type int
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用者帳號例外
|
||||||
|
* @param int $id 輸入的標的ID
|
||||||
|
*/
|
||||||
|
public function __construct($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
parent::__construct('No Study: '.$this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得輸入的標的ID
|
||||||
|
* @return int 標的ID
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正在學習中例外(難道使用者有分身?)
|
||||||
|
* @since 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Study
|
||||||
|
*/
|
||||||
|
class InLearningException extends \UnexpectedValueException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用者帳號例外
|
||||||
|
* @param int $id 輸入的標的ID
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('Learning');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 沒有找到此活動
|
* 沒有找到此活動
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
|
@ -0,0 +1,179 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Study.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace UElearning\Study;
|
||||||
|
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
|
use UElearning\Database;
|
||||||
|
use UElearning\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 學習點進出記錄
|
||||||
|
*
|
||||||
|
* 一個物件即代表此學習點進出記錄
|
||||||
|
*
|
||||||
|
* @version 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Study
|
||||||
|
*/
|
||||||
|
class Study {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主題ID
|
||||||
|
* @type int
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查詢到所有資訊的結果
|
||||||
|
*
|
||||||
|
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||||
|
* @type array
|
||||||
|
*/
|
||||||
|
protected $queryResultArray;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 從資料庫取得查詢
|
||||||
|
*
|
||||||
|
* @throw \UElearning\Exception\ThemeNoFoundException
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
protected function getQuery(){
|
||||||
|
|
||||||
|
// 從資料庫查詢
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
$info = $db->queryById($this->id);
|
||||||
|
|
||||||
|
// 判斷有沒有這個
|
||||||
|
if( $info != null ) {
|
||||||
|
$this->queryResultArray = $info;
|
||||||
|
}
|
||||||
|
else throw new Exception\StudyNoFoundException($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建構子
|
||||||
|
*
|
||||||
|
* @param int $inputTID 主題ID
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function __construct($inputID){
|
||||||
|
$this->id = $inputID;
|
||||||
|
$this->getQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得本進出記錄編號
|
||||||
|
*
|
||||||
|
* @return int 進出記錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getId(){
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得本次活動編號
|
||||||
|
*
|
||||||
|
* @return int 學習活動編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getActivityId(){
|
||||||
|
return $this->queryResultArray['activity_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得標的編號
|
||||||
|
*
|
||||||
|
* @return int 標的編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getTargetId(){
|
||||||
|
return $this->queryResultArray['target_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 取得標的名稱
|
||||||
|
// *
|
||||||
|
// * @return int 標的名稱
|
||||||
|
// * @since 2.0.0
|
||||||
|
// */
|
||||||
|
// public function getTargetName(){
|
||||||
|
// return $this->queryResultArray['target_id'];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 取得此紀錄的使用者ID
|
||||||
|
// *
|
||||||
|
// * @return string 使用者ID
|
||||||
|
// * @since 2.0.0
|
||||||
|
// */
|
||||||
|
// public function getUserId(){
|
||||||
|
// return $this->queryResultArray['target_id'];
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否為實體(實際抵達學習點)
|
||||||
|
*
|
||||||
|
* @return bool 是否為實體
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function isEntity(){
|
||||||
|
return $this->queryResultArray['is_entity'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得進入學習點時間
|
||||||
|
*
|
||||||
|
* @return string 進入學習點時間
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function isIn(){
|
||||||
|
// TODO: 尚未測試
|
||||||
|
if($this->queryResultArray['out_target_time'] == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得進入學習點時間
|
||||||
|
*
|
||||||
|
* @return string 進入學習點時間
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getInTime(){
|
||||||
|
return $this->queryResultArray['in_target_time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得離開學習點時間
|
||||||
|
*
|
||||||
|
* @return string 離開學習點時間
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getOutTime(){
|
||||||
|
return $this->queryResultArray['out_target_time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 離開學習點
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function toOut() {
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
$db->toOutTaeget($this->id);
|
||||||
|
}
|
||||||
|
}
|
86
htdocs/lib/Study/StudyManager.php
Normal file
86
htdocs/lib/Study/StudyManager.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* StudyManager.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace UElearning\Study;
|
||||||
|
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
|
use UElearning\Database;
|
||||||
|
use UElearning\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 學習點進出記錄
|
||||||
|
*
|
||||||
|
* 一個物件即代表此學習點進出記錄
|
||||||
|
*
|
||||||
|
* @version 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Study
|
||||||
|
*/
|
||||||
|
class StudyManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前已進入的學習點
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @return string 標的編號,若無則null
|
||||||
|
*/
|
||||||
|
public function getCurrentInTargetId($activity_id) {
|
||||||
|
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
return $db->getCurrentInTargetId($activity_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前已進入的學習點的進出紀錄物件
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @return int 進出紀錄編號
|
||||||
|
*/
|
||||||
|
public function getCurrentInStudyId($activity_id) {
|
||||||
|
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
return $db->getCurrentInStudyId($activity_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 進入標的
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @param int $target_id 標的編號
|
||||||
|
* @param bool $is_entity 是否為現場學習
|
||||||
|
* return int 進出紀錄編號
|
||||||
|
*/
|
||||||
|
public function toInTarget($activity_id, $target_id, $is_entity) {
|
||||||
|
|
||||||
|
// 若沒有任一個點正在學習中
|
||||||
|
if($this->getCurrentInTargetId($activity_id) == null) {
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
return $db->toInTaeget($activity_id, $target_id, $is_entity);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Exception\InLearningException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 離開標的
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @param int $target_id 標的編號
|
||||||
|
*/
|
||||||
|
public function toOutTarget($activity_id, $target_id) {
|
||||||
|
|
||||||
|
// 從資料庫取得此活動此標的學習中資料
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
|
||||||
|
|
||||||
|
if(isset($learning_array)) {
|
||||||
|
|
||||||
|
foreach($learning_array as $thisArray) {
|
||||||
|
|
||||||
|
$db->toOutTaeget($thisArray['study_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user