fix DBStudyActivity & StudyWill
This commit is contained in:
parent
7707cdc84d
commit
6e37bbba55
@ -157,11 +157,11 @@ class DBStudyActivity extends Database {
|
||||
"`LMode`, `LModeForce`, `MMode`, ".
|
||||
|
||||
"(SELECT count(`TID`)
|
||||
FROM `chu__TBelong` AS `belong`
|
||||
FROM `".$this->table('TBelong')."` AS `belong`
|
||||
WHERE `belong`.`ThID` = `sa`.`ThID`) AS `TargetTotal`, ".
|
||||
|
||||
"(SELECT count(DISTINCT `TID`)
|
||||
FROM `chu__Study` AS `study`
|
||||
FROM `".$this->table('Study')."` AS `study`
|
||||
WHERE `Out_TargetTime` IS NOT NULL
|
||||
AND `study`.`SaID` = `sa`.`SaID`) AS `LearnedTotal`".
|
||||
|
||||
@ -242,7 +242,9 @@ class DBStudyActivity extends Database {
|
||||
* 'time_force' => <時間到時是否強制中止學習>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>
|
||||
* 'material_mode' => <教材模式>,
|
||||
* 'target_total' => <有多少標的學習>,
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* );
|
||||
* @param int $id 活動編號
|
||||
*/
|
||||
@ -278,7 +280,9 @@ class DBStudyActivity extends Database {
|
||||
* 'time_force' => <時間到時是否強制中止學習>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>
|
||||
* 'material_mode' => <教材模式>,
|
||||
* 'target_total' => <有多少標的學習>,
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
@ -304,7 +308,9 @@ class DBStudyActivity extends Database {
|
||||
* 'delay' => <延誤結束時間(分)>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>
|
||||
* 'material_mode' => <教材模式>,
|
||||
* 'target_total' => <有多少標的學習>,
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
@ -472,4 +478,178 @@ class DBStudyActivity extends Database {
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
protected function queryWillActivityByWhere($where) {
|
||||
|
||||
$sqlString = "SELECT `SwID`, `UID`, `ThID`, ".
|
||||
"`StartTime`, `ExpiredTime`, `LearnTime`, `TimeForce`, ".
|
||||
"`LMode`, `LModeForce`, `MMode`, `Lock`, ".
|
||||
|
||||
"(SELECT count(`TID`)
|
||||
FROM `".$this->table('TBelong')."` AS `belong`
|
||||
WHERE `belong`.`ThID` = `sw`.`ThID`) AS `TargetTotal`, ".
|
||||
|
||||
"`BuildTime`, `ModifyTime` ".
|
||||
|
||||
"FROM `".$this->table('StudyWill')."` AS `sw` ".
|
||||
"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['TimeForce'] != '0') {
|
||||
$output_time_force = true;
|
||||
}
|
||||
else { $output_time_force = false; }
|
||||
|
||||
if($thisResult['LModeForce'] != '0') {
|
||||
$output_learnStyleForce = true;
|
||||
}
|
||||
else { $output_learnStyleForce = false; }
|
||||
|
||||
if($thisResult['Lock'] != '0') {
|
||||
$output_isLock = true;
|
||||
}
|
||||
else { $output_isLock = false; }
|
||||
|
||||
array_push($result,
|
||||
array( 'activity_will_id' => $thisResult['SwID'],
|
||||
'user_id' => $thisResult['UID'],
|
||||
'theme_id' => $thisResult['ThID'],
|
||||
'start_time' => $thisResult['StartTime'],
|
||||
'expired_time' => $thisResult['ExpiredTime'],
|
||||
'learn_time' => $thisResult['LearnTime'],
|
||||
'time_force' => $output_time_force,
|
||||
'learnStyle_mode' => $thisResult['LMode'],
|
||||
'learnStyle_force' => $output_learnStyleForce,
|
||||
'material_mode' => $thisResult['MMode'],
|
||||
'is_lock' => $output_isLock,
|
||||
'target_total' => $thisResult['TargetTotal'],
|
||||
'build_time' => $thisResult['BuildTime'],
|
||||
'modify_time' => $thisResult['ModifyTime']
|
||||
)
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// 若都沒查到的話
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢一個活動資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
* $db = new Database\DBTarget();
|
||||
*
|
||||
* $targetInfo = $db->queryActivity(4);
|
||||
* echo '<pre>'; print_r($targetInfo); echo '</pre>';
|
||||
*
|
||||
*
|
||||
* @param int $td 學習活動ID
|
||||
* @return array 活動資料陣列,格式為:
|
||||
* array( 'activity_id' => <預約活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
* 'start_time' => <開始生效時間>,
|
||||
* 'end_time' => <過期時間>,
|
||||
* 'learn_time' => <學習所需時間(分)>,
|
||||
* 'time_force' => <時間到時是否強制中止學習>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>,
|
||||
* 'is_lock' => <是否鎖定不讓學生更改>,
|
||||
* 'target_total' => <有多少標的學習>,
|
||||
* 'build_time' => <建立時間>,
|
||||
* 'modify_time' => <修改時間>
|
||||
* );
|
||||
* @param int $id 活動編號
|
||||
*/
|
||||
public function queryWillActivity($id) {
|
||||
|
||||
$queryResultAll =
|
||||
$this->queryWillActivityByWhere("`SwID`=".$this->connDB->quote($id));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
}
|
||||
// 若都沒查到的話
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢所有活動資料
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_id' => <活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
* 'start_time' => <開始學習時間>,
|
||||
* 'end_time' => <結束學習時間>,
|
||||
* 'learn_time' => <學習所需時間(分)>,
|
||||
* 'delay' => <延誤結束時間(分)>,
|
||||
* 'time_force' => <時間到時是否強制中止學習>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
public function queryAllWillActivity() {
|
||||
|
||||
return $this->queryWillActivityByWhere("1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢此使用者所有活動資料
|
||||
*
|
||||
* @param int $user_id 使用者ID
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_id' => <活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
* 'start_time' => <開始學習時間>,
|
||||
* 'end_time' => <結束學習時間>,
|
||||
* 'delay' => <延誤結束時間(分)>,
|
||||
* 'learnStyle_mode' => <學習導引模式>,
|
||||
* 'learnStyle_force' => <拒絕前往非推薦的學習點>,
|
||||
* 'material_mode' => <教材模式>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
public function queryAllWillActivityByUserId($user_id) {
|
||||
|
||||
return $this->queryWillActivityByWhere(
|
||||
"`UID`=".$this->connDB->quote($user_id));
|
||||
}
|
||||
}
|
@ -69,6 +69,37 @@ class StudyActivityFinishedException extends \UnexpectedValueException {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 沒有此預約
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
class StudyActivityWillNoFoundException extends \UnexpectedValueException {
|
||||
/**
|
||||
* 指定的學習活動ID
|
||||
* @type int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param int $id 輸入的標的ID
|
||||
*/
|
||||
public function __construct($id) {
|
||||
$this->id = $id;
|
||||
parent::__construct('No Activity: '.$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得輸入的標的ID
|
||||
* @return int 標的ID
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 沒有找到此主題
|
||||
* @since 2.0.0
|
||||
|
@ -4,8 +4,9 @@
|
||||
*/
|
||||
namespace UElearning\Study;
|
||||
|
||||
//require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
//require_once UELEARNING_LIB_ROOT.'/Target/Exception.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/User/User.php';
|
||||
use UElearning\Database;
|
||||
use UElearning\Exception;
|
||||
use UElearning\User;
|
||||
@ -43,16 +44,16 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// TODO: 從資料庫取得查詢
|
||||
//// 從資料庫查詢
|
||||
//$db = new Database\DBTarget();
|
||||
//$areaInfo = $db->queryArea($this->aId);
|
||||
//
|
||||
//// 判斷有沒有這個
|
||||
//if( $areaInfo != null ) {
|
||||
// $this->queryResultArray = $areaInfo;
|
||||
//}
|
||||
//else throw new Exception\AreaNoFoundException($this->aId);
|
||||
|
||||
// 從資料庫查詢
|
||||
$db = new Database\DBStudyActivity();
|
||||
$info = $db->queryWillActivity($this->id);
|
||||
|
||||
// 判斷有沒有這個
|
||||
if( $info != null ) {
|
||||
$this->queryResultArray = $info;
|
||||
}
|
||||
else throw new Exception\StudyActivityWillNoFoundException($this->id);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@ -60,11 +61,11 @@ class StudyWill {
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputID 學習階段流水號ID
|
||||
* @param int $inputID 預約學習流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputID){
|
||||
$this->id = $inputAID;
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
@ -153,7 +154,7 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setThemeById($theme_id){
|
||||
return $this->queryResultArray['theme_id'];
|
||||
//return $this->queryResultArray['theme_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +164,7 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getStartTime(){
|
||||
//return $this->queryResultArray['build_time'];
|
||||
return $this->queryResultArray['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +184,7 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getExpiredTime(){
|
||||
//return $this->queryResultArray['build_time'];
|
||||
return $this->queryResultArray['expired_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,7 +204,7 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
//return $this->queryResultArray['name'];
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,6 +217,26 @@ class StudyWill {
|
||||
//return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @return bool 是否在這次學習時間已過而強制結束學習
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isForceLearnTime() {
|
||||
return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @param bool $value 是否在這次學習時間已過而強制結束學習
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setForceLearnTime($value) {
|
||||
//return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預約學習的導引風格
|
||||
*
|
||||
@ -283,7 +304,7 @@ class StudyWill {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isLock() {
|
||||
|
||||
return $this->queryResultArray['is_lock'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,6 +317,16 @@ class StudyWill {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 總共要學幾個學習點
|
||||
*
|
||||
* @return int 有幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getPointTotal() {
|
||||
return $this->queryResultArray['target_total'];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user