diff --git a/docs/here b/docs/here deleted file mode 100644 index e69de29..0000000 diff --git a/htdocs/lib/Config/Exceptions.php b/htdocs/lib/Config/Exceptions.php index 14aa2e0..057302e 100644 --- a/htdocs/lib/Config/Exceptions.php +++ b/htdocs/lib/Config/Exceptions.php @@ -1,4 +1,4 @@ - 'mysql', + * 'host' => 'localhost', + * 'port' => '3306', + * 'user' => 'user', + * 'password' => '123456', + * '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\Exception\DatabaseNoSupportException $e) { + * echo 'No Support in ', $e->getType(); + * } catch (Exception $e) { + * echo 'Caught other exception: ', $e->getMessage(); + * } * * @author Yuan Chiu * @version 3.0 @@ -21,4 +57,24 @@ */ class DBAdmin extends Database { + /** + * 建立資料庫 + * + * 在資料庫系統內建立一個資料庫。 + * (注意!需有建立資料庫的權限) + * + */ + public function createDB() { + // TODO: Fill code in + + } + + /** + * 建立所有所需的資料表 + * + */ + public function createAllTable() { + // TODO: Fill code in + + } } \ No newline at end of file diff --git a/htdocs/lib/Database/DBUser.php b/htdocs/lib/Database/DBUser.php index 9b7e632..9875196 100644 --- a/htdocs/lib/Database/DBUser.php +++ b/htdocs/lib/Database/DBUser.php @@ -5,10 +5,24 @@ * * 此檔案針對使用者資料表的功能。 * - * @filesource + * @package UElearning + * @subpackage Database */ +require_once UELEARNING_LIB_ROOT.'Database/Database.php'; +require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php'; -class DBUser { +/** + * 使用者帳號資料表 + * + * 對資料庫中的使用者資料表進行操作。 + * + * + * @author Yuan Chiu + * @version 3.0 + * @package UElearning + * @subpackage Database + */ +class DBUser extends Database { /** * 資料表名稱 * @type string diff --git a/htdocs/lib/Database/Database.php b/htdocs/lib/Database/Database.php index 01aa901..da13683 100644 --- a/htdocs/lib/Database/Database.php +++ b/htdocs/lib/Database/Database.php @@ -10,16 +10,17 @@ */ require_once UELEARNING_LIB_ROOT.'Database/MySQLDB.php'; require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php'; +use UElearning\Database\Exception; /** - * 資料庫整體管理 + * 資料庫操作抽象類別 * - * 所有對於資料庫的操作(包含查詢、新增、修改、刪除),一律使用這個物件來操作。 + * 請根據一個資料表創建一個類別,並繼承此類別。所有對於資料表的操作(包含查詢、新增、修改、刪除),一律使用新創已繼承的類別物件。 * - * 例如: + * 基本的操作方式例如: * * use UElearning\Database; - * $db = new Database(array( + * $db = new Database\[資料表類別](array( * 'type' => 'mysql', * 'host' => 'localhost', * 'port' => '3306', @@ -29,14 +30,14 @@ require_once UELEARNING_LIB_ROOT.'Database/Exceptions.php'; * 'prefix' => 'chu_' * )); * - * 一個資料表為一個類別,如果要對某資料表進行操作,請參閱 + * 實際範例可參考 `DBAdmin` 類別的說明文件 * * @author Yuan Chiu * @version 3.0 * @package UElearning * @subpackage Database */ -class Database { +abstract class Database { /** * 資料庫伺服器類型 @@ -107,6 +108,7 @@ class Database { * 'prefix' => 'chu_' ) * 若不填寫將會直接使用設定在`config.php`的常數 * + * @throws UElearning\Database\Exception\DatabaseNoSupportException * @author Yuan Chiu * @since 3.0.0 */ @@ -137,7 +139,7 @@ class Database { $this->connDB = new MySQLDB($this->db_name, $this->db_host, $this->db_port, $this->db_user, $this->db_passwd); } else { - throw new DatabaseNoSupportException($this->db_type); + throw new Exception\DatabaseNoSupportException($this->db_type); } } @@ -163,25 +165,4 @@ class Database { // TODO: Fill code in } - - /** - * 建立資料庫 - * - * 在資料庫系統內建立一個資料庫。 - * (注意!需有建立資料庫的權限) - * - */ - public function createDB() { - // TODO: Fill code in - - } - - /** - * 建立所有所需的資料表 - * - */ - public function createAllTable() { - // TODO: Fill code in - - } } \ No newline at end of file diff --git a/htdocs/lib/Database/Exceptions.php b/htdocs/lib/Database/Exceptions.php index de2b675..1b370b0 100644 --- a/htdocs/lib/Database/Exceptions.php +++ b/htdocs/lib/Database/Exceptions.php @@ -1,14 +1,16 @@ - + * @version 3.0 + * @package UElearning + * @subpackage User + */ +class UserControl { + + /** + * 建立使用者 + * @since 3.0.0 + */ + public function create() { + // TODO: Fill code in + } + + /** + * 是否已有相同名稱的帳號名稱 + * + * @param string $userName 帳號名稱 + * @return bool 已有相同的帳號名稱 + * @since 3.0.0 + */ + public function isHave($userName) { + // TODO: Fill code in + } + + /** + * 使用者登入 + * @param string $userId 帳號名稱 + * @param string $password 密碼 + * @return string 登入session token + * @since 3.0.0 + */ + public function login($userId, $password) { + // TODO: Fill code in + // 如果登入錯誤,就丟例外 + } +} \ No newline at end of file