更改縮排字元 tab->4 whitespace
This commit is contained in:
parent
f12f21bb1c
commit
d2b2f1bed1
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
@ -2,14 +2,14 @@
|
||||
|
||||
/**
|
||||
* 除錯模式-管理
|
||||
*
|
||||
*
|
||||
* 警告: 若網站要正式上線,請務必設定為false,否則會有嚴重的安全問題
|
||||
*/
|
||||
*/
|
||||
define('DEBUG_ADMIN', false);
|
||||
// 資料庫 =====================================================================
|
||||
/**
|
||||
* 資料庫類型
|
||||
*/
|
||||
*/
|
||||
define('DB_TYPE', 'mysql'); // or mysql
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@
|
||||
define('DB_PREFIX', 'uel__');
|
||||
|
||||
// 學習導引設定 =================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 預設導引模式
|
||||
*
|
||||
@ -68,7 +68,7 @@
|
||||
*/
|
||||
define('SITE_NAME', '無所不在學習導引系統');
|
||||
|
||||
/**
|
||||
/**
|
||||
* 網站副標題
|
||||
*/
|
||||
define('SITE_SUBNAME', '');
|
||||
@ -80,14 +80,14 @@
|
||||
|
||||
/**
|
||||
* 網站首頁網址
|
||||
*
|
||||
*
|
||||
* Warning: 網址後面務必加上"/"
|
||||
*/
|
||||
*/
|
||||
define('SITE_URL', 'http://localhost/');
|
||||
|
||||
/**
|
||||
* 本系統根網址
|
||||
*
|
||||
*
|
||||
* 給絕對路徑用的。
|
||||
* Warning: 網址後面務必加上"/"
|
||||
*/
|
||||
@ -95,8 +95,8 @@
|
||||
|
||||
/**
|
||||
* 要用哪種加密方式
|
||||
*
|
||||
* 目前提供選項:
|
||||
*
|
||||
* 目前提供選項:
|
||||
* <ul>
|
||||
* <li>MD5</li>
|
||||
* <li>SHA1</li>
|
||||
@ -108,7 +108,7 @@
|
||||
/**
|
||||
* 你的地區
|
||||
*/
|
||||
date_default_timezone_set('Asia/Taipei'); //設定時區
|
||||
date_default_timezone_set('Asia/Taipei'); //設定時區
|
||||
|
||||
// 路徑設定 ===================================================================
|
||||
/**
|
||||
@ -123,5 +123,5 @@
|
||||
|
||||
/**
|
||||
* 這份設定檔的路徑
|
||||
*/
|
||||
*/
|
||||
define('UELEARNING_CONFIG_PATH', __FILE__);
|
||||
|
@ -12,19 +12,19 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
|
||||
/**
|
||||
* 資料庫整體管理
|
||||
*
|
||||
*
|
||||
* 對資料庫的管理操作。
|
||||
*
|
||||
* 建立資料庫連結,若直接使用`config.php`設定的參數,使用以下即可:
|
||||
*
|
||||
*
|
||||
* 建立資料庫連結,若直接使用`config.php`設定的參數,使用以下即可:
|
||||
*
|
||||
* require_once __DIR__.'/config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'Database/DBAdmin.php';
|
||||
* use UElearning\Database;
|
||||
* use UElearning\Exception;
|
||||
* $db = new Database\DBAdmin();
|
||||
*
|
||||
*
|
||||
* 若要自行指定連結參數,請使用:
|
||||
*
|
||||
*
|
||||
* use UElearning\Database;
|
||||
* $db = new Database\DBAdmin(array(
|
||||
* 'type' => 'mysql',
|
||||
@ -35,13 +35,13 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* 'dbname' => 'chu-elearning',
|
||||
* 'prefix' => 'chu_'
|
||||
* ));
|
||||
*
|
||||
* 可參考以下範例:
|
||||
*
|
||||
*
|
||||
* 可參考以下範例:
|
||||
*
|
||||
* require_once __DIR__.'/config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'Database/DBAdmin.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $db = new Database\DBAdmin();
|
||||
* } catch (Database\DatabaseNoSupportException $e) {
|
||||
@ -56,17 +56,17 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBAdmin extends Database {
|
||||
|
||||
|
||||
/**
|
||||
* 建立所有所需的資料表
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function createAllTable() {
|
||||
|
||||
|
||||
// 使用的資料庫系統為MySQL
|
||||
if($this->db_type == 'mysql') {
|
||||
|
||||
|
||||
// 所有要跑的SQL指令陣列
|
||||
$execSql = array(
|
||||
|
||||
@ -74,14 +74,14 @@ class DBAdmin extends Database {
|
||||
`TID` int(10) unsigned NOT NULL,
|
||||
`AID` int(10) unsigned NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
|
||||
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `".$this->db_prefix."AGroup` (
|
||||
`GID` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`GName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`GMemo` tinytext COLLATE utf8_unicode_ci,
|
||||
PRIMARY KEY (`GID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
|
||||
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `".$this->db_prefix."Area` (
|
||||
`AID` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '區域編號',
|
||||
`AName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '區域名稱',
|
||||
@ -199,7 +199,7 @@ class DBAdmin extends Database {
|
||||
PRIMARY KEY (`UsID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;"
|
||||
);
|
||||
|
||||
|
||||
// 執行此SQL指令
|
||||
foreach ($execSql as $value ){
|
||||
$this->connDB->exec($value);
|
||||
@ -209,4 +209,4 @@ class DBAdmin extends Database {
|
||||
throw new Exception\DatabaseNoSupportException($this->db_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,21 +14,21 @@ 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\DBStudyActivity();
|
||||
* // 現在開始一個活動
|
||||
* $db->insertActivity('yuan', '1', null, null, null, 0, false, null, true, null);
|
||||
* // 設定延後
|
||||
* $db->setDelay(40, -12);
|
||||
*
|
||||
*
|
||||
* // 查詢'yuan'的所有活動
|
||||
* $data = $db->queryAllActivityByUserId('yuan');
|
||||
* echo '<pre>';print_r($data);echo '</pre>';
|
||||
@ -39,10 +39,10 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBStudyActivity extends Database {
|
||||
|
||||
|
||||
/**
|
||||
* 建立一個活動
|
||||
*
|
||||
*
|
||||
* @param string $userId 使用者ID
|
||||
* @param string $themeId 主題ID
|
||||
* @param string $startTime 開始學習時間
|
||||
@ -55,61 +55,61 @@ class DBStudyActivity extends Database {
|
||||
* @param string $materialMode 教材模式
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function insertActivity($userId, $themeId, $startTime, $endTime,
|
||||
public function insertActivity($userId, $themeId, $startTime, $endTime,
|
||||
$learnTime, $delay, $timeForce,
|
||||
$learnStyle, $learnStyle_force, $materialMode)
|
||||
{
|
||||
|
||||
|
||||
// 自動填入未填的時間
|
||||
if(isset($startTime))
|
||||
if(isset($startTime))
|
||||
$to_startTime = $this->connDB->quote($startTime);
|
||||
else $to_startTime = "NOW()";
|
||||
|
||||
if(isset($endTime))
|
||||
|
||||
if(isset($endTime))
|
||||
$to_endTime = $this->connDB->quote($endTime);
|
||||
else $to_endTime = "NULL";
|
||||
|
||||
|
||||
// 未填入學習時間,將會自動取得主題學習時間
|
||||
if(isset($learnTime))
|
||||
if(isset($learnTime))
|
||||
$to_learnTime = $this->connDB->quote($learnTime);
|
||||
else $to_learnTime =
|
||||
else $to_learnTime =
|
||||
"(SELECT `ThLearnTime` FROM `".$this->table('Theme').
|
||||
"` WHERE `ThID` = ".$this->connDB->quote($themeId).")";
|
||||
|
||||
|
||||
// 未填入學習風格,將會取用使用者偏好的風格,若帳號未設定,將取用系統預設的學習風格
|
||||
$queryResult = array();
|
||||
if(!isset($learnStyle) || !isset($materialMode)) {
|
||||
$sqlSUser = "SELECT `LMode`, `MMode` ".
|
||||
"FROM `".$this->table('User')."` ".
|
||||
"WHERE `UID`=".$this->connDB->quote($userId);
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlSUser);
|
||||
$query->execute();
|
||||
|
||||
$query->execute();
|
||||
|
||||
$queryResult = $query->fetch();
|
||||
}
|
||||
if(isset($learnStyle))
|
||||
if(isset($learnStyle))
|
||||
$to_learnStyle = $this->connDB->quote($learnStyle);
|
||||
else if(isset($queryResult['LMode']))
|
||||
else if(isset($queryResult['LMode']))
|
||||
$to_learnStyle = $queryResult['LMode'];
|
||||
else
|
||||
$to_learnStyle = LMODE;
|
||||
|
||||
if(isset($materialMode))
|
||||
|
||||
if(isset($materialMode))
|
||||
$to_materialMode = $this->connDB->quote($materialMode);
|
||||
else if(isset($queryResult['MMode']))
|
||||
else if(isset($queryResult['MMode']))
|
||||
$to_materialMode = "'".$queryResult['MMode']."'";
|
||||
else
|
||||
$to_materialMode = "'".MMODE."'";
|
||||
|
||||
|
||||
|
||||
|
||||
// 寫入學習活動資料
|
||||
$sqlString = "INSERT INTO `".$this->table('StudyActivity').
|
||||
"` (`UID`, `ThID`,
|
||||
`StartTime`, `EndTime`, `LearnTime`, `Delay`, `TimeForce`,
|
||||
`LMode`, `LModeForce`, `MMode`)
|
||||
VALUES ( :uid , :thid ,
|
||||
".$to_startTime.", ".$to_endTime.", ".$to_learnTime." , :delay , :timeforce ,
|
||||
"` (`UID`, `ThID`,
|
||||
`StartTime`, `EndTime`, `LearnTime`, `Delay`, `TimeForce`,
|
||||
`LMode`, `LModeForce`, `MMode`)
|
||||
VALUES ( :uid , :thid ,
|
||||
".$to_startTime.", ".$to_endTime.", ".$to_learnTime." , :delay , :timeforce ,
|
||||
".$to_learnStyle.", :lstyle_force , ".$to_materialMode.")";
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
@ -119,75 +119,75 @@ class DBStudyActivity extends Database {
|
||||
$query->bindParam(":timeforce", $timeForce);
|
||||
$query->bindParam(":lstyle_force", $learnStyle_force);
|
||||
$query->execute();
|
||||
|
||||
|
||||
// 取得剛剛加入的ID
|
||||
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||
$query = $this->connDB->query($sqlString);
|
||||
$queryResult = $query->fetch();
|
||||
$resultId = $queryResult[0];
|
||||
|
||||
return $resultId;
|
||||
|
||||
return $resultId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除一場活動
|
||||
* @param int $id 活動編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function deleteActivity($id) {
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('StudyActivity').
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('StudyActivity').
|
||||
" WHERE `SaID` = :id ";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":id", $id);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryActivityByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT `SaID`, `UID`, `ThID`, ".
|
||||
"`StartTime`, `EndTime`, ".
|
||||
"`LearnTime`, `Delay`, `TimeForce`, ".
|
||||
"`LMode`, `LModeForce`, `MMode`, ".
|
||||
|
||||
"(SELECT count(`TID`)
|
||||
FROM `".$this->table('TBelong')."` AS `belong`
|
||||
|
||||
"(SELECT count(`TID`)
|
||||
FROM `".$this->table('TBelong')."` AS `belong`
|
||||
WHERE `belong`.`ThID` = `sa`.`ThID`) AS `TargetTotal`, ".
|
||||
|
||||
"(SELECT count(DISTINCT `TID`)
|
||||
FROM `".$this->table('Study')."` AS `study`
|
||||
WHERE `Out_TargetTime` IS NOT NULL
|
||||
|
||||
"(SELECT count(DISTINCT `TID`)
|
||||
FROM `".$this->table('Study')."` AS `study`
|
||||
WHERE `Out_TargetTime` IS NOT NULL
|
||||
AND `study`.`SaID` = `sa`.`SaID`) AS `LearnedTotal`".
|
||||
|
||||
|
||||
"FROM `".$this->table('StudyActivity')."` AS sa ".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
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; }
|
||||
|
||||
|
||||
array_push($result,
|
||||
array( 'activity_id' => $thisResult['SaID'],
|
||||
'user_id' => $thisResult['UID'],
|
||||
@ -202,7 +202,7 @@ class DBStudyActivity extends Database {
|
||||
'material_mode' => $thisResult['MMode'],
|
||||
'target_total' => $thisResult['TargetTotal'],
|
||||
'learned_total' => $thisResult['LearnedTotal']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
@ -212,26 +212,26 @@ class DBStudyActivity extends Database {
|
||||
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 活動資料陣列,格式為:
|
||||
* @return array 活動資料陣列,格式為:
|
||||
* array( 'activity_id' => <活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -247,12 +247,12 @@ class DBStudyActivity extends Database {
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* );
|
||||
* @param int $id 活動編號
|
||||
*/
|
||||
*/
|
||||
public function queryActivity($id) {
|
||||
|
||||
$queryResultAll =
|
||||
|
||||
$queryResultAll =
|
||||
$this->queryActivityByWhere("`SaID`=".$this->connDB->quote($id));
|
||||
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -262,14 +262,14 @@ class DBStudyActivity extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有活動資料
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_id' => <活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -285,21 +285,21 @@ class DBStudyActivity extends Database {
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllActivity() {
|
||||
|
||||
|
||||
return $this->queryActivityByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢此使用者所有活動資料
|
||||
*
|
||||
*
|
||||
* @param int $user_id 使用者ID
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_id' => <活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -313,71 +313,71 @@ class DBStudyActivity extends Database {
|
||||
* 'learned_total' => <已經完成多少標的學習>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllActivityByUserId($user_id) {
|
||||
|
||||
|
||||
return $this->queryActivityByWhere(
|
||||
"`UID`=".$this->connDB->quote($user_id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 設定結束時間
|
||||
*
|
||||
*
|
||||
* 只要一設定,就代表學習活動結束了
|
||||
* @param int $activity_id 活動編號
|
||||
* @param string $endTime 時間
|
||||
*/
|
||||
*/
|
||||
public function setEndTime($activity_id, $endTime) {
|
||||
$sqlString = "UPDATE ".$this->table('StudyActivity').
|
||||
" SET `EndTime` = :value".
|
||||
" WHERE `SaID` = :id";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->bindParam(':value', $endTime);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 設定立即結束
|
||||
*
|
||||
*
|
||||
* 只要一設定,就代表學習活動結束了
|
||||
* @param int $activity_id 活動編號
|
||||
*/
|
||||
*/
|
||||
public function setEndTimeNow($activity_id) {
|
||||
$sqlString = "UPDATE ".$this->table('StudyActivity').
|
||||
" SET `EndTime` = NOW()".
|
||||
" WHERE `SaID` = :id";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->execute();
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 設定延後時間
|
||||
*
|
||||
*
|
||||
* 只要一設定,就代表學習活動結束了
|
||||
* @param int $activity_id 活動編號
|
||||
* @param int $delay 延後時間(分)
|
||||
*/
|
||||
*/
|
||||
public function setDelay($activity_id, $delay) {
|
||||
$sqlString = "UPDATE ".$this->table('StudyActivity').
|
||||
" SET `Delay` = :value".
|
||||
" WHERE `SaID` = :id";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->bindParam(':id', $activity_id);
|
||||
$query->bindParam(':value', $delay);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 預約一個活動
|
||||
*
|
||||
*
|
||||
* @param string $userId 使用者ID
|
||||
* @param string $themeId 主題ID
|
||||
* @param string $startTime 開始生效時間
|
||||
@ -390,62 +390,62 @@ class DBStudyActivity extends Database {
|
||||
* @param string $isLock 是否鎖定不讓學生更改
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function insertWillActivity($userId, $themeId, $startTime, $expiredTime,
|
||||
public function insertWillActivity($userId, $themeId, $startTime, $expiredTime,
|
||||
$learnTime, $timeForce,
|
||||
$learnStyle, $learnStyle_force, $materialMode, $isLock)
|
||||
{
|
||||
|
||||
|
||||
// 自動填入未填的時間
|
||||
if(isset($startTime))
|
||||
if(isset($startTime))
|
||||
$to_startTime = $this->connDB->quote($startTime);
|
||||
else $to_startTime = "NOW()";
|
||||
|
||||
if(isset($expiredTime))
|
||||
|
||||
if(isset($expiredTime))
|
||||
$to_expiredTime = $this->connDB->quote($expiredTime);
|
||||
else $to_expiredTime = "NULL";
|
||||
|
||||
|
||||
// 未填入學習時間,將會自動取得主題學習時間
|
||||
if(isset($learnTime))
|
||||
if(isset($learnTime))
|
||||
$to_learnTime = $this->connDB->quote($learnTime);
|
||||
else $to_learnTime =
|
||||
else $to_learnTime =
|
||||
"(SELECT `ThLearnTime` FROM `".$this->table('Theme').
|
||||
"` WHERE `ThID` = ".$this->connDB->quote($themeId).")";
|
||||
|
||||
|
||||
// 未填入學習風格,將會取用使用者偏好的風格,若帳號未設定,將取用系統預設的學習風格
|
||||
$queryResult = array();
|
||||
if(!isset($learnStyle) || !isset($materialMode)) {
|
||||
$sqlSUser = "SELECT `LMode`, `MMode` ".
|
||||
"FROM `".$this->table('User')."` ".
|
||||
"WHERE `UID`=".$this->connDB->quote($userId);
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlSUser);
|
||||
$query->execute();
|
||||
|
||||
$query->execute();
|
||||
|
||||
$queryResult = $query->fetch();
|
||||
}
|
||||
if(isset($learnStyle))
|
||||
if(isset($learnStyle))
|
||||
$to_learnStyle = $this->connDB->quote($learnStyle);
|
||||
else if(isset($queryResult['LMode']))
|
||||
else if(isset($queryResult['LMode']))
|
||||
$to_learnStyle = $queryResult['LMode'];
|
||||
else
|
||||
$to_learnStyle = LMODE;
|
||||
|
||||
if(isset($materialMode))
|
||||
|
||||
if(isset($materialMode))
|
||||
$to_materialMode = $this->connDB->quote($materialMode);
|
||||
else if(isset($queryResult['MMode']))
|
||||
else if(isset($queryResult['MMode']))
|
||||
$to_materialMode = "'".$queryResult['MMode']."'";
|
||||
else
|
||||
$to_materialMode = "'".MMODE."'";
|
||||
|
||||
|
||||
// 寫入學習活動資料
|
||||
$sqlString = "INSERT INTO `".$this->table('StudyWill').
|
||||
"` (`UID`, `ThID`,
|
||||
`StartTime`, `ExpiredTime`, `LearnTime`, `TimeForce`,
|
||||
`LMode`, `LModeForce`, `MMode`, `Lock`)
|
||||
VALUES ( :uid , :thid ,
|
||||
".$to_startTime.", ".$to_expiredTime.", ".$to_learnTime." , :timeforce ,
|
||||
"` (`UID`, `ThID`,
|
||||
`StartTime`, `ExpiredTime`, `LearnTime`, `TimeForce`,
|
||||
`LMode`, `LModeForce`, `MMode`, `Lock`)
|
||||
VALUES ( :uid , :thid ,
|
||||
".$to_startTime.", ".$to_expiredTime.", ".$to_learnTime." , :timeforce ,
|
||||
".$to_learnStyle.", :lstyle_force , ".$to_materialMode.", :lock )";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":uid", $userId);
|
||||
$query->bindParam(":thid", $themeId);
|
||||
@ -453,76 +453,76 @@ class DBStudyActivity extends Database {
|
||||
$query->bindParam(":lstyle_force", $learnStyle_force);
|
||||
$query->bindParam(":lock", $isLock);
|
||||
$query->execute();
|
||||
|
||||
|
||||
// 取得剛剛加入的ID
|
||||
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||
$query = $this->connDB->query($sqlString);
|
||||
$queryResult = $query->fetch();
|
||||
$resultId = $queryResult[0];
|
||||
|
||||
return $resultId;
|
||||
|
||||
return $resultId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除一場預約
|
||||
* @param int $id 預約編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function deleteWillActivity($id) {
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('StudyWill').
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('StudyWill').
|
||||
" WHERE `SwID` = :id ";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":id", $id);
|
||||
$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`
|
||||
|
||||
"(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();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
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'],
|
||||
@ -538,7 +538,7 @@ class DBStudyActivity extends Database {
|
||||
'target_total' => $thisResult['TargetTotal'],
|
||||
'build_time' => $thisResult['BuildTime'],
|
||||
'modify_time' => $thisResult['ModifyTime']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
@ -548,25 +548,25 @@ class DBStudyActivity extends Database {
|
||||
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 活動資料陣列,格式為:
|
||||
* @return array 活動資料陣列,格式為:
|
||||
* array( 'activity_will_id' => <預約活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -583,12 +583,12 @@ class DBStudyActivity extends Database {
|
||||
* 'modify_time' => <修改時間>
|
||||
* );
|
||||
* @param int $id 活動編號
|
||||
*/
|
||||
*/
|
||||
public function queryWillActivity($id) {
|
||||
|
||||
$queryResultAll =
|
||||
|
||||
$queryResultAll =
|
||||
$this->queryWillActivityByWhere("`SwID`=".$this->connDB->quote($id));
|
||||
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -598,14 +598,14 @@ class DBStudyActivity extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有活動資料
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_will_id' => <預約活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -622,21 +622,21 @@ class DBStudyActivity extends Database {
|
||||
* 'modify_time' => <修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllWillActivity() {
|
||||
|
||||
|
||||
return $this->queryWillActivityByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢此使用者所有活動資料
|
||||
*
|
||||
*
|
||||
* @param int $user_id 使用者ID
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* @return array 學習活動資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'activity_id' => <預約活動流水編號>,
|
||||
* 'user_id' => <使用者ID>,
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -653,21 +653,21 @@ class DBStudyActivity extends Database {
|
||||
* 'modify_time' => <修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllWillActivityByUserId($user_id) {
|
||||
|
||||
|
||||
return $this->queryWillActivityByWhere(
|
||||
"`UID`=".$this->connDB->quote($user_id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改預約資訊
|
||||
*
|
||||
*
|
||||
* @param int $tId 標的編號
|
||||
* @param string $field 欄位名稱
|
||||
* @param string $value 內容
|
||||
*/
|
||||
*/
|
||||
public function changeWillActivityData($id, $field, $value) {
|
||||
$sqlField = null;
|
||||
switch($field) {
|
||||
@ -684,111 +684,111 @@ class DBStudyActivity extends Database {
|
||||
case 'is_lock': $sqlField = 'Lock'; break;
|
||||
default: $sqlField = $field; break;
|
||||
}
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('StudyWill').
|
||||
" SET `".$sqlField."` = :value".
|
||||
" , `ModifyTime` = NOW()".
|
||||
" WHERE `SwID` = :id";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':id', $id);
|
||||
$query->bindParam(':id', $id);
|
||||
$query->bindParam(':value', $value);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得可以學習的資訊
|
||||
*
|
||||
*
|
||||
* @param string $userId 使用者ID
|
||||
* @return array 可進行學習的資訊
|
||||
*/
|
||||
*/
|
||||
public function getEnableActivityByUserId($userId) {
|
||||
|
||||
$sqlString_SA = "
|
||||
SELECT 'study' AS `Type`,
|
||||
`SaID` AS `ID`, `SaID`, NULL AS `SwID`,
|
||||
`th`.`ThID`, `th`.`ThName`, `th`.`ThIntroduction`,
|
||||
|
||||
`StartTime`,
|
||||
FROM_UNIXTIME(UNIX_TIMESTAMP(`StartTime`)+(`LearnTime`+`Delay`)*60) AS `ExpiredTime`,
|
||||
(`LearnTime`+`Delay`) AS `HaveTime`, `LearnTime`, `Delay`,
|
||||
ceiling((UNIX_TIMESTAMP(`StartTime`)+(`LearnTime`+`Delay`)*60-UNIX_TIMESTAMP(NOW()))/60) AS `RemainingTime`, `TimeForce`,
|
||||
|
||||
`LMode`, `LModeForce`, `MMode`, '1' AS `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `sa`.`ThID`) AS ` TargetTotal`,
|
||||
SELECT 'study' AS `Type`,
|
||||
`SaID` AS `ID`, `SaID`, NULL AS `SwID`,
|
||||
`th`.`ThID`, `th`.`ThName`, `th`.`ThIntroduction`,
|
||||
|
||||
`StartTime`,
|
||||
FROM_UNIXTIME(UNIX_TIMESTAMP(`StartTime`)+(`LearnTime`+`Delay`)*60) AS `ExpiredTime`,
|
||||
(`LearnTime`+`Delay`) AS `HaveTime`, `LearnTime`, `Delay`,
|
||||
ceiling((UNIX_TIMESTAMP(`StartTime`)+(`LearnTime`+`Delay`)*60-UNIX_TIMESTAMP(NOW()))/60) AS `RemainingTime`, `TimeForce`,
|
||||
|
||||
`LMode`, `LModeForce`, `MMode`, '1' AS `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `sa`.`ThID`) AS ` TargetTotal`,
|
||||
(SELECT count(DISTINCT `TID`) FROM `".$this->table('Study')."` AS `study` WHERE `Out_TargetTime` IS NOT NULL AND `study`.`SaID` = `sa`.`SaID`) AS `LearnedTotal`
|
||||
|
||||
FROM `".$this->table('StudyActivity')."` AS `sa`
|
||||
LEFT JOIN `".$this->table('Theme')."` AS `th`
|
||||
ON `th`.`ThID` = `sa`.`ThID`
|
||||
LEFT JOIN `".$this->table('Theme')."` AS `th`
|
||||
ON `th`.`ThID` = `sa`.`ThID`
|
||||
WHERE `EndTime` IS NULL AND `UID` = :uid ";
|
||||
|
||||
|
||||
|
||||
|
||||
$sqlString_SW = "
|
||||
SELECT 'will' AS `Type`,
|
||||
`SwID` AS `ID`, NULL, `SwID`,
|
||||
`th`.`ThID`, `th`.`ThName`, `th`.`ThIntroduction`,
|
||||
|
||||
`StartTime`, `ExpiredTime`, `LearnTime` AS `HaveTime`, `LearnTime`, 0 AS `Delay`,
|
||||
`LearnTime` AS `RemainingTime`, `TimeForce`,
|
||||
|
||||
`LMode`, `LModeForce`, `MMode`, `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `sw`.`ThID`) AS `TargetTotal`,
|
||||
SELECT 'will' AS `Type`,
|
||||
`SwID` AS `ID`, NULL, `SwID`,
|
||||
`th`.`ThID`, `th`.`ThName`, `th`.`ThIntroduction`,
|
||||
|
||||
`StartTime`, `ExpiredTime`, `LearnTime` AS `HaveTime`, `LearnTime`, 0 AS `Delay`,
|
||||
`LearnTime` AS `RemainingTime`, `TimeForce`,
|
||||
|
||||
`LMode`, `LModeForce`, `MMode`, `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `sw`.`ThID`) AS `TargetTotal`,
|
||||
0 AS `LearnedTotal`
|
||||
|
||||
FROM `".$this->table('StudyWill')."` AS `sw`
|
||||
LEFT JOIN `".$this->table('Theme')."` AS `th`
|
||||
FROM `".$this->table('StudyWill')."` AS `sw`
|
||||
LEFT JOIN `".$this->table('Theme')."` AS `th`
|
||||
ON `th`.`ThID` = `sw`.`ThID`
|
||||
WHERE NOW()>=`StartTime` AND NOW()<`ExpiredTime` AND `UID` = :uid
|
||||
";
|
||||
|
||||
|
||||
WHERE NOW()>=`StartTime` AND NOW()<`ExpiredTime` AND `UID` = :uid
|
||||
";
|
||||
|
||||
|
||||
$sqlString_TG = "
|
||||
SELECT 'theme' AS `Type`,
|
||||
`ThID` AS `ID`, NULL, NULL,
|
||||
`ThID`, `ThName`, `ThIntroduction`,
|
||||
|
||||
NULL, NULL, `ThLearnTime` AS `HaveTime`, `ThLearnTime`, 0 AS `Delay`,
|
||||
`ThLearnTime` AS `RemainingTime`, NULL,
|
||||
|
||||
NULL, NULL, NULL, 0 AS `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `th`.`ThID`) AS `TargetTotal`,
|
||||
0 AS `LearnedTotal`
|
||||
SELECT 'theme' AS `Type`,
|
||||
`ThID` AS `ID`, NULL, NULL,
|
||||
`ThID`, `ThName`, `ThIntroduction`,
|
||||
|
||||
NULL, NULL, `ThLearnTime` AS `HaveTime`, `ThLearnTime`, 0 AS `Delay`,
|
||||
`ThLearnTime` AS `RemainingTime`, NULL,
|
||||
|
||||
NULL, NULL, NULL, 0 AS `Lock`,
|
||||
|
||||
(SELECT count(`TID`) FROM `".$this->table('TBelong')."` AS `belong` WHERE `belong`.`ThID` = `th`.`ThID`) AS `TargetTotal`,
|
||||
0 AS `LearnedTotal`
|
||||
|
||||
FROM `".$this->table('Theme')."` AS `th` WHERE (SELECT `UEnable_NoAppoint` FROM `".$this->table('User')."` WHERE `UID`= :uid ) = '1'
|
||||
";
|
||||
|
||||
|
||||
$sqlString = $sqlString_SA." UNION ".$sqlString_SW." UNION ".$sqlString_TG;
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":uid", $userId);
|
||||
$query->execute();
|
||||
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
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_lock = true;
|
||||
}
|
||||
else { $output_lock = false; }
|
||||
|
||||
|
||||
array_push($result,
|
||||
array( 'type' => $thisResult['Type'],
|
||||
'id' => $thisResult['ID'],
|
||||
@ -808,7 +808,7 @@ $sqlString = $sqlString_SA." UNION ".$sqlString_SW." UNION ".$sqlString_TG;
|
||||
'lock' => $thisResult['Lock'],
|
||||
'target_total' => $thisResult['TargetTotal'],
|
||||
'learned_total' => $thisResult['LearnedTotal']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
@ -817,6 +817,6 @@ $sqlString = $sqlString_SA." UNION ".$sqlString_SW." UNION ".$sqlString_TG;
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
|
||||
/**
|
||||
* 學習標的資料表
|
||||
*
|
||||
*
|
||||
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料表進行操作。
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
@ -24,14 +24,14 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBTarget extends Database {
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryTargetByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT `TID`, Target.`AID`, Area.`HID`, ".
|
||||
"`TNum`, `TName`, `TMapID`, `TLearnTime`, ".
|
||||
"`PLj`, `Mj`, `S`, IF(`Mj` >= `PLj`, 1, 0) AS Fj ".
|
||||
@ -39,17 +39,17 @@ class DBTarget extends Database {
|
||||
"LEFT JOIN `".$this->table('Area')."` as Area ".
|
||||
"ON Area.`AID` = Target.`AID` ".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
array_push($result,
|
||||
array( 'target_id' => $thisResult['TID'],
|
||||
'area_id' => $thisResult['AID'],
|
||||
@ -71,27 +71,27 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個標的資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBTarget();
|
||||
*
|
||||
*
|
||||
* $targetInfo = $db->queryTarget(4);
|
||||
* echo '<pre>'; print_r($targetInfo); echo '</pre>';
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $tId 標的ID
|
||||
* @return array 標的資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 標的資料陣列,格式為:
|
||||
* array(
|
||||
* 'target_id' => <標的ID>,
|
||||
* 'area_id' => <標的所在的區域ID>,
|
||||
* 'hall_id' => <標的所在的廳ID>,
|
||||
@ -104,12 +104,12 @@ class DBTarget extends Database {
|
||||
* 'S' => <學習標的飽和率上限>,
|
||||
* 'Fj' => <學習標的滿額指標>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryTarget($tId) {
|
||||
|
||||
$queryResultAll = $this->queryTargetByWhere("`TID`=".$this->connDB->quote($tId));
|
||||
|
||||
|
||||
$queryResultAll = $this->queryTargetByWhere("`TID`=".$this->connDB->quote($tId));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -119,14 +119,14 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有標的資料
|
||||
*
|
||||
* @return array 標的資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 標的資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'target_id' => <標的ID>,
|
||||
* 'area_id' => <標的所在的區域ID>,
|
||||
* 'hall_id' => <標的所在的廳ID>,
|
||||
@ -140,20 +140,20 @@ class DBTarget extends Database {
|
||||
* 'Fj' => <學習標的滿額指標>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllTarget() {
|
||||
|
||||
|
||||
return $this->queryAreaByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改一個標的資訊
|
||||
*
|
||||
*
|
||||
* @param int $tId 標的編號
|
||||
* @param string $field 欄位名稱
|
||||
* @param string $value 內容
|
||||
*/
|
||||
*/
|
||||
public function changeTargetData($tId, $field, $value) {
|
||||
$sqlField = null;
|
||||
switch($field) {
|
||||
@ -169,40 +169,40 @@ class DBTarget extends Database {
|
||||
case 'Fj': $sqlField = 'Fj'; break;
|
||||
default: $sqlField = $field; break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('Target').
|
||||
" SET `".$sqlField."` = :value".
|
||||
" WHERE `TID` = :tid";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':tid', $tId);
|
||||
$query->bindParam(':tid', $tId);
|
||||
$query->bindParam(':value', $value);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryAreaByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT * FROM `".$this->table('Area')."`".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
array_push($result,
|
||||
array( 'area_id' => $thisResult['AID'],
|
||||
'hall_id' => $thisResult['HID'],
|
||||
@ -220,26 +220,26 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個區域資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBTarget();
|
||||
*
|
||||
*
|
||||
* $areaInfo = $db->queryArea(4);
|
||||
* echo '<pre>'; print_r($areaInfo); echo '</pre>';
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $aId 區域ID
|
||||
* @return array 區域資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 區域資料陣列,格式為:
|
||||
* array(
|
||||
* 'area_id' => <區域ID>,
|
||||
* 'hall_id' => <區域所在的廳ID>,
|
||||
* 'floor' => <區域所在的樓層>,
|
||||
@ -248,12 +248,12 @@ class DBTarget extends Database {
|
||||
* 'map_url' => <地圖路徑>,
|
||||
* 'introduction' => <區域簡介>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryArea($aId) {
|
||||
|
||||
$queryResultAll = $this->queryAreaByWhere("`AID`=".$this->connDB->quote($aId));
|
||||
|
||||
|
||||
$queryResultAll = $this->queryAreaByWhere("`AID`=".$this->connDB->quote($aId));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -263,14 +263,14 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有區域資料
|
||||
*
|
||||
* @return array 區域資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 區域資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'area_id' => <區域ID>,
|
||||
* 'hall_id' => <區域所在的廳ID>,
|
||||
* 'floor' => <區域所在的樓層>,
|
||||
@ -280,20 +280,20 @@ class DBTarget extends Database {
|
||||
* 'introduction' => <區域簡介>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllArea() {
|
||||
|
||||
|
||||
return $this->queryAreaByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
///**
|
||||
// * 修改一個標的資訊
|
||||
// *
|
||||
// *
|
||||
// * @param int $tId 標的編號
|
||||
// * @param string $field 欄位名稱
|
||||
// * @param string $value 內容
|
||||
// */
|
||||
// */
|
||||
//function changeTargetData($tId, $field, $value) {
|
||||
////TODO: 待修成Area
|
||||
// $sqlField = null;
|
||||
@ -310,40 +310,40 @@ class DBTarget extends Database {
|
||||
// case 'Fj': $sqlField = 'Fj'; break;
|
||||
// default: $sqlField = $field; break;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// $sqlString = "UPDATE ".$this->table('Target').
|
||||
// " SET `".$sqlField."` = :value".
|
||||
// " WHERE `TID` = :tid";
|
||||
//
|
||||
//
|
||||
// $query = $this->connDB->prepare($sqlString);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':value', $value);
|
||||
// $query->execute();
|
||||
// $query->execute();
|
||||
//}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryHallByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT * FROM `".$this->table('Hall')."`".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
array_push($result,
|
||||
array( 'hall_id' => $thisResult['HID'],
|
||||
'name' => $thisResult['HName'],
|
||||
@ -358,37 +358,37 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個廳資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBTarget();
|
||||
*
|
||||
*
|
||||
* $hallInfo = $db->queryHall(1);
|
||||
* echo '<pre>'; print_r($hallInfo); echo '</pre>';
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $hId 廳ID
|
||||
* @return array 區域資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 區域資料陣列,格式為:
|
||||
* array(
|
||||
* 'hall_id' => <廳的ID>,
|
||||
* 'name' => <廳名稱>,
|
||||
* 'map_url' => <地圖路徑>,
|
||||
* 'introduction' => <區域簡介>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryHall($hId) {
|
||||
|
||||
$queryResultAll = $this->queryHallByWhere("`HID`=".$this->connDB->quote($hId));
|
||||
|
||||
|
||||
$queryResultAll = $this->queryHallByWhere("`HID`=".$this->connDB->quote($hId));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -398,33 +398,33 @@ class DBTarget extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有區域資料
|
||||
*
|
||||
* @return array 區域資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 區域資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'hall_id' => <廳的廳ID>,
|
||||
* 'name' => <廳名稱>,
|
||||
* 'map_url' => <地圖路徑>,
|
||||
* 'introduction' => <區域簡介>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllHall() {
|
||||
|
||||
|
||||
return $this->queryHallByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
///**
|
||||
// * 修改一個標的資訊
|
||||
// *
|
||||
// *
|
||||
// * @param int $tId 標的編號
|
||||
// * @param string $field 欄位名稱
|
||||
// * @param string $value 內容
|
||||
// */
|
||||
// */
|
||||
//function changeTargetData($tId, $field, $value) {
|
||||
////TODO: 待修成Area
|
||||
// $sqlField = null;
|
||||
@ -441,16 +441,16 @@ class DBTarget extends Database {
|
||||
// case 'Fj': $sqlField = 'Fj'; break;
|
||||
// default: $sqlField = $field; break;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// $sqlString = "UPDATE ".$this->table('Target').
|
||||
// " SET `".$sqlField."` = :value".
|
||||
// " WHERE `TID` = :tid";
|
||||
//
|
||||
//
|
||||
// $query = $this->connDB->prepare($sqlString);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':value', $value);
|
||||
// $query->execute();
|
||||
// $query->execute();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,32 +19,32 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBTheme extends Database {
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryThemeByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT `ThID`, `ThName`, ".
|
||||
"`ThLearnTime`, `ThIntroduction`, ".
|
||||
"`ThBuildTime`, `ThModifyTime`, ".
|
||||
"(SELECT count(`TID`) FROM `chu__TBelong` AS `belong`
|
||||
"(SELECT count(`TID`) FROM `chu__TBelong` AS `belong`
|
||||
WHERE `belong`.`ThID` = `theme`.`ThID`) AS `TargetTotal`".
|
||||
"FROM `".$this->table('Theme')."` AS `theme` ".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
array_push($result,
|
||||
array( 'theme_id' => $thisResult['ThID'],
|
||||
'name' => $thisResult['ThName'],
|
||||
@ -62,27 +62,27 @@ class DBTheme extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個主題資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBTheme();
|
||||
*
|
||||
*
|
||||
* $info = $db->queryTheme(1);
|
||||
* echo '<pre>'; print_r($info); echo '</pre>';
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $thId 主題ID
|
||||
* @return array 主題資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 主題資料陣列,格式為:
|
||||
* array(
|
||||
* 'theme_id' => <主題ID>,
|
||||
* 'name' => <主題名稱>,
|
||||
* 'learn_time' => <預估的學習時間>,
|
||||
@ -91,13 +91,13 @@ class DBTheme extends Database {
|
||||
* 'build_time' => <主題建立時間>,
|
||||
* 'modify_time' => <主題資料修改時間>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryTheme($thId) {
|
||||
|
||||
$queryResultAll =
|
||||
|
||||
$queryResultAll =
|
||||
$this->queryThemeByWhere("`ThID`=".$this->connDB->quote($thId));
|
||||
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -107,14 +107,14 @@ class DBTheme extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有主題資料
|
||||
*
|
||||
* @return array 主題資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 主題資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'theme_id' => <主題ID>,
|
||||
* 'name' => <主題名稱>,
|
||||
* 'learn_time' => <預估的學習時間>,
|
||||
@ -124,20 +124,20 @@ class DBTheme extends Database {
|
||||
* 'modify_time' => <主題資料修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllTheme() {
|
||||
|
||||
|
||||
return $this->queryThemeByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 修改一個標的資訊
|
||||
// *
|
||||
// *
|
||||
// * @param int $tId 標的編號
|
||||
// * @param string $field 欄位名稱
|
||||
// * @param string $value 內容
|
||||
// */
|
||||
// */
|
||||
// public function changeTargetData($tId, $field, $value) {
|
||||
// $sqlField = null;
|
||||
// switch($field) {
|
||||
@ -153,16 +153,16 @@ class DBTheme extends Database {
|
||||
// case 'Fj': $sqlField = 'Fj'; break;
|
||||
// default: $sqlField = $field; break;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// $sqlString = "UPDATE ".$this->table('Target').
|
||||
// " SET `".$sqlField."` = :value".
|
||||
// " WHERE `TID` = :tid";
|
||||
//
|
||||
//
|
||||
// $query = $this->connDB->prepare($sqlString);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':tid', $tId);
|
||||
// $query->bindParam(':value', $value);
|
||||
// $query->execute();
|
||||
// $query->execute();
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
|
||||
/**
|
||||
* 使用者帳號資料表
|
||||
*
|
||||
*
|
||||
* 對資料庫中的使用者資料表進行操作。
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
@ -24,23 +24,23 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBUser extends Database {
|
||||
|
||||
|
||||
const FORM_USER = 'User';
|
||||
|
||||
|
||||
/**
|
||||
* 新增一個使用者
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBUser.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $db = new Database\DBUser();
|
||||
*
|
||||
*
|
||||
* $db->insertUser(
|
||||
* array(
|
||||
* array(
|
||||
* 'user_id' => 'eric',
|
||||
* 'password' => 'passwd',
|
||||
* 'group_id' => 'user',
|
||||
@ -48,11 +48,11 @@ class DBUser extends Database {
|
||||
* 'enable_noAppoint' => true
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* echo 'Finish';
|
||||
* }
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* // 若設定的DBMS不被支援 則丟出例外
|
||||
* catch (Exception\DatabaseNoSupportException $e) {
|
||||
* echo 'No Support in ', $e->getType();
|
||||
@ -60,9 +60,9 @@ class DBUser extends Database {
|
||||
* echo 'Caught other exception: ', $e->getMessage();
|
||||
* echo '<h2>'. $e->getCode() .'</h2>';
|
||||
* }
|
||||
*
|
||||
* @param array $array 使用者資料陣列,格式為:
|
||||
* array(
|
||||
*
|
||||
* @param array $array 使用者資料陣列,格式為:
|
||||
* array(
|
||||
* 'user_id' => <帳號名稱>,
|
||||
* 'password' => <密碼>,
|
||||
* 'group_id' => <群組>,
|
||||
@ -76,12 +76,12 @@ class DBUser extends Database {
|
||||
* 'email' => <電子郵件地址>,
|
||||
* 'memo' => <備註>
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function insertUser($array){
|
||||
|
||||
|
||||
|
||||
|
||||
if( !isset($array['class_id']) ){
|
||||
$array['class_id'] = null;
|
||||
}
|
||||
@ -104,7 +104,7 @@ class DBUser extends Database {
|
||||
$array['memo'] = null;
|
||||
}
|
||||
// TODO: 不填enable, enable_noAppoint也要能操作
|
||||
|
||||
|
||||
$uId = $array['user_id'];
|
||||
$password = $array['password'];
|
||||
$gId = $array['group_id'];
|
||||
@ -117,13 +117,13 @@ class DBUser extends Database {
|
||||
$realName = $array['realname'];
|
||||
$email = $array['email'];
|
||||
$memo = $array['memo'];
|
||||
|
||||
|
||||
//紀錄使用者帳號進資料庫
|
||||
$sqlString = "INSERT INTO ".$this->table('User').
|
||||
" (`UID`, `UPassword`, `GID`, `CID`, `UEnabled`,
|
||||
`LMode`, `MMode`, `UEnable_NoAppoint`,
|
||||
" (`UID`, `UPassword`, `GID`, `CID`, `UEnabled`,
|
||||
`LMode`, `MMode`, `UEnable_NoAppoint`,
|
||||
`UNickname`, `URealName`, `UEmail`, `UMemo`)
|
||||
VALUES ( :id , :passwd, :gid , :cid , :enable ,
|
||||
VALUES ( :id , :passwd, :gid , :cid , :enable ,
|
||||
:lmode , :mmode , :enpublic ,
|
||||
:nickname , :realname , :email , :memo )";
|
||||
|
||||
@ -141,20 +141,20 @@ class DBUser extends Database {
|
||||
$query->bindParam(":email", $email);
|
||||
$query->bindParam(":memo", $memo);
|
||||
$query->execute();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除一位使用者
|
||||
* @param string $uId 使用者名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function deleteUser($uId) {
|
||||
|
||||
|
||||
//if($this->db_type == 'mysql') {
|
||||
$sqlString = "DELETE FROM ".$this->table(self::FORM_USER).
|
||||
$sqlString = "DELETE FROM ".$this->table(self::FORM_USER).
|
||||
" WHERE `UID` = :id ";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":id", $uId);
|
||||
$query->execute();
|
||||
@ -163,14 +163,14 @@ class DBUser extends Database {
|
||||
// throw new Exception\DatabaseNoSupportException($this->db_type);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryUserByWhere($where) {
|
||||
|
||||
|
||||
$sqlString = "SELECT `UID`, `UPassword`, ".
|
||||
"`group`.`GID`, `group`.`GName`, `class`.`CID`, `class`.`CName`, ".
|
||||
"`UEnabled`, `UBuildTime`, `UModifyTime`, ".
|
||||
@ -182,27 +182,27 @@ class DBUser extends Database {
|
||||
"LEFT JOIN `".$this->table('CGroup')."` as `class` ".
|
||||
"ON `class`.`CID` = `user`.`CID`".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
if($thisResult['UEnabled'] != '0') {
|
||||
$output_enable = true;
|
||||
}
|
||||
else { $output_enable = false; }
|
||||
|
||||
|
||||
if($thisResult['UEnable_NoAppoint'] != '0') {
|
||||
$output_enable_noAppoint = true;
|
||||
}
|
||||
else { $output_enable_noAppoint = false; }
|
||||
|
||||
|
||||
array_push($result,
|
||||
array( 'user_id' => $thisResult['UID'],
|
||||
'password' => $thisResult['UPassword'],
|
||||
@ -228,26 +228,26 @@ class DBUser extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一位使用者帳號資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBUser.php';
|
||||
* use UElearning\Database;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $db = new Database\DBUser();
|
||||
*
|
||||
*
|
||||
* $userInfo = $db->queryUser('yuan');
|
||||
* echo '<pre>'; print_r($userInfo); echo '</pre>';
|
||||
* }
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* // 若設定的DBMS不被支援 則丟出例外
|
||||
* catch (Exception\DatabaseNoSupportException $e) {
|
||||
* echo 'No Support in ', $e->getType();
|
||||
@ -255,10 +255,10 @@ class DBUser extends Database {
|
||||
* echo 'Caught other exception: ', $e->getMessage();
|
||||
* echo '<h2>'. $e->getCode() .'</h2>';
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param string $uId 使用者名稱
|
||||
* @return array 使用者資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 使用者資料陣列,格式為:
|
||||
* array(
|
||||
* 'user_id' => <帳號名稱>,
|
||||
* 'password' => <密碼>,
|
||||
* 'group_id' => <群組>,
|
||||
@ -274,13 +274,13 @@ class DBUser extends Database {
|
||||
* 'email' => <電子郵件地址>,
|
||||
* 'memo' => <備註>
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function queryUser($uId) {
|
||||
|
||||
$queryResultAll = $this->queryUserByWhere("`UID`=".$this->connDB->quote($uId));
|
||||
|
||||
|
||||
$queryResultAll = $this->queryUserByWhere("`UID`=".$this->connDB->quote($uId));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -290,14 +290,14 @@ class DBUser extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有的使用者帳號資料
|
||||
*
|
||||
* @return array 使用者資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 使用者資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'user_id' => <帳號名稱>,
|
||||
* 'password' => <密碼>,
|
||||
* 'group_id' => <群組>,
|
||||
@ -314,26 +314,26 @@ class DBUser extends Database {
|
||||
* 'memo' => <備註>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllUser() {
|
||||
return $this->queryUserByWhere("1");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改一位使用者的資料內容
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBUser();
|
||||
* $db->changeUserData('yuan', 'memo', 'hahaha');
|
||||
*
|
||||
*
|
||||
* @param string $uId 使用者名稱
|
||||
* @param string $field 欄位名稱
|
||||
* @param string $value 內容
|
||||
*/
|
||||
*/
|
||||
public function changeUserData($uId, $field, $value) {
|
||||
|
||||
|
||||
$sqlField = null;
|
||||
switch($field) {
|
||||
case 'user_id': $sqlField = 'UID'; break;
|
||||
@ -352,37 +352,37 @@ class DBUser extends Database {
|
||||
case 'memo': $sqlField = 'UMemo'; break;
|
||||
default: $sqlField = $field; break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('User').
|
||||
" SET `".$sqlField."` = :value".
|
||||
" , `UModifyTime` = NOW()".
|
||||
" WHERE `UID` = :uid";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->bindParam(':value', $value);
|
||||
|
||||
$query->execute();
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 插入群組資料
|
||||
*
|
||||
* @param array $array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @param array $array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
* array( 'group_id' => <群組ID>,
|
||||
* 'name' => <群組顯示名稱>,
|
||||
* 'memo' => <備註>,
|
||||
* 'auth_admin' => <Server端管理權>,
|
||||
* 'auth_clientAdmin' => <Client端管理權>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function insertGroup($array) {
|
||||
|
||||
|
||||
// TODO: 不填以下欄位也能進行操作
|
||||
if( !isset($array['name']) ){
|
||||
$array['name'] = null;
|
||||
@ -397,13 +397,13 @@ class DBUser extends Database {
|
||||
$array['auth_clientAdmin'] = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$gId = $array['group_id'];
|
||||
$name = $array['name'];
|
||||
$memo = $array['memo'];
|
||||
$auth_admin = $array['auth_admin'];
|
||||
$auth_clientAdmin = $array['auth_clientAdmin'];
|
||||
|
||||
|
||||
// 紀錄使用者帳號進資料庫
|
||||
$sqlString = "INSERT INTO ".$this->table('AGroup').
|
||||
" (`GID`, `GName`, `GMemo`, `GAuth_Admin`, `GAuth_ClientAdmin`)
|
||||
@ -417,40 +417,40 @@ class DBUser extends Database {
|
||||
$query->bindParam(":auth_clientAdmin", $auth_clientAdmin);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除一個使用者群組
|
||||
* @param string $gId
|
||||
*/
|
||||
* @param string $gId
|
||||
*/
|
||||
public function deleteGroup($gId) {
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('AGroup').
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('AGroup').
|
||||
" WHERE `GID` = :id ";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":id", $gId);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryGroupByWhere($where) {
|
||||
$sqlString = "SELECT * FROM ".$this->table('AGroup').
|
||||
" WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
// 轉換成boolean
|
||||
if($thisResult['GAuth_Admin'] != '0') {
|
||||
$output_auth_admin = true;
|
||||
@ -461,7 +461,7 @@ class DBUser extends Database {
|
||||
} else { $output_auth_clientAdmin = false; }
|
||||
|
||||
// 製作回傳結果陣列
|
||||
array_push($result,
|
||||
array_push($result,
|
||||
array('group_id' => $thisResult['GID'],
|
||||
'name' => $thisResult['GName'],
|
||||
'memo' => $thisResult['GMemo'],
|
||||
@ -471,7 +471,7 @@ class DBUser extends Database {
|
||||
'auth_clientAdmin' => $output_auth_clientAdmin)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
// 若都沒查到的話
|
||||
@ -480,13 +480,13 @@ class DBUser extends Database {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個使用者群組資料
|
||||
*
|
||||
*
|
||||
* @param string $gId 群組ID
|
||||
* @return array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
* @return array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
* array( 'group_id' => <群組ID>,
|
||||
* 'name' => <群組顯示名稱>,
|
||||
* 'memo' => <備註>,
|
||||
@ -495,12 +495,12 @@ class DBUser extends Database {
|
||||
* 'auth_admin' => <Server端管理權>,
|
||||
* 'auth_clientAdmin' => <Client端管理權>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryGroup($gId) {
|
||||
|
||||
|
||||
$queryResultAll = $this->queryGroupByWhere("`GID`=".$this->connDB->quote($gId));
|
||||
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -510,14 +510,14 @@ class DBUser extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有的使用者群組資料
|
||||
*
|
||||
* @return array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 使用者群組資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'group_id' => <群組ID>,
|
||||
* 'name' => <群組顯示名稱>,
|
||||
* 'memo' => <備註>,
|
||||
@ -527,27 +527,27 @@ class DBUser extends Database {
|
||||
* 'auth_clientAdmin' => <Client端管理權>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllGroup() {
|
||||
|
||||
|
||||
return $this->queryGroupByWhere('1');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改一個群組的資料內容
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBUser();
|
||||
* $db->changeGroupData('student', 'name', '學生');
|
||||
*
|
||||
*
|
||||
* @param string $gId 群組ID
|
||||
* @param string $field 欄位名稱
|
||||
* @param string $value 內容
|
||||
*/
|
||||
*/
|
||||
public function changeGroupData($gId, $field, $value) {
|
||||
|
||||
|
||||
$sqlField = null;
|
||||
switch($field) {
|
||||
case 'group_id': $sqlField = 'GID'; break;
|
||||
@ -557,40 +557,40 @@ class DBUser extends Database {
|
||||
case 'auth_clientAdmin': $sqlField = 'GAuth_ClientAdmin'; break;
|
||||
default: $sqlField = $field; break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('AGroup').
|
||||
" SET `".$sqlField."` = :value".
|
||||
" , `GModifyTime` = NOW()".
|
||||
" WHERE `GID` = :gid";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':gid', $gId);
|
||||
$query->bindParam(':gid', $gId);
|
||||
$query->bindParam(':value', $value);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 插入班級資料
|
||||
*
|
||||
* @param array $array 班級資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @param array $array 班級資料陣列,格式為:
|
||||
*
|
||||
* array( 'class_id' => <班級ID>,
|
||||
* 'name' => <班級顯示名稱>,
|
||||
* 'memo' => <備註>
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @return int 剛剛新增的ID
|
||||
*/
|
||||
*/
|
||||
public function insertClassGroup($array) {
|
||||
|
||||
|
||||
$cId = $array['class_id'];
|
||||
// TODO: 不填以下欄位也能進行操作
|
||||
$name = $array['name'];
|
||||
$memo = $array['memo'];
|
||||
|
||||
|
||||
// 紀錄使用者帳號進資料庫
|
||||
$sqlString = "INSERT INTO ".$this->table('CGroup').
|
||||
" (`CID`, `CName`, `CMemo`)
|
||||
@ -601,48 +601,48 @@ class DBUser extends Database {
|
||||
$query->bindParam(":name", $name);
|
||||
$query->bindParam(":memo", $memo);
|
||||
$query->execute();
|
||||
|
||||
|
||||
// 取得剛剛加入的ID
|
||||
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||
$query = $this->connDB->query($sqlString);
|
||||
$queryResult = $query->fetch();
|
||||
|
||||
|
||||
if(isset($cId)) return $cId;
|
||||
return $queryResult[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除一個班級
|
||||
* @param string $cId
|
||||
*/
|
||||
* @param string $cId
|
||||
*/
|
||||
public function deleteClassGroup($cId) {
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('CGroup').
|
||||
|
||||
$sqlString = "DELETE FROM ".$this->table('CGroup').
|
||||
" WHERE `CID` = :id ";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":id", $cId);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
*/
|
||||
protected function queryClassByWhere($where) {
|
||||
$sqlString = "SELECT * FROM ".$this->table('CGroup').
|
||||
" WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
array_push($result,
|
||||
array( 'class_id' => $thisResult['CID'],
|
||||
'name' => $thisResult['CName'],
|
||||
@ -651,7 +651,7 @@ class DBUser extends Database {
|
||||
'modify_time' => $thisResult['CModifyTime'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
// 若都沒查到的話
|
||||
@ -660,25 +660,25 @@ class DBUser extends Database {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個班級資料
|
||||
*
|
||||
*
|
||||
* @param int $cId 班級ID
|
||||
* @return array 班級資料陣列,格式為:
|
||||
*
|
||||
* @return array 班級資料陣列,格式為:
|
||||
*
|
||||
* array( 'class_id' => <班級ID>,
|
||||
* 'name' => <班級顯示名稱>,
|
||||
* 'memo' => <備註>,
|
||||
* 'build_time' => <建立時間>,
|
||||
* 'modify_time' => <修改時間>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryClassGroup($cId) {
|
||||
|
||||
|
||||
$queryResultAll = $this->queryClassByWhere("`CID`=".$this->connDB->quote($cId));
|
||||
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
@ -688,14 +688,14 @@ class DBUser extends Database {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢所有的班級資料
|
||||
*
|
||||
* @return array 班級資料陣列,格式為:
|
||||
*
|
||||
*
|
||||
* @return array 班級資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'class_id' => <班級ID>,
|
||||
* 'name' => <班級顯示名稱>,
|
||||
* 'memo' => <備註>,
|
||||
@ -703,27 +703,27 @@ class DBUser extends Database {
|
||||
* 'modify_time' => <修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
public function queryAllClassGroup() {
|
||||
|
||||
|
||||
return $this->queryClassByWhere('1');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改一個群組的資料內容
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* $db = new Database\DBUser();
|
||||
* $db->changeClassGroupData(2, 'name', '五年一班');
|
||||
*
|
||||
*
|
||||
* @param string $cId 班級ID
|
||||
* @param string $field 欄位名稱
|
||||
* @param string $value 內容
|
||||
*/
|
||||
*/
|
||||
public function changeClassGroupData($cId, $field, $value) {
|
||||
|
||||
|
||||
$sqlField = null;
|
||||
switch($field) {
|
||||
case 'class_id': $sqlField = 'CID'; break;
|
||||
@ -731,29 +731,29 @@ class DBUser extends Database {
|
||||
case 'memo': $sqlField = 'CMemo'; break;
|
||||
default: $sqlField = $field; break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('CGroup').
|
||||
" SET `".$sqlField."` = :value".
|
||||
" , `CModifyTime` = NOW()".
|
||||
" WHERE `CID` = :cid";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':cid', $cId);
|
||||
$query->bindParam(':cid', $cId);
|
||||
$query->bindParam(':value', $value);
|
||||
$query->execute();
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 設定自動編號的起始值
|
||||
* @param int $num 自動編號起始值
|
||||
*/
|
||||
*/
|
||||
public function setClassGroupIDAutoIncrement($num) {
|
||||
|
||||
|
||||
// TODO: 不帶值的話,以最後編號為起頭
|
||||
$sqlString = "ALTER TABLE ".$this->table('CGroup').
|
||||
" AUTO_INCREMENT = $num";
|
||||
|
||||
|
||||
$this->connDB->exec($sqlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
|
||||
/**
|
||||
* 使用者帳號資料表
|
||||
*
|
||||
*
|
||||
* 對資料庫中的使用者資料表進行操作。
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
@ -22,15 +22,15 @@ require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBUserSession extends Database {
|
||||
|
||||
|
||||
/**
|
||||
* 新增登入資料
|
||||
* @param string $token 登入token
|
||||
* @param string $uId 帳號ID
|
||||
* @param string $agent 登入所使用的裝置
|
||||
*/
|
||||
*/
|
||||
public function login($token, $uId, $agent) {
|
||||
|
||||
|
||||
//紀錄登入階段進資料庫
|
||||
$sqlString = "INSERT INTO ".$this->table('UserSession').
|
||||
" (`UsID`, `UToken`, `UID`, `UAgent`, `ULoginDate`, `ULogoutDate`)
|
||||
@ -42,44 +42,44 @@ class DBUserSession extends Database {
|
||||
$query->bindParam(":agent", $agent);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 標注此登入階段為登出
|
||||
* @param string $token 登入token
|
||||
*/
|
||||
*/
|
||||
public function logout($token) {
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('UserSession').
|
||||
" SET `UToken` = NULL, `ULogoutDate` = NOW()
|
||||
" SET `UToken` = NULL, `ULogoutDate` = NOW()
|
||||
WHERE `UToken` = :token";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":token", $token);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 標注此帳號所有的登入階段為登出
|
||||
* @param string $uid 帳號ID
|
||||
* @return int 修改幾筆資料
|
||||
*/
|
||||
*/
|
||||
public function logoutByUserId($uid) {
|
||||
|
||||
|
||||
$sqlString = "UPDATE ".$this->table('UserSession').
|
||||
" SET `UToken` = NULL, `ULogoutDate` = NOW()
|
||||
" SET `UToken` = NULL, `ULogoutDate` = NOW()
|
||||
WHERE `UID` = :uid AND `UToken` IS NOT NULL";
|
||||
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(":uid", $uid);
|
||||
$query->execute();
|
||||
return $query->rowCount();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以token查詢
|
||||
* @param string $token 登入token
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* array(
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* array(
|
||||
* 'session_id' => <登入編號>,
|
||||
* 'token' => <登入Token>,
|
||||
* 'user_id' => <使用者>,
|
||||
@ -87,21 +87,21 @@ class DBUserSession extends Database {
|
||||
* 'login_date' => <登入時間>,
|
||||
* 'logout_date' => <登出時間>
|
||||
* );
|
||||
*/
|
||||
*/
|
||||
public function queryByToken($token) {
|
||||
$sqlString = "SELECT * FROM ".$this->table('UserSession').
|
||||
" WHERE `UToken` = :token";
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':token', $token);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':token', $token);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
$queryResult = $queryResultAll[0];
|
||||
|
||||
$result = array(
|
||||
|
||||
$result = array(
|
||||
'session_id' => $queryResult['UsID'],
|
||||
'token' => $queryResult['UToken'],
|
||||
'user_id' => $queryResult['UID'],
|
||||
@ -114,13 +114,13 @@ class DBUserSession extends Database {
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以使用者ID查詢
|
||||
* @param string $uId 使用者ID
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'session_id' => <登入編號>,
|
||||
* 'token' => <登入Token>,
|
||||
* 'user_id' => <使用者>,
|
||||
@ -129,22 +129,22 @@ class DBUserSession extends Database {
|
||||
* 'logout_date' => <登出時間>
|
||||
* )
|
||||
* );
|
||||
*/
|
||||
*/
|
||||
public function queryByUserId($uId) {
|
||||
$sqlString = "SELECT * FROM ".$this->table('UserSession').
|
||||
" WHERE `UID` = :uid";
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
|
||||
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
array_push($result,
|
||||
array(
|
||||
'session_id' => $thisResult['UsID'],
|
||||
@ -160,13 +160,13 @@ class DBUserSession extends Database {
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以使用者ID查詢,目前所有已登入的登入階段
|
||||
* @param string $uId 使用者ID
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* @return array 登入階段資料陣列,格式為:
|
||||
* array(
|
||||
* array(
|
||||
* array(
|
||||
* 'session_id' => <登入編號>,
|
||||
* 'token' => <登入Token>,
|
||||
* 'user_id' => <使用者>,
|
||||
@ -175,22 +175,22 @@ class DBUserSession extends Database {
|
||||
* 'logout_date' => <登出時間>
|
||||
* )
|
||||
* );
|
||||
*/
|
||||
*/
|
||||
public function queryLoginByUserId($uId) {
|
||||
$sqlString = "SELECT * FROM ".$this->table('UserSession').
|
||||
" WHERE `UID` = :uid AND `UToken` IS NOT NULL";
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->bindParam(':uid', $uId);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
|
||||
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
array_push($result,
|
||||
array(
|
||||
'session_id' => $thisResult['UsID'],
|
||||
@ -206,5 +206,5 @@ class DBUserSession extends Database {
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* Database.php
|
||||
*
|
||||
* 此檔案針對整體資料庫的功能,像是建立此資料庫、建立表格、清空...等等
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace UElearning\Database;
|
||||
@ -14,12 +14,12 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 資料庫操作抽象類別
|
||||
*
|
||||
*
|
||||
* 請根據一個資料表創建一個類別,並繼承此類別。
|
||||
* 所有對於資料表的操作(包含查詢、新增、修改、刪除),一律使用新創已繼承的類別物件。
|
||||
*
|
||||
*
|
||||
* 基本的操作方式例如:
|
||||
*
|
||||
*
|
||||
* use UElearning\Database;
|
||||
* $db = new Database\[資料表類別](array(
|
||||
* 'type' => 'mysql',
|
||||
@ -39,66 +39,66 @@ use UElearning\Exception;
|
||||
* @subpackage Database
|
||||
*/
|
||||
abstract class Database {
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫伺服器類型
|
||||
*
|
||||
*
|
||||
* 目前支援的:
|
||||
* * mysql
|
||||
*
|
||||
* @type string
|
||||
* * mysql
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
protected $db_type;
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫伺服器位址
|
||||
* @type string
|
||||
*/
|
||||
protected $db_host;
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫伺服器連結埠
|
||||
* @type string
|
||||
*/
|
||||
protected $db_port;
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫帳號
|
||||
* @type string
|
||||
*/
|
||||
protected $db_user;
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫密碼
|
||||
* @type string
|
||||
*/
|
||||
protected $db_passwd;
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫名稱
|
||||
* @type string
|
||||
*/
|
||||
protected $db_name;
|
||||
|
||||
|
||||
/**
|
||||
* 資料表前綴字元
|
||||
* @type string
|
||||
*/
|
||||
protected $db_prefix;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 資料庫連結物件
|
||||
* @type UElearning\Database\PDODB
|
||||
*/
|
||||
protected $connDB;
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 連接資料庫
|
||||
*
|
||||
*
|
||||
* @param array $conf (optional) 資料庫相關參數,格式為:
|
||||
* array( 'type' => 'mysql',
|
||||
* 'host' => 'localhost',
|
||||
@ -108,13 +108,13 @@ abstract class Database {
|
||||
* 'dbname' => 'chu-elearning',
|
||||
* 'prefix' => 'chu_' )
|
||||
* 若不填寫將會直接使用設定在`config.php`的常數
|
||||
*
|
||||
*
|
||||
* @throws UElearning\Exception\DatabaseNoSupportException
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($conf = null) {
|
||||
|
||||
|
||||
// 將資料庫設定資訊帶入
|
||||
if(isset($conf)) {
|
||||
$this->db_type = $conf['type'];
|
||||
@ -134,7 +134,7 @@ abstract class Database {
|
||||
$this->db_name = DB_NAME;
|
||||
$this->db_prefix = DB_PREFIX;
|
||||
}
|
||||
|
||||
|
||||
// 檢查是否有支援所設定的DBMS
|
||||
if($this->db_type == 'mysql') {
|
||||
$this->connDB = new MySQLDB($this->db_name
|
||||
@ -147,27 +147,27 @@ abstract class Database {
|
||||
throw new Exception\DatabaseNoSupportException($this->db_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 轉為完整的資料表名稱(包含前綴字元)
|
||||
*
|
||||
*
|
||||
* @param string $tableName 資料表名稱
|
||||
* @return string 完整的資料表名稱
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function table($tableName) {
|
||||
return $this->db_prefix.$tableName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 測試資料庫有無連接成功
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function connectTest() {
|
||||
// TODO: Fill code in
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,28 +8,28 @@ namespace UElearning\Exception;
|
||||
/**
|
||||
* 沒有支援的資料庫系統例外
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
class DatabaseNoSupportException extends \UnexpectedValueException {
|
||||
|
||||
|
||||
/**
|
||||
* 欲使用的資料庫系統名稱
|
||||
* @type string
|
||||
*/
|
||||
*/
|
||||
private $type;
|
||||
|
||||
|
||||
/**
|
||||
* 沒有支援的資料庫系統
|
||||
* @param array $type 資料庫系統名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct($type) {
|
||||
$this->type = $type;
|
||||
parent::__construct('No support: '.$this->type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的資料庫系統名稱
|
||||
* @return string 錯誤訊息內容
|
||||
*/
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception.php
|
||||
*
|
||||
*
|
||||
* 通用例外類別檔案
|
||||
*/
|
||||
|
||||
@ -11,24 +11,24 @@ namespace UElearning\Exception;
|
||||
* 沒填入資料例外
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
*/
|
||||
*/
|
||||
class NoDataException extends \UnexpectedValueException {
|
||||
|
||||
|
||||
/**
|
||||
* 指定的使用者名稱
|
||||
* @type string|array 欄位名稱
|
||||
*/
|
||||
*/
|
||||
private $fieldName;
|
||||
|
||||
|
||||
/**
|
||||
* 未填資料例外
|
||||
* @param string|array $fieldName 欄位名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct() {
|
||||
if(func_num_args() == 1){
|
||||
$args = func_get_args();
|
||||
$fieldName = $args[0];
|
||||
|
||||
|
||||
$this->fieldName = $fieldName;
|
||||
parent::__construct();
|
||||
}
|
||||
@ -36,18 +36,18 @@ class NoDataException extends \UnexpectedValueException {
|
||||
$this->fieldName = array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增一項未輸入的欄位名稱
|
||||
*/
|
||||
*/
|
||||
public function addFieldName($fieldName) {
|
||||
$this->fieldName += array($fieldName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得未輸入的欄位名稱
|
||||
* @return string|array 欄位名稱
|
||||
*/
|
||||
*/
|
||||
public function getFieldName() {
|
||||
return $this->fieldName;
|
||||
}
|
||||
|
@ -12,27 +12,27 @@ namespace UElearning\Exception;
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
*/
|
||||
class StudyActivityNoFoundException 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;
|
||||
}
|
||||
@ -43,27 +43,27 @@ class StudyActivityNoFoundException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
*/
|
||||
class StudyActivityFinishedException 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;
|
||||
}
|
||||
@ -74,27 +74,27 @@ 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;
|
||||
}
|
||||
@ -105,27 +105,27 @@ class StudyActivityWillNoFoundException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
*/
|
||||
class ThemeNoFoundException 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;
|
||||
}
|
||||
|
@ -14,19 +14,19 @@ use UElearning\User;
|
||||
|
||||
/**
|
||||
* 學習階段類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一個學習活動
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
|
||||
* use UElearning\Study;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try{
|
||||
* $sact = new Study\StudyActivity(8);
|
||||
*
|
||||
*
|
||||
* echo $sact->getId();
|
||||
* echo $sact->getUserId();
|
||||
* echo $sact->getThemeId();
|
||||
@ -36,7 +36,7 @@ use UElearning\User;
|
||||
* $sact->setDelay(23);
|
||||
* echo $sact->getDelay();
|
||||
* echo $sact->isLearning();
|
||||
*
|
||||
*
|
||||
* $sact->finishActivity();
|
||||
* }
|
||||
* catch (Exception\StudyActivityNoFoundException $e) {
|
||||
@ -45,7 +45,7 @@ use UElearning\User;
|
||||
* catch (Exception\StudyActivityFinishedException $e) {
|
||||
* echo 'The learnActivity is over: '. $e->getId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
@ -53,63 +53,63 @@ use UElearning\User;
|
||||
class StudyActivity {
|
||||
/**
|
||||
* 學習階段流水號ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
protected $id;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery() {
|
||||
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery() {
|
||||
|
||||
// 從資料庫查詢
|
||||
$db = new Database\DBStudyActivity();
|
||||
$info = $db->queryActivity($this->id);
|
||||
|
||||
|
||||
// 判斷有沒有這個
|
||||
if( $info != null ) {
|
||||
$this->queryResultArray = $info;
|
||||
}
|
||||
else throw new Exception\StudyActivityNoFoundException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputID 學習階段流水號ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputID 學習階段流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputID) {
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
*/
|
||||
public function __construct($inputID) {
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 控制這次學習階段時間:
|
||||
|
||||
|
||||
/**
|
||||
* 結束這次學習
|
||||
* *
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* 結束這次學習
|
||||
* *
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function finishActivity() {
|
||||
|
||||
*/
|
||||
public function finishActivity() {
|
||||
|
||||
// 此活動還在進行中
|
||||
if($this->isLearning()) {
|
||||
$db = new Database\DBStudyActivity();
|
||||
@ -117,204 +117,204 @@ class StudyActivity {
|
||||
}
|
||||
// 此活動已結束
|
||||
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤銷這次學習
|
||||
*
|
||||
* 撤銷這次學習
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function cancelActivity() {
|
||||
//return $this->queryResultArray['name'];
|
||||
*/
|
||||
public function cancelActivity() {
|
||||
//return $this->queryResultArray['name'];
|
||||
// TODO: cancelActivity
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 此學習階段是否正在學習中
|
||||
*/
|
||||
*/
|
||||
public function isLearning() {
|
||||
if(!isset($this->queryResultArray['end_time'])) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 總共要學幾個學習點
|
||||
*
|
||||
*
|
||||
* @return int 有幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getPointTotal() {
|
||||
return $this->queryResultArray['target_total'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得已經學過幾個學習點
|
||||
*
|
||||
*
|
||||
* @return int 已學過幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getLearnedPointTotal() {
|
||||
return $this->queryResultArray['learned_total'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得還剩下幾個學習點還沒學
|
||||
*
|
||||
*
|
||||
* @return int 還剩下幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getRemainingPointTotal() {
|
||||
$total = $this->getPointTotal();
|
||||
$learned = $this->getLearnedPointTotal();
|
||||
|
||||
|
||||
return $total - $learned;
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
// 取得資料:
|
||||
|
||||
/**
|
||||
* 取得學習階段流水號ID
|
||||
*
|
||||
* @return int 學習階段流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
// 取得資料:
|
||||
|
||||
/**
|
||||
* 取得這次是誰在學習物件
|
||||
*
|
||||
* @return \UElearning\User\User 使用者物件
|
||||
* 取得學習階段流水號ID
|
||||
*
|
||||
* @return int 學習階段流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUser() {
|
||||
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次是誰在學習物件
|
||||
*
|
||||
* @return \UElearning\User\User 使用者物件
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUser() {
|
||||
|
||||
$userId = $this->queryResultArray['user_id'];;
|
||||
return new User\User($userId);
|
||||
}
|
||||
|
||||
return new User\User($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次是誰在學習
|
||||
*
|
||||
* @return string 使用者ID
|
||||
* 取得這次是誰在學習
|
||||
*
|
||||
* @return string 使用者ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->queryResultArray['user_id'];
|
||||
}
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->queryResultArray['user_id'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 取得這次是學哪個主題物件
|
||||
// *
|
||||
// * @return int 主題物件
|
||||
// * 取得這次是學哪個主題物件
|
||||
// *
|
||||
// * @return int 主題物件
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function getTheme() {
|
||||
// */
|
||||
//public function getTheme() {
|
||||
// $tId = $this->queryResultArray['theme_id'];
|
||||
// return new Target\User($userId);;
|
||||
//}
|
||||
|
||||
// return new Target\User($userId);;
|
||||
//}
|
||||
|
||||
/**
|
||||
* 取得這次是學哪個主題
|
||||
*
|
||||
* @return int 主題ID
|
||||
* 取得這次是學哪個主題
|
||||
*
|
||||
* @return int 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getThemeId() {
|
||||
return $this->queryResultArray['theme_id'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getThemeId() {
|
||||
return $this->queryResultArray['theme_id'];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 時間控制:
|
||||
|
||||
|
||||
/**
|
||||
* 取得這次學習是什麼時候開始的
|
||||
*
|
||||
* @return string 開始學習時間
|
||||
* 取得這次學習是什麼時候開始的
|
||||
*
|
||||
* @return string 開始學習時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getStartTime() {
|
||||
return $this->queryResultArray['start_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getStartTime() {
|
||||
return $this->queryResultArray['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習是什麼時候結束的
|
||||
*
|
||||
* @return string 結束學習時間
|
||||
* 取得這次學習是什麼時候結束的
|
||||
*
|
||||
* @return string 結束學習時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getEndTime() {
|
||||
return $this->queryResultArray['end_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getEndTime() {
|
||||
return $this->queryResultArray['end_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* 取得這次學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime() {
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getLearnTime() {
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次可實際學習時間(包含延時)
|
||||
*
|
||||
* @return int 可實際學習時間(分)
|
||||
* 取得這次可實際學習時間(包含延時)
|
||||
*
|
||||
* @return int 可實際學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getRealLearnTimeWith() {
|
||||
|
||||
*/
|
||||
public function getRealLearnTimeWith() {
|
||||
|
||||
$learnTime = $this->queryResultArray['learn_time'];
|
||||
$delay = $this->queryResultArray['delay'];
|
||||
return $learnTime + $delay;
|
||||
}
|
||||
|
||||
return $learnTime + $delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習還剩下多少學習時間
|
||||
*
|
||||
* @return int 剩下的學習時間(分)
|
||||
* 取得這次學習還剩下多少學習時間
|
||||
*
|
||||
* @return int 剩下的學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getRemainingTime() {
|
||||
|
||||
|
||||
// TODO: 取得這次學習還剩下多少學習時間
|
||||
|
||||
|
||||
// 計算總共學習時間(包含延長時間)
|
||||
$haveTime = $this->getLearnTime() - $this->getDelay();
|
||||
|
||||
|
||||
// 取得現在時間
|
||||
// 開始時間+學習時間 = 應結束時間
|
||||
|
||||
|
||||
// 應結束時間-現在時間 = 剩餘時間
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得這次學習時間要延長多久
|
||||
*
|
||||
* @return int 延長時間(分)
|
||||
* 取得這次學習時間要延長多久
|
||||
*
|
||||
* @return int 延長時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getDelay() {
|
||||
return $this->queryResultArray['delay'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getDelay() {
|
||||
return $this->queryResultArray['delay'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這次學習時間要延長多久
|
||||
*
|
||||
* @param int $minute 延長時間(分)
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* 設定這次學習時間要延長多久
|
||||
*
|
||||
* @param int $minute 延長時間(分)
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setDelay($minute) {
|
||||
|
||||
*/
|
||||
public function setDelay($minute) {
|
||||
|
||||
// 此活動還在進行中
|
||||
if($this->isLearning()) {
|
||||
|
||||
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->setDelay($this->id, $minute);
|
||||
|
||||
@ -322,20 +322,20 @@ class StudyActivity {
|
||||
}
|
||||
// 此活動已結束
|
||||
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定累加這次學習時間要延長多久
|
||||
*
|
||||
* @param int $minute 延長時間(分)
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* 設定累加這次學習時間要延長多久
|
||||
*
|
||||
* @param int $minute 延長時間(分)
|
||||
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function addDelay($minute) {
|
||||
|
||||
*/
|
||||
public function addDelay($minute) {
|
||||
|
||||
// 此活動還在進行中
|
||||
if($this->isLearning()) {
|
||||
|
||||
|
||||
$setMinute = $this->queryResultArray['delay'] + $minute;
|
||||
|
||||
$db = new Database\DBStudyActivity();
|
||||
@ -347,48 +347,48 @@ class StudyActivity {
|
||||
}
|
||||
// 此活動已結束
|
||||
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @return bool 是否在這次學習時間已過而強制結束學習
|
||||
* 在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @return bool 是否在這次學習時間已過而強制結束學習
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isForceLearnTime() {
|
||||
return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function isForceLearnTime() {
|
||||
return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 取得這次學習的導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* 取得這次學習的導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnStyle() {
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getLearnStyle() {
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 在這次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @return bool 是否拒絕前往非推薦的學習點
|
||||
* 在這次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @return bool 是否拒絕前往非推薦的學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isForceLearnStyle() {
|
||||
return $this->queryResultArray['learnStyle_force'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function isForceLearnStyle() {
|
||||
return $this->queryResultArray['learnStyle_force'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* 取得這次學習的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaterialStyle() {
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function getMaterialStyle() {
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* StudyActivityManager
|
||||
*/
|
||||
*/
|
||||
namespace UElearning\Study;
|
||||
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
|
||||
@ -12,35 +12,35 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 學習階段管理類別
|
||||
*
|
||||
*
|
||||
* 開始活動、預約活動所用的
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
class StudyActivityManager {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Type} $uid
|
||||
* @param {Type} tid
|
||||
* @param {Type} mmode
|
||||
*
|
||||
* @param {Type} $uid
|
||||
* @param {Type} tid
|
||||
* @param {Type} mmode
|
||||
* @return bool 輸入的資料是否存在來新增學習活動記錄
|
||||
*/
|
||||
protected function checkDataIsExist($uid, $tid, $mmode) {
|
||||
|
||||
protected function checkDataIsExist($uid, $tid, $mmode) {
|
||||
|
||||
// TODO: 使用者存不存在
|
||||
|
||||
|
||||
// TODO: 標的存不存在
|
||||
|
||||
|
||||
// TODO: 教材是否存在
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 開始這次學習
|
||||
*
|
||||
*
|
||||
* @param string $userId 使用者ID
|
||||
* @param string $themeId 主題ID
|
||||
* @param int $learnTime 所需學習時間(分)
|
||||
@ -50,32 +50,32 @@ class StudyActivityManager {
|
||||
* @param string $materialMode 教材風格
|
||||
* @return int 本次學習活動的流水編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function startActivity( $userId, $themeId, $learnTime, $timeForce,
|
||||
*/
|
||||
public function startActivity( $userId, $themeId, $learnTime, $timeForce,
|
||||
$learnStyle, $learnStyle_force, $materialMode )
|
||||
{
|
||||
|
||||
if($this->checkDataIsExist($userId, $themeId, $materialMode)) {
|
||||
|
||||
|
||||
// 存入資料庫
|
||||
$db = new Database\DBStudyActivity();
|
||||
$resultId = $db->insertActivity($userId, $themeId, null, null,
|
||||
$resultId = $db->insertActivity($userId, $themeId, null, null,
|
||||
$learnTime, 0, $timeForce, $learnStyle, $learnStyle_force, $materialMode);
|
||||
|
||||
// 傳回新增後得到的編號
|
||||
return $resultId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從預約開始進行學習活動
|
||||
*
|
||||
*
|
||||
* @param int $swid 預約編號
|
||||
* @return int 本次學習活動的流水編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function startWithWillActivity($swid) {
|
||||
|
||||
|
||||
// 取得預約資料
|
||||
$sact = new StudyWill($swid);
|
||||
$userId = $sact->getUserId();
|
||||
@ -85,14 +85,14 @@ class StudyActivityManager {
|
||||
$learnStyle = $sact->getLearnStyle();
|
||||
$learnStyle_force = $sact->isForceLearnStyle();
|
||||
$materialMode = $sact->getMaterialStyle();
|
||||
|
||||
$this->startActivity( $userId, $themeId, $learnTime, $timeForce,
|
||||
|
||||
$this->startActivity( $userId, $themeId, $learnTime, $timeForce,
|
||||
$learnStyle, $learnStyle_force, $materialMode );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 幫學生預約學習
|
||||
*
|
||||
*
|
||||
* @param string $userId 使用者ID
|
||||
* @param string $themeId 主題ID
|
||||
* @param string $startTime 預約開始時間
|
||||
@ -105,32 +105,32 @@ class StudyActivityManager {
|
||||
* @param bool $lock 是否鎖定不讓學生更改
|
||||
* @return int 預約學習活動的流水編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function createWiilActivity($userId, $themeId, $startTime, $expiredTime,
|
||||
$learnTime, $timeForce, $learnStyle, $learnStyle_force, $materialMode, $lock)
|
||||
{
|
||||
|
||||
|
||||
if($this->checkDataIsExist($userId, $themeId, $materialMode)) {
|
||||
|
||||
|
||||
// 存入資料庫
|
||||
$db = new Database\DBStudyActivity();
|
||||
$resultId = $db->insertWillActivity($userId, $themeId,
|
||||
$startTime, $expiredTime, $learnTime, $timeForce,
|
||||
$resultId = $db->insertWillActivity($userId, $themeId,
|
||||
$startTime, $expiredTime, $learnTime, $timeForce,
|
||||
$learnStyle, $learnStyle_force, $materialMode, $lock);
|
||||
|
||||
// 傳回新增後得到的編號
|
||||
return $resultId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 取得這位學生可以使用的學習活動有哪些
|
||||
*
|
||||
*
|
||||
* @param string $user_id 使用者ID
|
||||
* @return array 可用的學習活動資訊,格式如下:
|
||||
*
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'type' => <類型>,
|
||||
@ -153,12 +153,12 @@ class StudyActivityManager {
|
||||
* 'learned_total' => <還剩下幾個學習點還沒學>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getEnableActivityByUserId($user_id) {
|
||||
|
||||
|
||||
$db = new Database\DBStudyActivity();
|
||||
return $db->getEnableActivityByUserId($user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ use UElearning\User;
|
||||
|
||||
/**
|
||||
* 預約學習階段類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一個主題
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
@ -23,363 +23,363 @@ use UElearning\User;
|
||||
class StudyWill {
|
||||
/**
|
||||
* 預約學習階段流水號ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
protected $id;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw UElearning\Exception\AreaNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw UElearning\Exception\AreaNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
// 從資料庫查詢
|
||||
$db = new Database\DBStudyActivity();
|
||||
$info = $db->queryWillActivity($this->id);
|
||||
|
||||
|
||||
// 判斷有沒有這個
|
||||
if( $info != null ) {
|
||||
$this->queryResultArray = $info;
|
||||
}
|
||||
else throw new Exception\StudyActivityWillNoFoundException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputID 預約學習流水號ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputID 預約學習流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputID){
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
*/
|
||||
public function __construct($inputID){
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 控制這次學習階段:
|
||||
|
||||
|
||||
/**
|
||||
* 撤銷這次預約
|
||||
*
|
||||
* 撤銷這次預約
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function cancel(){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function cancel(){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->deleteWillActivity($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 取得資料:
|
||||
|
||||
/**
|
||||
* 取得預約學習階段流水號ID
|
||||
*
|
||||
* @return int 預約學習階段流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
// 取得資料:
|
||||
|
||||
/**
|
||||
* 取得是誰要預約學習的使用者物件
|
||||
*
|
||||
* @return \UElearning\User\User 使用者物件
|
||||
* 取得預約學習階段流水號ID
|
||||
*
|
||||
* @return int 預約學習階段流水號ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUser(){
|
||||
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得是誰要預約學習的使用者物件
|
||||
*
|
||||
* @return \UElearning\User\User 使用者物件
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUser(){
|
||||
|
||||
$userId = $this->queryResultArray['user_id'];;
|
||||
return new User\User($userId);
|
||||
}
|
||||
|
||||
return new User\User($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得是誰要預約學習
|
||||
*
|
||||
* @return string 使用者ID
|
||||
* 取得是誰要預約學習
|
||||
*
|
||||
* @return string 使用者ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUserId(){
|
||||
return $this->queryResultArray['user_id'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getUserId(){
|
||||
return $this->queryResultArray['user_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這次是誰要預約學習
|
||||
*
|
||||
* @param string $user_id 使用者ID
|
||||
* 設定這次是誰要預約學習
|
||||
*
|
||||
* @param string $user_id 使用者ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setUserById($user_id){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setUserById($user_id){
|
||||
$db = new Database\DBStudyActivity();
|
||||
// TODO: 檢查使用者有無存在
|
||||
$db->changeWillActivityData($this->id, 'user_id', $user_id);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
}
|
||||
|
||||
///**
|
||||
// * 取得這次預約是學哪個主題物件
|
||||
// *
|
||||
// * @return int 主題物件
|
||||
// * 取得這次預約是學哪個主題物件
|
||||
// *
|
||||
// * @return int 主題物件
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function getTheme(){
|
||||
// */
|
||||
//public function getTheme(){
|
||||
// $tId = $this->queryResultArray['theme_id'];
|
||||
// return new Target\User($userId);;
|
||||
//}
|
||||
|
||||
// return new Target\User($userId);;
|
||||
//}
|
||||
|
||||
/**
|
||||
* 取得這次預約是學哪個主題
|
||||
*
|
||||
* @return int 主題ID
|
||||
* 取得這次預約是學哪個主題
|
||||
*
|
||||
* @return int 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getThemeId(){
|
||||
return $this->queryResultArray['theme_id'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getThemeId(){
|
||||
return $this->queryResultArray['theme_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這次要預約學哪個主題
|
||||
*
|
||||
* @param int $theme_id 主題ID
|
||||
* 設定這次要預約學哪個主題
|
||||
*
|
||||
* @param int $theme_id 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setThemeById($theme_id){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setThemeById($theme_id){
|
||||
$db = new Database\DBStudyActivity();
|
||||
// TODO: 檢查主體有無存在
|
||||
$db->changeWillActivityData($this->id, 'thime_id', $theme_id);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習是預約在什麼時候開始
|
||||
*
|
||||
* @return string 開始學習預約時間
|
||||
* 取得這次學習是預約在什麼時候開始
|
||||
*
|
||||
* @return string 開始學習預約時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getStartTime(){
|
||||
return $this->queryResultArray['start_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getStartTime(){
|
||||
return $this->queryResultArray['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這次學習是預約在什麼時候開始
|
||||
*
|
||||
* @param string $time 開始學習預約時間
|
||||
* 設定這次學習是預約在什麼時候開始
|
||||
*
|
||||
* @param string $time 開始學習預約時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setStartTime($time){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setStartTime($time){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'start_time', $time);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這次學習預約什麼時候過期
|
||||
*
|
||||
* @return string 過期預約時間
|
||||
* 取得這次學習預約什麼時候過期
|
||||
*
|
||||
* @return string 過期預約時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getExpiredTime(){
|
||||
return $this->queryResultArray['expired_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getExpiredTime(){
|
||||
return $this->queryResultArray['expired_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這次學習預約什麼時候過期
|
||||
*
|
||||
* @param string $time 過期預約時間
|
||||
* 設定這次學習預約什麼時候過期
|
||||
*
|
||||
* @param string $time 過期預約時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setExpiredTime($time){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setExpiredTime($time){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'expired_time', $time);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預約學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* 取得預約學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定預約學習所需時間
|
||||
*
|
||||
* @param int $min 所需學習時間(分)
|
||||
* 設定預約學習所需時間
|
||||
*
|
||||
* @param int $min 所需學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setLearnTime($min){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setLearnTime($min){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'learn_time', $min);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @return bool 是否在這次學習時間已過而強制結束學習
|
||||
* 在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @return bool 是否在這次學習時間已過而強制結束學習
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isForceLearnTime() {
|
||||
return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function isForceLearnTime() {
|
||||
return $this->queryResultArray['time_force'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @param bool $value 是否在這次學習時間已過而強制結束學習
|
||||
* 設定在這次學習時間已過,是否強制結束學習
|
||||
*
|
||||
* @param bool $value 是否在這次學習時間已過而強制結束學習
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setForceLearnTime($value) {
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setForceLearnTime($value) {
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'time_force', $value);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預約學習的導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* 取得預約學習的導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定預約學習的導引風格
|
||||
*
|
||||
* @param int $num 將推薦幾個學習點
|
||||
* 設定預約學習的導引風格
|
||||
*
|
||||
* @param int $num 將推薦幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setLearnStyle($num){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setLearnStyle($num){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'learnStyle_mode', $num);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在這次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @return bool 是否拒絕前往非推薦的學習點
|
||||
* 在這次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @return bool 是否拒絕前往非推薦的學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isForceLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_force'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function isForceLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_force'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 預約本次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @param bool $value 是否拒絕前往非推薦的學習點
|
||||
* 預約本次學習,是否拒絕使用者前往非推薦的學習點
|
||||
*
|
||||
* @param bool $value 是否拒絕前往非推薦的學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setForceLearnStyle($value){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setForceLearnStyle($value){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'learnStyle_force', $value);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預約學習的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* 取得預約學習的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaterialStyle(){
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getMaterialStyle(){
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定預約學習的教材風格
|
||||
*
|
||||
* @param string $value 教材風格
|
||||
* 設定預約學習的教材風格
|
||||
*
|
||||
* @param string $value 教材風格
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMaterialStyle($value){
|
||||
$db = new Database\DBStudyActivity();
|
||||
*/
|
||||
public function setMaterialStyle($value){
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'material_mode', $value);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得開始學習此預約前,是否允許讓學生自行更改設定
|
||||
*
|
||||
* @return bool 是否允許讓學生自行更改設定
|
||||
*
|
||||
* @return bool 是否允許讓學生自行更改設定
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function isLock() {
|
||||
return $this->queryResultArray['is_lock'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 設定開始學習此預約前,是否允許讓學生自行更改設定
|
||||
*
|
||||
*
|
||||
* @param bool $value 是否允許讓學生自行更改設定
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
function setLock($value) {
|
||||
$db = new Database\DBStudyActivity();
|
||||
$db->changeWillActivityData($this->id, 'is_lock', $value);
|
||||
|
||||
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 總共要學幾個學習點
|
||||
*
|
||||
*
|
||||
* @return int 有幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getPointTotal() {
|
||||
return $this->queryResultArray['target_total'];
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得此預約建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得此預約修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* 取得此預約建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得此預約修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,158 +12,158 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 主題專用類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一個主題
|
||||
*
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Study/Theme.php';
|
||||
* use UElearning\Study;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try{
|
||||
* $theme = new Study\Theme(1);
|
||||
*
|
||||
*
|
||||
* echo $theme->getId();
|
||||
* echo $theme->getName();
|
||||
* echo $theme->getIntroduction();
|
||||
* echo $theme->getLearnTime();
|
||||
* echo $theme->getCreateTime();
|
||||
* echo $theme->getModifyTime();
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\ThemeNoFoundException $e) {
|
||||
* echo 'No Found theme: '. $e->getId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
class Theme {
|
||||
|
||||
|
||||
/**
|
||||
* 主題ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
protected $id;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw \UElearning\Exception\ThemeNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
/**
|
||||
* 查詢到所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得查詢
|
||||
*
|
||||
* @throw \UElearning\Exception\ThemeNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// TODO: 從資料庫取得查詢
|
||||
//// 從資料庫查詢
|
||||
$db = new Database\DBTheme();
|
||||
$info = $db->queryTheme($this->id);
|
||||
|
||||
|
||||
// 判斷有沒有這個
|
||||
if( $info != null ) {
|
||||
$this->queryResultArray = $info;
|
||||
}
|
||||
else throw new Exception\ThemeNoFoundException($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
* 從資料庫更新設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
// TODO: 從資料庫更新設定
|
||||
// 將新設定寫進資料庫裡
|
||||
//$db = new Database\DBTarget();
|
||||
//$db = new Database\DBTarget();
|
||||
//$db->changeTargetData($this->tId, $field, $value);
|
||||
//$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputTID 主題ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputTID 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputID){
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
*/
|
||||
public function __construct($inputID){
|
||||
$this->id = $inputID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得主題ID
|
||||
*
|
||||
* @return int 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得主題名稱
|
||||
*
|
||||
* @return string 主題名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得主題介紹
|
||||
*
|
||||
* @return string 主題介紹
|
||||
* 取得主題ID
|
||||
*
|
||||
* @return int 主題ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得此主題學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* 取得主題名稱
|
||||
*
|
||||
* @return string 主題名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* 取得主題介紹
|
||||
*
|
||||
* @return string 主題介紹
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* 取得此主題學習所需時間
|
||||
*
|
||||
* @return int 所需學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* ThemeManager.php
|
||||
*/
|
||||
@ -12,19 +12,19 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 主題管理類別
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Study
|
||||
*/
|
||||
*/
|
||||
class ThemeManager {
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的主題資訊清單
|
||||
*
|
||||
*
|
||||
* @return array 班級資訊清單陣列,格式為:
|
||||
*
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'theme_id' => <主題ID>,
|
||||
@ -35,13 +35,13 @@ class ThemeManager {
|
||||
* 'modify_time' => <主題資料修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getInfoList() {
|
||||
|
||||
|
||||
$db = new Database\DBTheme();
|
||||
$queryResult = $db->queryAllTheme();
|
||||
return $queryResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 區域專用類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表一塊區域
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try{
|
||||
* $target = new Target\Area(3);
|
||||
* echo $target->getId();
|
||||
@ -25,41 +25,41 @@ use UElearning\Exception;
|
||||
* echo $target->getNumber();
|
||||
* echo $target->getName();
|
||||
* echo $target->getMapUrl();
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\AreaNoFoundException $e) {
|
||||
* echo 'No Found area: '. $e->getId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
class Area {
|
||||
|
||||
|
||||
/**
|
||||
* 標的ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $aId;
|
||||
|
||||
protected $aId;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到此標的的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此標的查詢
|
||||
*
|
||||
* @throw UElearning\Exception\AreaNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
/**
|
||||
* 查詢到此標的的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此標的查詢
|
||||
*
|
||||
* @throw UElearning\Exception\AreaNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// 從資料庫查詢
|
||||
$db = new Database\DBTarget();
|
||||
$areaInfo = $db->queryArea($this->aId);
|
||||
@ -69,115 +69,115 @@ class Area {
|
||||
$this->queryResultArray = $areaInfo;
|
||||
}
|
||||
else throw new Exception\AreaNoFoundException($this->aId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
// 將新設定寫進資料庫裡
|
||||
//$db = new Database\DBTarget();
|
||||
//$db = new Database\DBTarget();
|
||||
//$db->changeTargetData($this->tId, $field, $value);
|
||||
//$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputAID 區域ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputAID 區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputAID){
|
||||
$this->aId = $inputAID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
*/
|
||||
public function __construct($inputAID){
|
||||
$this->aId = $inputAID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得區域ID
|
||||
*
|
||||
* @return int 區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->aId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得區域所在的廳ID
|
||||
*
|
||||
* @return int 區域所在的廳ID
|
||||
* 取得區域ID
|
||||
*
|
||||
* @return int 區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getHallId(){
|
||||
return $this->queryResultArray['hall_id'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->aId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域所在樓層
|
||||
*
|
||||
* @return int 區域所在樓層
|
||||
* 取得區域所在的廳ID
|
||||
*
|
||||
* @return int 區域所在的廳ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getFloor(){
|
||||
return $this->queryResultArray['floor'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getHallId(){
|
||||
return $this->queryResultArray['hall_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域地圖上的編號
|
||||
*
|
||||
* @return int 地圖上的區域編號
|
||||
* 取得區域所在樓層
|
||||
*
|
||||
* @return int 區域所在樓層
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getNumber(){
|
||||
return $this->queryResultArray['area_number'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域名稱
|
||||
*
|
||||
* @return string 區域名稱
|
||||
*/
|
||||
public function getFloor(){
|
||||
return $this->queryResultArray['floor'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域地圖上的編號
|
||||
*
|
||||
* @return int 地圖上的區域編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定區域名稱
|
||||
// *
|
||||
// * @param string $name 區域名稱
|
||||
*/
|
||||
public function getNumber(){
|
||||
return $this->queryResultArray['area_number'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域名稱
|
||||
*
|
||||
* @return string 區域名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定區域名稱
|
||||
// *
|
||||
// * @param string $name 區域名稱
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 取得區域的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* 取得區域的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域簡介
|
||||
*
|
||||
* @return string 區域簡介
|
||||
* 取得區域簡介
|
||||
*
|
||||
* @return string 區域簡介
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,27 +12,27 @@ namespace UElearning\Exception;
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
*/
|
||||
class TargetNoFoundException extends \UnexpectedValueException {
|
||||
/**
|
||||
* 指定的標的ID
|
||||
* @type int
|
||||
*/
|
||||
*/
|
||||
private $id;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param int $id 輸入的標的ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($id) {
|
||||
$this->id = $id;
|
||||
parent::__construct('No Target: '.$this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的標的ID
|
||||
* @return int 標的ID
|
||||
*/
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
@ -43,27 +43,27 @@ class TargetNoFoundException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
*/
|
||||
class AreaNoFoundException extends \UnexpectedValueException {
|
||||
/**
|
||||
* 指定的標的ID
|
||||
* @type int
|
||||
*/
|
||||
*/
|
||||
private $id;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param int $id 輸入的標的ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($id) {
|
||||
$this->id = $id;
|
||||
parent::__construct('No Target: '.$this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的標的ID
|
||||
* @return int 標的ID
|
||||
*/
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
@ -74,28 +74,28 @@ class AreaNoFoundException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
*/
|
||||
class HallNoFoundException extends \UnexpectedValueException {
|
||||
/**
|
||||
* 指定的標的ID
|
||||
* @type int
|
||||
*/
|
||||
*/
|
||||
private $id;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param int $id 輸入的標的ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($id) {
|
||||
$this->id = $id;
|
||||
parent::__construct('No Target: '.$this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的標的ID
|
||||
* @return int 標的ID
|
||||
*/
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,52 +12,52 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 廳專用類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表一塊廳
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
* try{
|
||||
* $target = new Target\Hall(1);
|
||||
* echo $target->getId();
|
||||
* echo $target->getName();
|
||||
* echo $target->getMapUrl();
|
||||
* echo $target->getIntroduction();
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\HallNoFoundException $e) {
|
||||
* echo 'No Found area: '. $e->getId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
class Hall {
|
||||
|
||||
|
||||
/**
|
||||
* 廳ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $hId;
|
||||
|
||||
protected $hId;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到此廳的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此廳查詢
|
||||
*
|
||||
* @throw UElearning\Exception\HallNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
/**
|
||||
* 查詢到此廳的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此廳查詢
|
||||
*
|
||||
* @throw UElearning\Exception\HallNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// 從資料庫查詢
|
||||
$db = new Database\DBTarget();
|
||||
$hallInfo = $db->queryHall($this->hId);
|
||||
@ -67,85 +67,85 @@ class Hall {
|
||||
$this->queryResultArray = $hallInfo;
|
||||
}
|
||||
else throw new Exception\HallNoFoundException($this->hId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
// 將新設定寫進資料庫裡
|
||||
//$db = new Database\DBTarget();
|
||||
//$db = new Database\DBTarget();
|
||||
//$db->changeTargetData($this->tId, $field, $value);
|
||||
//$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputAID 區域ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputAID 區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputHID){
|
||||
$this->hId = $inputHID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
*/
|
||||
public function __construct($inputHID){
|
||||
$this->hId = $inputHID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得廳ID
|
||||
*
|
||||
* @return int 廳ID
|
||||
|
||||
/**
|
||||
* 取得廳ID
|
||||
*
|
||||
* @return int 廳ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->hId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得廳名稱
|
||||
*
|
||||
* @return string 廳名稱
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->hId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得廳名稱
|
||||
*
|
||||
* @return string 廳名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定區域名稱
|
||||
// *
|
||||
// * @param string $name 區域名稱
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定區域名稱
|
||||
// *
|
||||
// * @param string $name 區域名稱
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 取得區域的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* 取得區域的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得區域簡介
|
||||
*
|
||||
* @return string 區域簡介
|
||||
* 取得區域簡介
|
||||
*
|
||||
* @return string 區域簡介
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function getIntroduction(){
|
||||
return $this->queryResultArray['introduction'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,16 +12,16 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 標的專用類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表一個標的
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||
* use UElearning\Target;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try{
|
||||
* $target = new Target\Target(3);
|
||||
* echo $target->getId();
|
||||
@ -37,41 +37,41 @@ use UElearning\Exception;
|
||||
* echo $target->getVacancyPeople();
|
||||
* echo $target->getS();
|
||||
* echo $target->getFj();
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\TargetNoFoundException $e) {
|
||||
* echo 'No Found target: '. $e->getId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Target
|
||||
*/
|
||||
class Target {
|
||||
|
||||
|
||||
/**
|
||||
* 標的ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $tId;
|
||||
|
||||
protected $tId;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到此標的的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此標的查詢
|
||||
*
|
||||
* @throw UElearning\Exception\TargetNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
/**
|
||||
* 查詢到此標的的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此標的查詢
|
||||
*
|
||||
* @throw UElearning\Exception\TargetNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// 從資料庫查詢此標的
|
||||
$db = new Database\DBTarget();
|
||||
$targetInfo = $db->queryTarget($this->tId);
|
||||
@ -81,250 +81,250 @@ class Target {
|
||||
$this->queryResultArray = $targetInfo;
|
||||
}
|
||||
else throw new Exception\TargetNoFoundException($this->tId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
// 將新設定寫進資料庫裡
|
||||
$db = new Database\DBTarget();
|
||||
$db->changeTargetData($this->tId, $field, $value);
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputTID 標的ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputTID){
|
||||
$this->tId = $inputTID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的ID
|
||||
*
|
||||
* @return int 標的ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->tId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得標的所在的區域ID
|
||||
*
|
||||
* @return int 標的所在的區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getAreaId(){
|
||||
return $this->queryResultArray['area_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得標的所在的廳ID
|
||||
*
|
||||
* @return int 標的所在的廳ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getHallId(){
|
||||
return $this->queryResultArray['hall_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得標的地圖上的編號
|
||||
*
|
||||
* @return int 地圖上的標的編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getNumber(){
|
||||
return $this->queryResultArray['target_number'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的名稱
|
||||
*
|
||||
* @return string 標的名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定標的名稱
|
||||
// *
|
||||
// * @param string $name 標的名稱
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預估的學習時間
|
||||
*
|
||||
* @return int 預估的學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的的人數限制
|
||||
*
|
||||
* @return int 學習標的的人數限制
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getPLj(){
|
||||
return $this->queryResultArray['PLj'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的的人數限制
|
||||
*
|
||||
* @return int 學習標的的人數限制
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaxPeople(){
|
||||
return $this->getPLj();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得學習標的目前人數
|
||||
*
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMj(){
|
||||
return $this->queryResultArray['Mj'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定學習標的目前人數
|
||||
*
|
||||
* @param int $number 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function setMj($number){
|
||||
$this->setUpdate('Mj', $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加學習標的目前人數
|
||||
*
|
||||
* 若要減少可直接在參數內帶入負值
|
||||
*
|
||||
* @param int $number 學習標的目前人數調整值
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function addMj($number){
|
||||
$setedNum = $this->queryResultArray['Mj']+$number;
|
||||
if($setedNum < 0) $setedNum = 0;
|
||||
$this->setUpdate('Mj', $setedNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的目前人數
|
||||
*
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCurrentPeople(){
|
||||
return $this->getMj();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加學習標的目前人數
|
||||
*
|
||||
* 若要減少可直接在參數內帶入負值
|
||||
*
|
||||
* @param int $number 學習標的目前人數調整值
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function addCurrentPeople($number){
|
||||
return $this->addMj($number);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定學習標的目前人數
|
||||
*
|
||||
* @param int $number 學習標的目前人數
|
||||
* 從資料庫更新此標的設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setCurrentPeople($number){
|
||||
$this->setMj($number);
|
||||
}
|
||||
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
// 將新設定寫進資料庫裡
|
||||
$db = new Database\DBTarget();
|
||||
$db->changeTargetData($this->tId, $field, $value);
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputTID 標的ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputTID){
|
||||
$this->tId = $inputTID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的ID
|
||||
*
|
||||
* @return int 標的ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->tId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得標的所在的區域ID
|
||||
*
|
||||
* @return int 標的所在的區域ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getAreaId(){
|
||||
return $this->queryResultArray['area_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得標的所在的廳ID
|
||||
*
|
||||
* @return int 標的所在的廳ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getHallId(){
|
||||
return $this->queryResultArray['hall_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得標的地圖上的編號
|
||||
*
|
||||
* @return int 地圖上的標的編號
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getNumber(){
|
||||
return $this->queryResultArray['target_number'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的名稱
|
||||
*
|
||||
* @return string 標的名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
///**
|
||||
// * 設定標的名稱
|
||||
// *
|
||||
// * @param string $name 標的名稱
|
||||
// * @since 2.0.0
|
||||
// */
|
||||
//public function setName($name){
|
||||
// $this->setUpdate('name', $name);
|
||||
//}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得標的的地圖圖片檔路徑
|
||||
*
|
||||
* @return string 地圖圖片檔路徑
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMapUrl(){
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得預估的學習時間
|
||||
*
|
||||
* @return int 預估的學習時間(分)
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnTime(){
|
||||
return $this->queryResultArray['learn_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的的人數限制
|
||||
*
|
||||
* @return int 學習標的的人數限制
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getPLj(){
|
||||
return $this->queryResultArray['PLj'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的的人數限制
|
||||
*
|
||||
* @return int 學習標的的人數限制
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaxPeople(){
|
||||
return $this->getPLj();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得學習標的目前人數
|
||||
*
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMj(){
|
||||
return $this->queryResultArray['Mj'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定學習標的目前人數
|
||||
*
|
||||
* @param int $number 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function setMj($number){
|
||||
$this->setUpdate('Mj', $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加學習標的目前人數
|
||||
*
|
||||
* 若要減少可直接在參數內帶入負值
|
||||
*
|
||||
* @param int $number 學習標的目前人數調整值
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function addMj($number){
|
||||
$setedNum = $this->queryResultArray['Mj']+$number;
|
||||
if($setedNum < 0) $setedNum = 0;
|
||||
$this->setUpdate('Mj', $setedNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的目前人數
|
||||
*
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCurrentPeople(){
|
||||
return $this->getMj();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加學習標的目前人數
|
||||
*
|
||||
* 若要減少可直接在參數內帶入負值
|
||||
*
|
||||
* @param int $number 學習標的目前人數調整值
|
||||
* @return int 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function addCurrentPeople($number){
|
||||
return $this->addMj($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定學習標的目前人數
|
||||
*
|
||||
* @param int $number 學習標的目前人數
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setCurrentPeople($number){
|
||||
$this->setMj($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得此標的還剩下人可容納
|
||||
*
|
||||
*
|
||||
* @return int 此標的還剩下人可容納
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getVacancyPeople() {
|
||||
return $this->getPLj() - $this->getMj();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 目前此標的人數是否已滿
|
||||
*
|
||||
* @return bool 目前人數已滿
|
||||
* 目前此標的人數是否已滿
|
||||
*
|
||||
* @return bool 目前人數已滿
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isFullPeople(){
|
||||
if($this->getFj() >= 1) return true;
|
||||
*/
|
||||
public function isFullPeople(){
|
||||
if($this->getFj() >= 1) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 取得學習標的飽和率上限
|
||||
*
|
||||
* @return int 學習標的飽和率上限
|
||||
* 取得學習標的飽和率上限
|
||||
*
|
||||
* @return int 學習標的飽和率上限
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getS(){
|
||||
return $this->queryResultArray['S'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getS(){
|
||||
return $this->queryResultArray['S'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得學習標的滿額指標
|
||||
*
|
||||
* @return int 學習標的滿額指標
|
||||
* 取得學習標的滿額指標
|
||||
*
|
||||
* @return int 學習標的滿額指標
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getFj(){
|
||||
return $this->queryResultArray['Fj'];
|
||||
}
|
||||
|
||||
*/
|
||||
public function getFj(){
|
||||
return $this->queryResultArray['Fj'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* ClassGroup.php
|
||||
*/
|
||||
@ -13,15 +13,15 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 班級群組類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一個班級
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/ClassGroup.php'
|
||||
* use UElearning\User;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $group = new User\ClassGroup(1);
|
||||
* echo $group->getName();
|
||||
@ -31,38 +31,38 @@ use UElearning\Exception;
|
||||
* catch (Exception\ClassNoFoundException $e) {
|
||||
* echo 'No Found class: '. $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
class ClassGroup {
|
||||
|
||||
|
||||
/**
|
||||
* 群組ID
|
||||
* @type int
|
||||
* @type int
|
||||
*/
|
||||
protected $cId;
|
||||
|
||||
protected $cId;
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此群組查詢
|
||||
*
|
||||
* @throw UElearning\Exception\ClassNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
* 從資料庫取得此群組查詢
|
||||
*
|
||||
* @throw UElearning\Exception\ClassNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
// 從資料庫查詢群組
|
||||
$db = new Database\DBUser();
|
||||
$groupInfo = $db->queryClassGroup($this->cId);
|
||||
@ -72,97 +72,97 @@ class ClassGroup {
|
||||
$this->queryResultArray = $groupInfo;
|
||||
}
|
||||
else throw new Exception\ClassNoFoundException($this->cId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此群組設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
|
||||
* 從資料庫更新此群組設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
|
||||
// 將新設定寫進資料庫裡
|
||||
$db = new Database\DBUser();
|
||||
$db = new Database\DBUser();
|
||||
$db->changeClassGroupData($this->cId, $field, $value);
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputCID 班級ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param int $inputCID 班級ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputCID){
|
||||
$this->cId = $inputCID;
|
||||
*/
|
||||
public function __construct($inputCID){
|
||||
$this->cId = $inputCID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組ID
|
||||
*
|
||||
* @return int 班級ID
|
||||
|
||||
/**
|
||||
* 取得群組ID
|
||||
*
|
||||
* @return int 班級ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getID(){
|
||||
return $this->cId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
*/
|
||||
public function getID(){
|
||||
return $this->cId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定群組顯示名稱
|
||||
*
|
||||
* @param string $name 群組名稱
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定群組顯示名稱
|
||||
*
|
||||
* @param string $name 群組名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setName($name){
|
||||
$this->setUpdate('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
*/
|
||||
public function setName($name){
|
||||
$this->setUpdate('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* ClassGroupAdmin.php
|
||||
*/
|
||||
@ -13,23 +13,23 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 管理班級群組的操作
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class ClassGroupAdmin {
|
||||
|
||||
|
||||
/**
|
||||
* 建立班級
|
||||
*
|
||||
*
|
||||
* 建立班級群組範例:
|
||||
*
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/ClassGroupAdmin.php';
|
||||
* use UElearning\User;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $groupAdmin = new User\ClassGroupAdmin();
|
||||
* $newId = null;
|
||||
@ -43,7 +43,7 @@ class ClassGroupAdmin {
|
||||
* catch (Exception\ClassIdExistException $e) {
|
||||
* echo 'Is exist class: ', $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param array $classGroupArray 班級群組資訊陣列,格式為:
|
||||
* array( 'class_id' => 12,
|
||||
* 'name' => '學生',
|
||||
@ -51,16 +51,16 @@ class ClassGroupAdmin {
|
||||
* @return int 剛剛新增進去的ID
|
||||
* @throw UElearning\Exception\ClassIdExistException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function create($classGroupArray) {
|
||||
|
||||
|
||||
// 檢查有無填寫
|
||||
if(isset($classGroupArray)) {
|
||||
|
||||
|
||||
// 若此id已存在
|
||||
if( isset($classGroupArray['class_id']) &&
|
||||
if( isset($classGroupArray['class_id']) &&
|
||||
$this->isExist($classGroupArray['class_id']) ) {
|
||||
|
||||
|
||||
throw new Exception\ClassIdExistException(
|
||||
$classGroupArray['class_id'] );
|
||||
}
|
||||
@ -70,7 +70,7 @@ class ClassGroupAdmin {
|
||||
if( !isset($classGroupArray['class_id']) ){
|
||||
$classGroupArray['class_id'] = null;
|
||||
}
|
||||
|
||||
|
||||
// 處理未帶入的資料
|
||||
if( !isset($classGroupArray['name']) ){
|
||||
$classGroupArray['name'] = null;
|
||||
@ -79,7 +79,7 @@ class ClassGroupAdmin {
|
||||
if( !isset($classGroupArray['memo']) ){
|
||||
$classGroupArray['memo'] = null;
|
||||
}
|
||||
|
||||
|
||||
// 新增一筆使用者資料進資料庫
|
||||
$db = new Database\DBUser();
|
||||
$id = $db->insertClassGroup(
|
||||
@ -88,55 +88,55 @@ class ClassGroupAdmin {
|
||||
'memo' => $classGroupArray['memo']
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// 回傳剛剛新增的ID
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else throw Exception\NoDataException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否已有相同名稱的班級ID
|
||||
*
|
||||
*
|
||||
* @param int $class_id 班級ID
|
||||
* @return bool 已有相同的班級ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function isExist($class_id) {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$info = $db->queryClassGroup($class_id);
|
||||
|
||||
|
||||
if( $info != null ) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除此班級
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $groupAdmin = new User\ClassGroupAdmin();
|
||||
* $groupAdmin->remove(2);
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\ClassNoFoundException $e) {
|
||||
* echo 'No Found class: ', $e->getGroupId();
|
||||
* echo 'No Found class: ', $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
* @param int $class_id 班級ID
|
||||
* @throw UElearning\Exception\ClassNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function remove($class_id) {
|
||||
|
||||
|
||||
// 若有此使用者
|
||||
if($this->isExist($class_id)) {
|
||||
|
||||
|
||||
// TODO: 檢查所有關聯的資料,確認是否可以移除
|
||||
|
||||
|
||||
// 移除資料庫中的使用者
|
||||
$db = new Database\DBUser();
|
||||
$db->deleteClassGroup($class_id);
|
||||
@ -145,40 +145,40 @@ class ClassGroupAdmin {
|
||||
else {
|
||||
throw new Exception\ClassNoFoundException($class_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級ID清單
|
||||
*
|
||||
*
|
||||
* @return array 班級ID清單
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getIDList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllClassGroup();
|
||||
|
||||
|
||||
if(isset($queryResult)) {
|
||||
|
||||
|
||||
$output = array();
|
||||
foreach($queryResult as $key => $value) {
|
||||
array_push($output, $value['class_id']);
|
||||
}
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級資訊清單
|
||||
*
|
||||
*
|
||||
* @return array 班級資訊清單陣列,格式為:
|
||||
*
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'class_id' => <班級ID>,
|
||||
@ -188,41 +188,41 @@ class ClassGroupAdmin {
|
||||
* 'modify_time' => <修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getInfoList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllClassGroup();
|
||||
return $queryResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級清單
|
||||
*
|
||||
*
|
||||
* @return array 班級物件
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getObjectList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllClassGroup();
|
||||
|
||||
|
||||
if(isset($queryResult)) {
|
||||
|
||||
|
||||
$output = array();
|
||||
foreach($queryResult as $key => $value) {
|
||||
$group = new ClassGroup($value['class_id']);
|
||||
array_push($output, $group);
|
||||
}
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,29 +10,29 @@ namespace UElearning\Exception;
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
abstract class UserException extends \UnexpectedValueException {
|
||||
|
||||
|
||||
/**
|
||||
* 指定的使用者名稱
|
||||
* @type string
|
||||
*/
|
||||
*/
|
||||
private $userId;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param string $userId 輸入的使用者名稱
|
||||
* @param string $description 描述
|
||||
*/
|
||||
*/
|
||||
public function __construct($userId, $description) {
|
||||
$this->userId = $userId;
|
||||
parent::__construct($description);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的資料庫系統名稱
|
||||
* @return string 錯誤訊息內容
|
||||
*/
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->userId;
|
||||
}
|
||||
@ -44,12 +44,12 @@ abstract class UserException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserNoFoundException extends UserException {
|
||||
/**
|
||||
* 沒有找到此帳號
|
||||
* @param string $userId 輸入的使用者名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct($userId) {
|
||||
parent::__construct($userId, 'User: "'.$userId.'" is no found.');
|
||||
}
|
||||
@ -60,12 +60,12 @@ class UserNoFoundException extends UserException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserPasswordErrException extends UserException {
|
||||
/**
|
||||
* 沒有找到此帳號
|
||||
* @param string $userId 輸入的使用者名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct($userId) {
|
||||
parent::__construct($userId, 'User: "'.$userId.'" password is wrong.');
|
||||
}
|
||||
@ -76,12 +76,12 @@ class UserPasswordErrException extends UserException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserNoActivatedException extends UserException {
|
||||
/**
|
||||
* 此帳號未啟用
|
||||
* @param string $userId 輸入的使用者名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct($userId) {
|
||||
parent::__construct($userId, 'User: "'.$userId.'" is no activated.');
|
||||
}
|
||||
@ -93,12 +93,12 @@ class UserNoActivatedException extends UserException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserIdExistException extends UserException {
|
||||
/**
|
||||
* 已有重複的使用者名稱
|
||||
* @param string $userId 輸入的使用者名稱
|
||||
*/
|
||||
*/
|
||||
public function __construct($userId) {
|
||||
parent::__construct($userId, 'UserId: "'.$userId.'" is exist.');
|
||||
}
|
||||
@ -111,29 +111,29 @@ class UserIdExistException extends UserException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
abstract class GroupException extends \UnexpectedValueException {
|
||||
|
||||
|
||||
/**
|
||||
* 指定的使用者群組ID
|
||||
* @type string
|
||||
*/
|
||||
*/
|
||||
private $groupId;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
* @param string $description 描述
|
||||
*/
|
||||
*/
|
||||
public function __construct($groupId, $description) {
|
||||
$this->groupId = $groupId;
|
||||
parent::__construct($description);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的資料庫系統名稱
|
||||
* @return string 錯誤訊息內容
|
||||
*/
|
||||
*/
|
||||
public function getGroupId() {
|
||||
return $this->groupId;
|
||||
}
|
||||
@ -144,12 +144,12 @@ abstract class GroupException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class GroupIdExistException extends GroupException {
|
||||
/**
|
||||
* 已有重複的使用者名稱
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($groupId) {
|
||||
parent::__construct($groupId, 'GroupId: "'.$groupId.'" is exist.');
|
||||
}
|
||||
@ -160,12 +160,12 @@ class GroupIdExistException extends GroupException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class GroupNoFoundException extends GroupException {
|
||||
/**
|
||||
* 沒有找到此帳號
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($groupId) {
|
||||
parent::__construct($groupId, 'Group: "'.$groupId.'" is no found.');
|
||||
}
|
||||
@ -178,12 +178,12 @@ class GroupNoFoundException extends GroupException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class ClassIdExistException extends GroupException {
|
||||
/**
|
||||
* 已有重複的使用者名稱
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($groupId) {
|
||||
parent::__construct($groupId, 'ClassId: "'.$groupId.'" is exist.');
|
||||
}
|
||||
@ -194,12 +194,12 @@ class ClassIdExistException extends GroupException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class ClassNoFoundException extends GroupException {
|
||||
/**
|
||||
* 沒有找到此帳號
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
*/
|
||||
*/
|
||||
public function __construct($groupId) {
|
||||
parent::__construct($groupId, 'Class Group: "'.$groupId.'" is no found.');
|
||||
}
|
||||
@ -212,33 +212,33 @@ class ClassNoFoundException extends GroupException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class PermissionNoFoundException extends \UnexpectedValueException {
|
||||
|
||||
|
||||
/**
|
||||
* 指定的使用者群組ID
|
||||
* @type string
|
||||
*/
|
||||
*/
|
||||
private $permissionName;
|
||||
|
||||
|
||||
/**
|
||||
* 使用者帳號例外
|
||||
* @param string $groupId 輸入的使用者群組ID
|
||||
* @param string $description 描述
|
||||
*/
|
||||
*/
|
||||
public function __construct($permissionName) {
|
||||
$this->permissionName = $permissionName;
|
||||
parent::__construct('No Found Permission: '.$this->permissionName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得輸入的資料庫系統名稱
|
||||
* @return string 錯誤訊息內容
|
||||
*/
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->permissionName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@ -248,19 +248,19 @@ class PermissionNoFoundException extends \UnexpectedValueException {
|
||||
* @since 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class LoginTokenNoFoundException extends \UnexpectedValueException {
|
||||
|
||||
/**
|
||||
* 登入階段Token
|
||||
* @type string
|
||||
*/
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* 找不到此登入階段例外
|
||||
* @param string $token 登入階段Token
|
||||
*/
|
||||
*/
|
||||
public function __construct($token) {
|
||||
$this->token = $token;
|
||||
parent::__construct('No Found Login Token: '.$this->token);
|
||||
@ -269,8 +269,8 @@ class LoginTokenNoFoundException extends \UnexpectedValueException {
|
||||
/**
|
||||
* 取得輸入的登入階段Token
|
||||
* @return string 登入階段Token
|
||||
*/
|
||||
*/
|
||||
public function getToken() {
|
||||
return $this->token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,57 +18,57 @@ use UElearning\Util;
|
||||
|
||||
/**
|
||||
* 使用者處理專用類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一位使用者
|
||||
*
|
||||
* 建立此物件範例:
|
||||
*
|
||||
*
|
||||
* 建立此物件範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/User.php';
|
||||
* use UElearning\User;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $user = new User\User('yuan');
|
||||
*
|
||||
*
|
||||
* $user->changePassword('123456');
|
||||
* echo $user->isPasswordCorrect('123456');
|
||||
*
|
||||
*
|
||||
* echo 'NickName: '.$user->getNickName();
|
||||
* }
|
||||
* catch (Exception\UserNoFoundException $e) {
|
||||
* echo 'No Found user: '. $e->getUserId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
class User {
|
||||
|
||||
|
||||
/**
|
||||
* 使用者ID
|
||||
* @type string
|
||||
* @type string
|
||||
*/
|
||||
protected $uId;
|
||||
|
||||
protected $uId;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此帳號查詢
|
||||
*
|
||||
* @throw UElearning\Exception\UserNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
/**
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此帳號查詢
|
||||
*
|
||||
* @throw UElearning\Exception\UserNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
// 從資料庫查詢使用者
|
||||
$db = new Database\DBUser();
|
||||
$userInfo = $db->queryUser($this->uId);
|
||||
@ -78,137 +78,137 @@ class User {
|
||||
$this->queryResultArray = $userInfo;
|
||||
}
|
||||
else throw new Exception\UserNoFoundException($this->uId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此帳號設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
* 從資料庫更新此帳號設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
/// 將新設定寫進資料庫裡
|
||||
$db = new Database\DBUser();
|
||||
$db = new Database\DBUser();
|
||||
$db->changeUserData($this->uId, $field, $value);
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param string $inputUID 使用者ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputUID){
|
||||
$this->uId = $inputUID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得帳號名稱
|
||||
*
|
||||
* @return string 帳號名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->uId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得帳號名稱
|
||||
*
|
||||
* @return string 帳號名稱
|
||||
* 建構子
|
||||
*
|
||||
* @param string $inputUID 使用者ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUsername(){
|
||||
return $this->uId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 驗證密碼是否錯誤
|
||||
*
|
||||
* @param string $inputPasswd 密碼
|
||||
* @return bool true:密碼正確,false:密碼錯誤
|
||||
*/
|
||||
public function __construct($inputUID){
|
||||
$this->uId = $inputUID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得帳號名稱
|
||||
*
|
||||
* @return string 帳號名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isPasswordCorrect($inputPasswd){
|
||||
$passUtil = new Util\Password();
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->uId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號名稱
|
||||
*
|
||||
* @return string 帳號名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getUsername(){
|
||||
return $this->uId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 驗證密碼是否錯誤
|
||||
*
|
||||
* @param string $inputPasswd 密碼
|
||||
* @return bool true:密碼正確,false:密碼錯誤
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isPasswordCorrect($inputPasswd){
|
||||
$passUtil = new Util\Password();
|
||||
$this_passwd = $this->queryResultArray['password'];
|
||||
return $passUtil->checkSame($this_passwd, $inputPasswd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改密碼
|
||||
*
|
||||
* @param string $newPasswd 新密碼
|
||||
* @param string $newPasswdMode 新密碼加密方式(可省略)
|
||||
* @return string 狀態回傳
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改密碼
|
||||
*
|
||||
* @param string $newPasswd 新密碼
|
||||
* @param string $newPasswdMode 新密碼加密方式(可省略)
|
||||
* @return string 狀態回傳
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function changePassword($newPasswd){
|
||||
*/
|
||||
public function changePassword($newPasswd){
|
||||
// 進行密碼加密
|
||||
$passUtil = new Util\Password();
|
||||
$passwdEncrypted = $passUtil->encrypt($newPasswd);
|
||||
|
||||
|
||||
// 將新密碼寫進資料庫裡
|
||||
$this->setUpdate('password', $passwdEncrypted);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
$this->setUpdate('password', $passwdEncrypted);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號資訊修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得所在群組
|
||||
*
|
||||
* @return string 群組ID
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號資訊修改時間
|
||||
*
|
||||
* @return string 修改時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getGroupID(){
|
||||
return $this->queryResultArray['group_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得所在群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
*/
|
||||
public function getModifyTime(){
|
||||
return $this->queryResultArray['modify_time'];
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得所在群組
|
||||
*
|
||||
* @return string 群組ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getGroupID(){
|
||||
return $this->queryResultArray['group_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得所在群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
* @throw UElearning\Exception\GroupNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getGroupName(){
|
||||
|
||||
*/
|
||||
public function getGroupName(){
|
||||
|
||||
return $this->queryResultArray['group_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定所在群組
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定所在群組
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $user = new User\User('yuan');
|
||||
* try {
|
||||
@ -223,13 +223,13 @@ class User {
|
||||
* echo 'No Found user: '. $e->getUserId();
|
||||
* }
|
||||
*
|
||||
* @param string $toGroup 群組ID
|
||||
* @param string $toGroup 群組ID
|
||||
* @throw UElearning\Exception\GroupNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setGroup($toGroup){
|
||||
|
||||
// 檢查有此群組
|
||||
*/
|
||||
public function setGroup($toGroup){
|
||||
|
||||
// 檢查有此群組
|
||||
$groupAdmin = new UserGroupAdmin();
|
||||
if($groupAdmin->isExist($toGroup)) {
|
||||
$this->setUpdate('group_id', $toGroup);
|
||||
@ -237,39 +237,39 @@ class User {
|
||||
else {
|
||||
throw new Exception\GroupNoFoundException($toGroup);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得所在班級
|
||||
*
|
||||
* @return string 班級ID
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得所在班級
|
||||
*
|
||||
* @return string 班級ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getClass(){
|
||||
return $this->queryResultArray['class_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得所在班級名稱
|
||||
*
|
||||
* @return string 班級名稱
|
||||
*/
|
||||
public function getClass(){
|
||||
return $this->queryResultArray['class_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得所在班級名稱
|
||||
*
|
||||
* @return string 班級名稱
|
||||
* @throw UElearning\Exception\ClassNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getClassName(){
|
||||
return $this->queryResultArray['class_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定所在班級
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*/
|
||||
public function getClassName(){
|
||||
return $this->queryResultArray['class_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定所在班級
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $user = new User\User('yuan');
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $user->setClass(1);
|
||||
* }
|
||||
@ -280,16 +280,16 @@ class User {
|
||||
* catch (Exception\UserNoFoundException $e) {
|
||||
* echo 'No Found user: '. $e->getUserId();
|
||||
* }
|
||||
*
|
||||
* @param string $toClass 班級ID
|
||||
*
|
||||
* @param string $toClass 班級ID
|
||||
* @throw UElearning\Exception\ClassNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setClass($toClass){
|
||||
|
||||
// 檢查有此群組
|
||||
*/
|
||||
public function setClass($toClass){
|
||||
|
||||
// 檢查有此群組
|
||||
if(isset($toClass)) {
|
||||
|
||||
|
||||
$classGroupAdmin = new ClassGroupAdmin();
|
||||
if($classGroupAdmin->isExist($toClass)) {
|
||||
$this->setUpdate('class_id', $toClass);
|
||||
@ -301,255 +301,255 @@ class User {
|
||||
else {
|
||||
$this->setUpdate('class_id', null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號啟用狀態
|
||||
*
|
||||
* @return bool 是否已啟用
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function isEnable(){
|
||||
return $this->queryResultArray['enable'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定帳號啟用狀態
|
||||
*
|
||||
* @param bool $isActive 是否為啟用
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setEnable($isActive){
|
||||
// TODO: 防呆,至少一個帳號是啟用的
|
||||
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('enable', $isActive);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 取得這個人的學習導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* 取得帳號啟用狀態
|
||||
*
|
||||
* @return bool 是否已啟用
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這個人的學習導引風格
|
||||
*
|
||||
* @param int $style 將推薦幾個學習點
|
||||
*/
|
||||
public function isEnable(){
|
||||
return $this->queryResultArray['enable'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定帳號啟用狀態
|
||||
*
|
||||
* @param bool $isActive 是否為啟用
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setLearnStyle($style){
|
||||
|
||||
*/
|
||||
public function setEnable($isActive){
|
||||
// TODO: 防呆,至少一個帳號是啟用的
|
||||
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('enable', $isActive);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得這個人的學習導引風格
|
||||
*
|
||||
* @return int 將推薦幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLearnStyle(){
|
||||
return $this->queryResultArray['learnStyle_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這個人的學習導引風格
|
||||
*
|
||||
* @param int $style 將推薦幾個學習點
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setLearnStyle($style){
|
||||
|
||||
if( $style >= 0 ) {
|
||||
$this->setUpdate('learnStyle_mode', $style);
|
||||
}
|
||||
else {
|
||||
else {
|
||||
throw new \UnexpectedValueException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得這個人的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* 取得這個人的教材風格
|
||||
*
|
||||
* @return string 教材風格
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaterialStyle(){
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這個人的教材風格
|
||||
*
|
||||
* @param string $style 教材風格
|
||||
*/
|
||||
public function getMaterialStyle(){
|
||||
return $this->queryResultArray['material_mode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定這個人的教材風格
|
||||
*
|
||||
* @param string $style 教材風格
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMaterialStyle($style){
|
||||
|
||||
// TODO: 防呆- 無此教材
|
||||
$this->setUpdate('material_mode', $style);
|
||||
}
|
||||
|
||||
*/
|
||||
public function setMaterialStyle($style){
|
||||
|
||||
// TODO: 防呆- 無此教材
|
||||
$this->setUpdate('material_mode', $style);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 取得名稱
|
||||
*
|
||||
* @return string 依照有填入多少名字 <br />優先順序: 暱稱→真實名字→帳號名稱
|
||||
* 取得名稱
|
||||
*
|
||||
* @return string 依照有填入多少名字 <br />優先順序: 暱稱→真實名字→帳號名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
*/
|
||||
public function getName(){
|
||||
// TODO: 待修正-取得名稱
|
||||
if($this->getNickName() != "") {
|
||||
return $this->getNickName();
|
||||
}
|
||||
else if($this->getRealName() != "") {
|
||||
return $this->getRealName();
|
||||
}
|
||||
else {
|
||||
return $this->getUsername();
|
||||
}
|
||||
}
|
||||
|
||||
if($this->getNickName() != "") {
|
||||
return $this->getNickName();
|
||||
}
|
||||
else if($this->getRealName() != "") {
|
||||
return $this->getRealName();
|
||||
}
|
||||
else {
|
||||
return $this->getUsername();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* 取得暱稱
|
||||
*
|
||||
* @return string 暱稱
|
||||
* 取得暱稱
|
||||
*
|
||||
* @return string 暱稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getNickName(){
|
||||
return $this->queryResultArray['nickname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改暱稱
|
||||
*
|
||||
* @param string $input 新暱稱
|
||||
*/
|
||||
public function getNickName(){
|
||||
return $this->queryResultArray['nickname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改暱稱
|
||||
*
|
||||
* @param string $input 新暱稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setNickName($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('nickname', $input);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得真實姓名
|
||||
*
|
||||
* @return string 真實姓名
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getRealName(){
|
||||
return $this->queryResultArray['realname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改真實姓名
|
||||
*
|
||||
* @param string $input 新真實姓名
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setRealName($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('realname', $input);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號Email
|
||||
*
|
||||
* @return string 使用者資訊的Email
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getEmail(){
|
||||
return $this->queryResultArray['email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號Email
|
||||
*
|
||||
* @param string $input 新Email
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setEmail($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('email', $input);
|
||||
}
|
||||
|
||||
*/
|
||||
public function setNickName($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('nickname', $input);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
|
||||
/**
|
||||
* 取得真實姓名
|
||||
*
|
||||
* @return string 真實姓名
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
*/
|
||||
public function getRealName(){
|
||||
return $this->queryResultArray['realname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改真實姓名
|
||||
*
|
||||
* @param string $input 新真實姓名
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得權限清單
|
||||
*
|
||||
* @return array 權限清單
|
||||
*/
|
||||
public function setRealName($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('realname', $input);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號Email
|
||||
*
|
||||
* @return string 使用者資訊的Email
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getEmail(){
|
||||
return $this->queryResultArray['email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號Email
|
||||
*
|
||||
* @param string $input 新Email
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setEmail($input){
|
||||
// 將新設定寫進資料庫裡
|
||||
$this->setUpdate('email', $input);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得權限清單
|
||||
*
|
||||
* @return array 權限清單
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getPermissionList() {
|
||||
$thisGroup = new UserGroup($this->getQueryInfo("GID"));
|
||||
return $thisGroup->getPermissionList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* @return bool 是否擁有
|
||||
*/
|
||||
public function getPermissionList() {
|
||||
$thisGroup = new UserGroup($this->getQueryInfo("GID"));
|
||||
return $thisGroup->getPermissionList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* @return bool 是否擁有
|
||||
* @throw UElearning\User\Exception\PermissionNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function havePermission($permissionName) {
|
||||
$thisGroup = new UserGroup($this->getQueryInfo("GID"));
|
||||
*/
|
||||
public function havePermission($permissionName) {
|
||||
$thisGroup = new UserGroup($this->getQueryInfo("GID"));
|
||||
return $thisGroup->havePermission($permissionName);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得登入次數
|
||||
*
|
||||
* @return int 登入了多少次
|
||||
* 取得登入次數
|
||||
*
|
||||
* @return int 登入了多少次
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getLoginTimes() {
|
||||
*/
|
||||
public function getLoginTimes() {
|
||||
// TODO: 取得登入次數
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 目前有幾個裝置登入
|
||||
*
|
||||
* @return int 幾個已登入的登入階段
|
||||
* 目前有幾個裝置登入
|
||||
*
|
||||
* @return int 幾個已登入的登入階段
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCurrentLoginTotal() {
|
||||
*/
|
||||
public function getCurrentLoginTotal() {
|
||||
// TODO: 取得登入次數
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 目前有哪些活動可以進行學習
|
||||
*
|
||||
* @return array 可以學習的活動清單
|
||||
* 目前有哪些活動可以進行學習
|
||||
*
|
||||
* @return array 可以學習的活動清單
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getStudyActivity() {
|
||||
*/
|
||||
public function getStudyActivity() {
|
||||
// TODO: 可以學習的活動清單
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* UserAdmin.php
|
||||
*/
|
||||
@ -15,24 +15,24 @@ use UElearning\Util;
|
||||
|
||||
/**
|
||||
* 管理使用者的操作
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserAdmin {
|
||||
|
||||
|
||||
/**
|
||||
* 建立使用者
|
||||
*
|
||||
*
|
||||
* 建立使用者範例:
|
||||
*
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
|
||||
* use UElearning\User;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $userAdmin = new User\UserAdmin();
|
||||
* $userAdmin->create(
|
||||
@ -43,13 +43,13 @@ class UserAdmin {
|
||||
* 'nickname' => '艾瑞克',
|
||||
* 'email' => 'eric@example.com' )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* }
|
||||
* // 若已有重複帳號名稱
|
||||
* catch (Exception\UserIdExistException $e) {
|
||||
* echo 'Is exist user: ', $e->getUserId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param array $userInfoArray 使用者資訊陣列,格式為:
|
||||
* array( 'user_id' => 'root',
|
||||
* 'password' => 'pass123',
|
||||
@ -67,12 +67,12 @@ class UserAdmin {
|
||||
* 'memo' => '' ) // (optional)
|
||||
* @throw UElearning\Exception\UserIdExistException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function create($userInfoArray) {
|
||||
|
||||
|
||||
// 檢查必填項目有無填寫
|
||||
if(isset($userInfoArray)) {
|
||||
|
||||
|
||||
// 若無填寫
|
||||
if( !isset($userInfoArray['user_id']) ||
|
||||
!isset($userInfoArray['password']) ||
|
||||
@ -86,7 +86,7 @@ class UserAdmin {
|
||||
}
|
||||
// 沒有問題
|
||||
else {
|
||||
|
||||
|
||||
// 處理未帶入的資料
|
||||
if( !isset($userInfoArray['class_id']) ){
|
||||
$userInfoArray['class_id'] = null;
|
||||
@ -115,11 +115,11 @@ class UserAdmin {
|
||||
if( !isset($userInfoArray['memo']) ){
|
||||
$userInfoArray['memo'] = null;
|
||||
}
|
||||
|
||||
|
||||
// 進行密碼加密
|
||||
$passUtil = new Util\Password();
|
||||
$passwdEncrypted = $passUtil->encrypt( $userInfoArray['password'] );
|
||||
|
||||
|
||||
// 新增一筆使用者資料進資料庫
|
||||
$db = new Database\DBUser();
|
||||
$db->insertUser(
|
||||
@ -129,7 +129,7 @@ class UserAdmin {
|
||||
'group_id' => $userInfoArray['group_id'],
|
||||
'class_id' => $userInfoArray['class_id'],
|
||||
'enable' => $userInfoArray['enable'],
|
||||
'learnStyle_mode' => $userInfoArray['learnStyle_mode'],
|
||||
'learnStyle_mode' => $userInfoArray['learnStyle_mode'],
|
||||
'material_mode' => $userInfoArray['material_mode'],
|
||||
'enable_noAppoint' => $userInfoArray['enable_noAppoint'],
|
||||
'nickname' => $userInfoArray['nickname'],
|
||||
@ -138,52 +138,52 @@ class UserAdmin {
|
||||
'memo' => $userInfoArray['memo']
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else throw Exception\NoDataException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否已有相同名稱的帳號名稱
|
||||
*
|
||||
*
|
||||
* @param string $userName 帳號名稱
|
||||
* @return bool 已有相同的帳號名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function isExist($userName) {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$info = $db->queryUser($userName);
|
||||
|
||||
|
||||
if( $info != null ) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除此使用者
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $userAdmin = new User\UserAdmin();
|
||||
* $userAdmin->remove('eric');
|
||||
* }
|
||||
* catch (Exception\UserNoFoundException $e) {
|
||||
* echo 'No Found user: ', $e->getUserId();
|
||||
* echo 'No Found user: ', $e->getUserId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param string $userName 帳號名稱
|
||||
* @throw UElearning\Exception\UserNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function remove($userName) {
|
||||
|
||||
|
||||
// 若有此使用者
|
||||
if($this->isExist($userName)) {
|
||||
|
||||
|
||||
// TODO: 檢查所有關聯的資料,確認是否可以移除
|
||||
|
||||
|
||||
// 移除資料庫中的使用者
|
||||
$db = new Database\DBUser();
|
||||
$db->deleteUser($userName);
|
||||
@ -194,4 +194,4 @@ class UserAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* UserGroup.php
|
||||
*/
|
||||
@ -13,16 +13,16 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 使用者群組類別
|
||||
*
|
||||
*
|
||||
* 一個物件即代表這一個使用者群組
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/UserGroup.php'
|
||||
* use UElearning\User;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $group = new User\UserGroup('testG');
|
||||
* echo $group->getName();
|
||||
@ -32,38 +32,38 @@ use UElearning\Exception;
|
||||
* catch (Exception\GroupNoFoundException $e) {
|
||||
* echo 'No Found group: '. $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
class UserGroup {
|
||||
|
||||
|
||||
/**
|
||||
* 群組ID
|
||||
* @type string
|
||||
* @type string
|
||||
*/
|
||||
protected $gId;
|
||||
|
||||
protected $gId;
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
* 查詢到此帳號的所有資訊的結果
|
||||
*
|
||||
* 由 $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $queryResultArray;
|
||||
|
||||
/**
|
||||
* 從資料庫取得此群組查詢
|
||||
*
|
||||
* @throw UElearning\Exception\GroupNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
* 從資料庫取得此群組查詢
|
||||
*
|
||||
* @throw UElearning\Exception\GroupNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function getQuery(){
|
||||
|
||||
// 從資料庫查詢群組
|
||||
$db = new Database\DBUser();
|
||||
$groupInfo = $db->queryGroup($this->gId);
|
||||
@ -73,156 +73,156 @@ class UserGroup {
|
||||
$this->queryResultArray = $groupInfo;
|
||||
}
|
||||
else throw new Exception\GroupNoFoundException($this->gId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 從資料庫更新此群組設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
|
||||
* 從資料庫更新此群組設定
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
protected function setUpdate($field, $value){
|
||||
|
||||
/// 將新設定寫進資料庫裡
|
||||
$db = new Database\DBUser();
|
||||
$db = new Database\DBUser();
|
||||
$db->changeGroupData($this->gId, $field, $value);
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param string $inputGID 群組ID
|
||||
|
||||
/**
|
||||
* 建構子
|
||||
*
|
||||
* @param string $inputGID 群組ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($inputGID){
|
||||
$this->gId = $inputGID;
|
||||
*/
|
||||
public function __construct($inputGID){
|
||||
$this->gId = $inputGID;
|
||||
$this->getQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組ID
|
||||
*
|
||||
* @return string 群組ID
|
||||
|
||||
/**
|
||||
* 取得群組ID
|
||||
*
|
||||
* @return string 群組ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getID(){
|
||||
return $this->gId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
*/
|
||||
public function getID(){
|
||||
return $this->gId;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 取得帳號建立時間
|
||||
*
|
||||
* @return string 建立時間
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
*/
|
||||
public function getCreateTime(){
|
||||
return $this->queryResultArray['build_time'];
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得群組顯示名稱
|
||||
*
|
||||
* @return string 群組名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定群組顯示名稱
|
||||
*
|
||||
* @param string $name 群組名稱
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->queryResultArray['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定群組顯示名稱
|
||||
*
|
||||
* @param string $name 群組名稱
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setName($name){
|
||||
$this->setUpdate('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
*/
|
||||
public function setName($name){
|
||||
$this->setUpdate('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得帳號備註資訊
|
||||
*
|
||||
* @return string 使用者帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
*/
|
||||
public function getMemo(){
|
||||
return $this->queryResultArray['memo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改帳號備註資訊
|
||||
*
|
||||
* @param string $input 新的帳號備註資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得權限清單
|
||||
*
|
||||
* @return array 權限清單
|
||||
*/
|
||||
public function getPermissionList() {
|
||||
// TODO: 取得權限清單
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* @return bool 是否擁有
|
||||
*/
|
||||
public function setMemo($input){
|
||||
$this->setUpdate('memo', $input);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得權限清單
|
||||
*
|
||||
* @return array 權限清單
|
||||
*/
|
||||
public function getPermissionList() {
|
||||
// TODO: 取得權限清單
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* @return bool 是否擁有
|
||||
* @throw UElearning\Exception\PermissionNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function havePermission($permissionName) {
|
||||
switch($permissionName) {
|
||||
*/
|
||||
public function havePermission($permissionName) {
|
||||
switch($permissionName) {
|
||||
case 'server_admin':
|
||||
case 'serverAdmin':
|
||||
case 'ServerAdmin':
|
||||
return $this->queryResultArray['auth_admin'];
|
||||
break;
|
||||
|
||||
|
||||
case 'client_admin':
|
||||
case 'clientAdmin':
|
||||
case 'ClientAdmin':
|
||||
return $this->queryResultArray['auth_clientAdmin'];
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw new Exception\PermissionNoFoundException('$permissionName');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* 設定擁有此權限
|
||||
*
|
||||
* @param string $permissionName 權限名稱
|
||||
* @param string $setBool 是否給予
|
||||
* @return bool 是否擁有
|
||||
* @return bool 是否擁有
|
||||
* @throw UElearning\Exception\PermissionNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function setPermission($permissionName, $setBool) {
|
||||
switch($permissionName) {
|
||||
*/
|
||||
public function setPermission($permissionName, $setBool) {
|
||||
switch($permissionName) {
|
||||
case 'server_admin':
|
||||
case 'serverAdmin':
|
||||
case 'ServerAdmin':
|
||||
$this->setUpdate('auth_admin', $setBool);
|
||||
break;
|
||||
|
||||
|
||||
case 'client_admin':
|
||||
case 'clientAdmin':
|
||||
case 'ClientAdmin':
|
||||
@ -231,6 +231,6 @@ class UserGroup {
|
||||
default:
|
||||
throw new Exception\PermissionNoFoundException('$permissionName');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* UserGroupAdmin.php
|
||||
*/
|
||||
@ -14,19 +14,19 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 管理使用者權限群組的操作
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserGroupAdmin {
|
||||
|
||||
|
||||
/**
|
||||
* 建立群組
|
||||
*
|
||||
*
|
||||
* 建立使用者群組範例:
|
||||
*
|
||||
*
|
||||
* // 建立班級
|
||||
* try {
|
||||
* $classAdmin = new User\ClassGroupAdmin();
|
||||
@ -40,7 +40,7 @@ class UserGroupAdmin {
|
||||
* catch (Exception\ClassIdExistException $e) {
|
||||
* echo 'Is exist class: ', $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param array $groupArray 使用者群組資訊陣列,格式為:
|
||||
* array( 'group_id' => 'student',
|
||||
* 'name' => '學生',
|
||||
@ -49,12 +49,12 @@ class UserGroupAdmin {
|
||||
* 'auth_client_admin' => false ) // (optional) 預設為false
|
||||
* @throw UElearning\Exception\GroupIdExistException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function create($groupArray) {
|
||||
|
||||
|
||||
// 檢查有無填寫
|
||||
if(isset($groupArray)) {
|
||||
|
||||
|
||||
// 若必填項目無填寫
|
||||
if( !isset($groupArray['group_id']) ) {
|
||||
throw new Exception\NoDataException();
|
||||
@ -66,7 +66,7 @@ class UserGroupAdmin {
|
||||
}
|
||||
// 沒有問題
|
||||
else {
|
||||
|
||||
|
||||
// 處理未帶入的資料
|
||||
if( !isset($groupArray['name']) ){
|
||||
$groupArray['name'] = null;
|
||||
@ -81,7 +81,7 @@ class UserGroupAdmin {
|
||||
if( !isset($groupArray['auth_client_admin']) ){
|
||||
$groupArray['auth_client_admin'] = false;
|
||||
}
|
||||
|
||||
|
||||
// 新增一筆使用者資料進資料庫
|
||||
$db = new Database\DBUser();
|
||||
$db->insertGroup(
|
||||
@ -96,48 +96,48 @@ class UserGroupAdmin {
|
||||
}
|
||||
else throw Exception\NoDataException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否已有相同名稱的帳號名稱
|
||||
*
|
||||
*
|
||||
* @param string $group_id 群組ID
|
||||
* @return bool 已有相同的群組ID
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function isExist($group_id) {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$info = $db->queryGroup($group_id);
|
||||
|
||||
|
||||
if( $info != null ) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除此群組
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $groupAdmin = new User\UserGroupAdmin();
|
||||
* $groupAdmin->remove('test_student');
|
||||
*
|
||||
*
|
||||
* }
|
||||
* catch (Exception\GroupNoFoundException $e) {
|
||||
* echo 'No Found group: ', $e->getGroupId();
|
||||
* echo 'No Found group: ', $e->getGroupId();
|
||||
* }
|
||||
*
|
||||
* @param string $group_id 群組ID
|
||||
* @throw UElearning\Exception\GroupNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function remove($group_id) {
|
||||
|
||||
|
||||
// 若有此使用者
|
||||
if($this->isExist($group_id)) {
|
||||
|
||||
|
||||
// TODO: 檢查所有關聯的資料,確認是否可以移除
|
||||
|
||||
|
||||
// 移除資料庫中的使用者
|
||||
$db = new Database\DBUser();
|
||||
$db->deleteGroup($group_id);
|
||||
@ -146,40 +146,40 @@ class UserGroupAdmin {
|
||||
else {
|
||||
throw new Exception\GroupNoFoundException($group_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級ID清單
|
||||
*
|
||||
*
|
||||
* @return array 班級ID清單
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getIDList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllGroup();
|
||||
|
||||
|
||||
if(isset($queryResult)) {
|
||||
|
||||
|
||||
$output = array();
|
||||
foreach($queryResult as $key => $value) {
|
||||
array_push($output, $value['group_id']);
|
||||
}
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級資訊清單
|
||||
*
|
||||
*
|
||||
* @return array 班級資訊清單陣列,格式為:
|
||||
*
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'class_id' => <班級ID>,
|
||||
@ -189,41 +189,41 @@ class UserGroupAdmin {
|
||||
* 'modify_time' => <修改時間>
|
||||
* )
|
||||
* );
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getInfoList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllGroup();
|
||||
return $queryResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有的班級清單
|
||||
*
|
||||
*
|
||||
* @return array 班級物件
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getObjectList() {
|
||||
|
||||
|
||||
$db = new Database\DBUser();
|
||||
$queryResult = $db->queryAllGroup();
|
||||
|
||||
|
||||
if(isset($queryResult)) {
|
||||
|
||||
|
||||
$output = array();
|
||||
foreach($queryResult as $key => $value) {
|
||||
$group = new UserGroup($value['group_id']);
|
||||
array_push($output, $group);
|
||||
}
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* UserSession.php
|
||||
*/
|
||||
@ -15,24 +15,24 @@ use UElearning\Exception;
|
||||
|
||||
/**
|
||||
* 使用者登入階段管理
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage User
|
||||
*/
|
||||
*/
|
||||
class UserSession {
|
||||
|
||||
|
||||
/**
|
||||
* 使用者登入
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/User/UserSession.php';
|
||||
* use UElearning\User;
|
||||
* use UElearning\Exception;
|
||||
*
|
||||
*
|
||||
* try {
|
||||
* $session = new User\UserSession();
|
||||
* $loginToken = $session->login('yuan', 'password', 'browser');
|
||||
@ -47,7 +47,7 @@ class UserSession {
|
||||
* catch (Exception\UserNoActivatedException $e) {
|
||||
* echo 'User No Activiated: '. $e->getUserId();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param string $userId 帳號名稱
|
||||
* @param string $password 密碼
|
||||
* @param string $agent 用什麼裝置登入
|
||||
@ -56,9 +56,9 @@ class UserSession {
|
||||
* @throw UElearning\Exception\UserPasswordErrException
|
||||
* @throw UElearning\Exception\UserNoActivatedException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function login($userId, $password, $agent) {
|
||||
|
||||
|
||||
try {
|
||||
$user = new User($userId);
|
||||
|
||||
@ -72,10 +72,10 @@ class UserSession {
|
||||
}
|
||||
// 沒問題,登入此帳號
|
||||
else {
|
||||
|
||||
|
||||
// 使用資料庫
|
||||
$db = new Database\DBUserSession();
|
||||
|
||||
|
||||
// 產生登入token
|
||||
$passUtil = new Util\Password();
|
||||
$token = null;
|
||||
@ -84,10 +84,10 @@ class UserSession {
|
||||
$token = $passUtil->generator(32);
|
||||
}
|
||||
while ($db->queryByToken($token));
|
||||
|
||||
|
||||
// 登入資訊寫入資料庫
|
||||
$db->login($token, $userId, $agent);
|
||||
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
@ -96,14 +96,14 @@ class UserSession {
|
||||
echo 'No Found user: '. $e->getUserId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 使用者登出
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* $session = new User\UserSession();
|
||||
* $session->logout('YdcfzqUuuRAR]4h6u4^Ew-qa4A-kvD5C');
|
||||
@ -111,15 +111,15 @@ class UserSession {
|
||||
* catch (Exception\LoginTokenNoFoundException $e) {
|
||||
* echo 'No Login by token: '. $e->getToken();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param string $token 登入階段token
|
||||
* @throw \UElearning\Exception\LoginTokenNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function logout($token) {
|
||||
|
||||
|
||||
$db = new Database\DBUserSession();
|
||||
|
||||
|
||||
// 如果有找到此登入階段
|
||||
if( $db->queryByToken($token) ) {
|
||||
$db->logout($token);
|
||||
@ -129,19 +129,19 @@ class UserSession {
|
||||
throw new Exception\LoginTokenNoFoundException($token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 將其他已登入的裝置登出
|
||||
* @param string $token 登入階段token
|
||||
* @return int 已登出數量
|
||||
* @throw \UElearning\Exception\LoginTokenNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function logoutOtherSession($token) {
|
||||
|
||||
// 先從token查詢到使用者是誰
|
||||
$user_id = $this->getUserId($token);
|
||||
|
||||
|
||||
$db = new Database\DBUserSession();
|
||||
// 如果有找到此登入階段
|
||||
if( $db->queryByToken($token) ) {
|
||||
@ -166,20 +166,20 @@ class UserSession {
|
||||
throw new Exception\LoginTokenNoFoundException($token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得使用者物件
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* try {
|
||||
* // 正常寫法
|
||||
* $userSession = new User\UserSession();
|
||||
* $user = $userSession->getUser(‘YZ8@(3fYb[!f!A^E4^6b4LuqxSXgZ2FJ’);
|
||||
*
|
||||
*
|
||||
* // 簡短寫法(PHP 5.4以上才支援)
|
||||
* //$user = (new User\UserSession())->getUser('YZ8@(3fYb[!f!A^E4^6b4LuqxSXgZ2FJ');
|
||||
*
|
||||
*
|
||||
* // 撈帳號資料
|
||||
* echo '暱稱: '.$user->getNickName(); // 取得暱稱
|
||||
* echo '本名: '.$user->getRealName(); // 取得本名
|
||||
@ -187,104 +187,104 @@ class UserSession {
|
||||
* catch (Exception\LoginTokenNoFoundException $e) {
|
||||
* echo 'No Found Token: '. $e->getToken();
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param string $token 登入階段token
|
||||
* @return User 使用者物件
|
||||
* @throw \UElearning\Exception\LoginTokenNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getUser($token) {
|
||||
$userId = $this->getUserId($token);
|
||||
return new User($userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得使用者ID
|
||||
* @param string $token 登入階段token
|
||||
* @return string 使用者ID
|
||||
* @throw \UElearning\Exception\LoginTokenNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getUserId($token) {
|
||||
$db = new Database\DBUserSession();
|
||||
$sessionArray = $db->queryByToken($token);
|
||||
if(isset($sessionArray)) return $sessionArray['user_id'];
|
||||
else throw new Exception\LoginTokenNoFoundException($token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得登入資訊
|
||||
* @param string $token 登入階段token
|
||||
* @return Array 此登入階段資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getTokenInfo($token) {
|
||||
// TODO: 取得登入資訊
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有此使用者已登入的登入階段資訊
|
||||
* @param string $userId 使用者帳號名稱
|
||||
* @return Array 已登入的所有登入階段資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getUserLoginInfo($userId) {
|
||||
// TODO: 取得所有此使用者已登入的登入階段資訊
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得此使用者登入的裝置數
|
||||
* @param string $userId 使用者帳號名稱
|
||||
* @return int 所有以登入的數量
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getCurrentLoginTotalByUserId($userId) {
|
||||
|
||||
|
||||
// 確保若無此使用者則丟例外
|
||||
$user = new User($userId);
|
||||
|
||||
|
||||
// 查詢者個使用者的所有登入階段
|
||||
$db = new Database\DBUserSession();
|
||||
$allSession = $db->queryLoginByUserId($userId);
|
||||
|
||||
|
||||
// 回傳目前已登入的裝置數
|
||||
if(isset($allSession)) {
|
||||
return count($allSession);
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取得所有此使用者全部的登入階段資訊
|
||||
*
|
||||
*
|
||||
* 用於查詢登入紀錄的時候使用
|
||||
* @param string $userId 使用者帳號名稱
|
||||
* @return Array 已登入的所有登入階段資訊
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function getUserAllInfo($userId) {
|
||||
// TODO: 取得所有此使用者全部的登入階段資訊
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 將此使用者全部登入階段登出
|
||||
* @param string $userId 使用者帳號名稱
|
||||
* @return int 已登出數量
|
||||
* @throw UElearning\User\Exception\UserNoFoundException
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function logoutByUser($userId) {
|
||||
|
||||
|
||||
// 確保若無此使用者則丟例外
|
||||
$user = new User($userId);
|
||||
|
||||
|
||||
// 登出此使用者所有登入階段
|
||||
$db = new Database\DBUserSession();
|
||||
|
||||
|
||||
$logoutTotal = 0;
|
||||
$logoutTotal = $db->logoutByUserId($userId);
|
||||
return $logoutTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ namespace UElearning\Util;
|
||||
|
||||
/**
|
||||
* 密碼以及加密相關的函式庫
|
||||
*
|
||||
*
|
||||
* 使用範例:
|
||||
*
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Util/Password.php';
|
||||
* use UElearning\Util;
|
||||
*
|
||||
*
|
||||
* $passUtil = new Util\Password();
|
||||
* echo $passUtil->generator(10); // 產生10個字的密碼
|
||||
* echo $passUtil->encrypt('abc'); // 加密此字串
|
||||
@ -27,24 +27,24 @@ namespace UElearning\Util;
|
||||
* @subpackage Util
|
||||
*/
|
||||
class Password {
|
||||
|
||||
|
||||
/**
|
||||
* 取得亂數字串
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2007 Tsung-Hao
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@ -52,7 +52,7 @@ class Password {
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*
|
||||
* @author tsung http://plog.longwin.com.tw
|
||||
* @desc http://blog.longwin.com.tw/2007/11/php_snap_image_block_2007/
|
||||
* @param int $password_len 字串長度(幾個字)
|
||||
@ -72,14 +72,14 @@ class Password {
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加密這段字
|
||||
*
|
||||
*
|
||||
* @param string $text 原本字串
|
||||
* @return string 加密後結果字串
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function encrypt($text){
|
||||
// 從config.php設定檔取得預設加密方式
|
||||
switch(ENCRYPT_MODE){
|
||||
@ -100,19 +100,19 @@ class Password {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加密這段字
|
||||
*
|
||||
*
|
||||
* @param string $encrypted 已加密字串
|
||||
* @param string $text 原本字串
|
||||
* @return bool true代表與加密後字串一樣
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function checkSame($encrypted, $text) {
|
||||
// 加密此字串
|
||||
$textToEncypt = $this->encrypt($text);
|
||||
|
||||
|
||||
// 判斷是否吻合
|
||||
if( $textToEncypt == $encrypted ) {
|
||||
return true;
|
||||
@ -121,40 +121,40 @@ class Password {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* MD5加密這段字
|
||||
*
|
||||
*
|
||||
* @param string $text 原本字串
|
||||
* @return string 加密後結果字串
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function md5Encrypt($text){
|
||||
return md5($text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SHA1加密這段字
|
||||
*
|
||||
*
|
||||
* @param string $text 原本字串
|
||||
* @return string 加密後結果字串
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function sha1Encrypt($text){
|
||||
return sha1($text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CRYPT加密這段字
|
||||
*
|
||||
*
|
||||
* @param string $text 原本字串
|
||||
* @return string 加密後結果字串
|
||||
* @since 2.0.0
|
||||
*/
|
||||
*/
|
||||
public function cryptEncrypt($text){
|
||||
return crypt($text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user