User Manager to fix & fill setclass
This commit is contained in:
parent
adf9c28135
commit
697e213aa3
@ -8,6 +8,8 @@ namespace UElearning\User;
|
|||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBUser.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBUser.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/User/UserGroupAdmin.php';
|
require_once UELEARNING_LIB_ROOT.'/User/UserGroupAdmin.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/User/UserGroup.php';
|
require_once UELEARNING_LIB_ROOT.'/User/UserGroup.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/User/ClassGroupAdmin.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/User/ClassGroup.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/User/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/User/Exception.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/Exception.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Util/Password.php';
|
require_once UELEARNING_LIB_ROOT.'/Util/Password.php';
|
||||||
@ -232,7 +234,6 @@ class User {
|
|||||||
else {
|
else {
|
||||||
throw new Exception\GroupNoFoundException($toGroup);
|
throw new Exception\GroupNoFoundException($toGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -248,23 +249,69 @@ class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得所在群組顯示名稱
|
* 取得所在班級名稱
|
||||||
*
|
*
|
||||||
* @return string 班級名稱
|
* @return string 班級名稱
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function getClassName(){
|
public function getClassName(){
|
||||||
// TODO: 取得所在群組顯示名稱
|
// TODO: 取得所在群組顯示名稱
|
||||||
|
// 群組ID
|
||||||
|
$classID = $this->queryResultArray['class_id'];
|
||||||
|
|
||||||
|
// 檢查有此群組
|
||||||
|
if(isset($classID)) {
|
||||||
|
// 取得群組名稱
|
||||||
|
try {
|
||||||
|
$group = new ClassGroup($classID);
|
||||||
|
return $group->getName();
|
||||||
|
}
|
||||||
|
catch (Exception\ClassNoFoundException $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 設定所在群組
|
* 設定所在班級
|
||||||
*
|
*
|
||||||
* @param string $toGroup 班級ID
|
* 範例:
|
||||||
|
*
|
||||||
|
* try {
|
||||||
|
* $user = new User\User('yuan');
|
||||||
|
*
|
||||||
|
* try {
|
||||||
|
* $user->setClass(1);
|
||||||
|
* }
|
||||||
|
* catch (User\Exception\ClassNoFoundException $e) {
|
||||||
|
* echo 'No Class to set: '. $e->getGroupId();
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* catch (User\Exception\UserNoFoundException $e) {
|
||||||
|
* echo 'No Found user: '. $e->getUserId();
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @param string $toClass 班級ID
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function setClass($toClass){
|
public function setClass($toClass){
|
||||||
// TODO: 設定所在群組
|
|
||||||
|
// 檢查有此群組
|
||||||
|
if(isset($toClass)) {
|
||||||
|
|
||||||
|
$classGroupAdmin = new ClassGroupAdmin();
|
||||||
|
if($classGroupAdmin->isExist($toClass)) {
|
||||||
|
$this->setUpdate('class_id', $toClass);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Exception\ClassNoFoundException($toGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->setUpdate('class_id', null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
@ -26,6 +26,10 @@ class UserAdmin {
|
|||||||
* 建立使用者
|
* 建立使用者
|
||||||
*
|
*
|
||||||
* 建立使用者範例:
|
* 建立使用者範例:
|
||||||
|
*
|
||||||
|
* require_once __DIR__.'/../config.php';
|
||||||
|
* require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
|
||||||
|
* use UElearning\User;
|
||||||
*
|
*
|
||||||
* try {
|
* try {
|
||||||
* $userAdmin = new User\UserAdmin();
|
* $userAdmin = new User\UserAdmin();
|
||||||
@ -35,13 +39,13 @@ class UserAdmin {
|
|||||||
* 'group_id' => 'admin',
|
* 'group_id' => 'admin',
|
||||||
* 'enable' => true,
|
* 'enable' => true,
|
||||||
* 'nickname' => '艾瑞克',
|
* 'nickname' => '艾瑞克',
|
||||||
* 'email' => 'eric@example.com'
|
* 'email' => 'eric@example.com' )
|
||||||
* ));
|
* );
|
||||||
*
|
*
|
||||||
* }
|
* }
|
||||||
* // 若已有重複帳號名稱
|
* // 若已有重複帳號名稱
|
||||||
* catch (User\Exception\UserIdExistException $e) {
|
* catch (User\Exception\UserIdExistException $e) {
|
||||||
* echo 'Is exist user: ', $e->getUserId();
|
* echo 'Is exist user: ', $e->getUserId();
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @param array $userInfoArray 使用者資訊陣列,格式為:
|
* @param array $userInfoArray 使用者資訊陣列,格式為:
|
||||||
|
@ -27,9 +27,14 @@ class UserSession {
|
|||||||
*
|
*
|
||||||
* 範例:
|
* 範例:
|
||||||
*
|
*
|
||||||
|
* require_once __DIR__.'/../config.php';
|
||||||
|
* require_once UELEARNING_LIB_ROOT.'/User/UserSession.php';
|
||||||
|
* use UElearning\User;
|
||||||
|
*
|
||||||
* try {
|
* try {
|
||||||
* $session = new User\UserSession();
|
* $session = new User\UserSession();
|
||||||
* echo 'Token: '$session->login('yuan', '123456', 'browser');
|
* $loginToken = $session->login('yuan', 'password', 'browser');
|
||||||
|
* echo 'Token: '.$loginToken;
|
||||||
* }
|
* }
|
||||||
* catch (User\Exception\UserNoFoundException $e) {
|
* catch (User\Exception\UserNoFoundException $e) {
|
||||||
* echo 'No Found user: '. $e->getUserId();
|
* echo 'No Found user: '. $e->getUserId();
|
||||||
@ -162,6 +167,25 @@ class UserSession {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得使用者物件
|
* 取得使用者物件
|
||||||
|
*
|
||||||
|
* 範例:
|
||||||
|
*
|
||||||
|
* 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(); // 取得本名
|
||||||
|
* }
|
||||||
|
* catch (User\Exception\LoginTokenNoFoundException $e) {
|
||||||
|
* echo 'No Found Token: '. $e->getToken();
|
||||||
|
* }
|
||||||
|
*
|
||||||
* @param string $token 登入階段token
|
* @param string $token 登入階段token
|
||||||
* @return User 使用者物件
|
* @return User 使用者物件
|
||||||
* @throw \UElearning\User\Exception\LoginTokenNoFoundException
|
* @throw \UElearning\User\Exception\LoginTokenNoFoundException
|
||||||
|
Loading…
x
Reference in New Issue
Block a user