DBTheme & 修正註解的subpackage

This commit is contained in:
Yuan Chiu 2014-10-28 18:51:36 +08:00
parent 670a875a0d
commit 699e9fc29f
10 changed files with 303 additions and 39 deletions

View File

@ -150,7 +150,7 @@ class DBStudyActivity extends Database {
* @param string $where 查詢語法
* @return array 查詢結果陣列
*/
public function queryActivityByWhere($where) {
protected function queryActivityByWhere($where) {
$sqlString = "SELECT `SaID`, `UID`, `ThID`, ".
"`StartTime`, `EndTime`, ".

View File

@ -30,7 +30,7 @@ class DBTarget extends Database {
* @param string $where 查詢語法
* @return array 查詢結果陣列
*/
public function queryTargetByWhere($where) {
protected function queryTargetByWhere($where) {
$sqlString = "SELECT `TID`, Target.`AID`, Area.`HID`, ".
"`TNum`, `TName`, `TMapID`, `TLearnTime`, ".
@ -188,7 +188,7 @@ class DBTarget extends Database {
* @param string $where 查詢語法
* @return array 查詢結果陣列
*/
private function queryAreaByWhere($where) {
protected function queryAreaByWhere($where) {
$sqlString = "SELECT * FROM `".$this->table('Area')."`".
"WHERE ".$where;
@ -329,7 +329,7 @@ class DBTarget extends Database {
* @param string $where 查詢語法
* @return array 查詢結果陣列
*/
private function queryHallByWhere($where) {
protected function queryHallByWhere($where) {
$sqlString = "SELECT * FROM `".$this->table('Hall')."`".
"WHERE ".$where;

View File

@ -0,0 +1,166 @@
<?php
/**
* DBTheme.php
*/
namespace UElearning\Database;
use UElearning\Exception;
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
/**
* 學習主題資料表
*
* @author Yuan Chiu <chyuaner@gmail.com>
* @version 2.0.0
* @package UElearning
* @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`
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();
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
// 製作回傳結果陣列
$result = array();
foreach($queryResultAll as $key => $thisResult) {
array_push($result,
array( 'theme_id' => $thisResult['ThID'],
'name' => $thisResult['ThName'],
'learn_time' => $thisResult['ThLearnTime'],
'introduction' => $thisResult['ThIntroduction'],
'target_total' => $thisResult['TargetTotal'],
'build_time' => $thisResult['ThBuildTime'],
'modify_time' => $thisResult['ThModifyTime'] )
);
}
return $result;
}
// 若都沒查到的話
else {
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(
* 'theme_id' => <主題ID>,
* 'name' => <主題名稱>,
* 'learn_time' => <預估的學習時間>,
* 'introduction' => <主題介紹>,
* 'build_time' => <主題建立時間>,
* 'modify_time' => <主題資料修改時間>
* );
*
*/
public function queryTheme($thId) {
$queryResultAll =
$this->queryThemeByWhere("`ThID`=".$this->connDB->quote($thId));
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
return $queryResultAll[0];
}
// 若都沒查到的話
else {
return null;
}
}
/**
* 查詢所有主題資料
*
* @return array 主題資料陣列,格式為:
*
* array(
* array(
* 'theme_id' => <主題ID>,
* 'name' => <主題名稱>,
* 'learn_time' => <預估的學習時間>,
* 'introduction' => <主題介紹>,
* 'build_time' => <主題建立時間>,
* '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) {
// case 'area_id': $sqlField = 'AID'; break;
// case 'hall_id': $sqlField = 'HID'; break;
// case 'target_number': $sqlField = 'TNum'; break;
// case 'name': $sqlField = 'TName'; break;
// case 'map_url': $sqlField = 'TMapID'; break;
// case 'learn_time': $sqlField = 'TLearnTime'; break;
// case 'PLj': $sqlField = 'PLj'; break;
// case 'Mj': $sqlField = 'Mj'; break;
// case 'S': $sqlField = 'S'; break;
// 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(':value', $value);
// $query->execute();
// }
}

View File

@ -11,7 +11,7 @@ namespace UElearning\Exception;
* 沒有找到此活動
* @since 2.0.0
* @package UElearning
* @subpackage Target
* @subpackage Study
*/
class StudyActivityNoFoundException extends \UnexpectedValueException {
/**
@ -42,7 +42,7 @@ class StudyActivityNoFoundException extends \UnexpectedValueException {
* 此活動已結束
* @since 2.0.0
* @package UElearning
* @subpackage Target
* @subpackage Study
*/
class StudyActivityFinishedException extends \UnexpectedValueException {
/**
@ -67,4 +67,35 @@ class StudyActivityFinishedException extends \UnexpectedValueException {
public function getId() {
return $this->id;
}
}
}
/**
* 沒有找到此主題
* @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;
}
}

View File

@ -48,7 +48,7 @@ use UElearning\User;
*
* @version 2.0.0
* @package UElearning
* @subpackage Target
* @subpackage Study
*/
class StudyActivity {
/**

View File

@ -16,7 +16,7 @@ use UElearning\Exception;
*
* @version 2.0.0
* @package UElearning
* @subpackage Target
* @subpackage Study
*/
class StudyActivityManager {

View File

@ -17,7 +17,7 @@ use UElearning\User;
*
* @version 2.0.0
* @package UElearning
* @subpackage Target
* @subpackage Study
*/
class StudyWill {
/**

View File

@ -5,8 +5,8 @@
namespace UElearning\Study;
//require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
//require_once UELEARNING_LIB_ROOT.'/Target/Exception.php';
require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
use UElearning\Exception;
@ -15,9 +15,31 @@ 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 Target
* @subpackage Study
*/
class Theme {
@ -25,7 +47,7 @@ class Theme {
* 主題ID
* @type int
*/
protected $tId;
protected $id;
// ------------------------------------------------------------------------
@ -40,20 +62,20 @@ class Theme {
/**
* 從資料庫取得查詢
*
* @throw UElearning\Exception\AreaNoFoundException
* @throw \UElearning\Exception\ThemeNoFoundException
* @since 2.0.0
*/
protected function getQuery(){
// TODO: 從資料庫取得查詢
//// 從資料庫查詢
//$db = new Database\DBTarget();
//$areaInfo = $db->queryArea($this->aId);
//
//// 判斷有沒有這個
//if( $areaInfo != null ) {
// $this->queryResultArray = $areaInfo;
//}
//else throw new Exception\AreaNoFoundException($this->aId);
$db = new Database\DBTheme();
$info = $db->queryTheme($this->id);
// 判斷有沒有這個
if( $info != null ) {
$this->queryResultArray = $info;
}
else throw new Exception\ThemeNoFoundException($this->id);
}
/**
@ -77,8 +99,8 @@ class Theme {
* @param int $inputTID 主題ID
* @since 2.0.0
*/
public function __construct($inputTID){
$this->tId = $inputAID;
public function __construct($inputID){
$this->id = $inputID;
$this->getQuery();
}
@ -91,7 +113,7 @@ class Theme {
* @since 2.0.0
*/
public function getId(){
return $this->tId;
return $this->id;
}
/**
@ -111,7 +133,7 @@ class Theme {
* @since 2.0.0
*/
public function getIntroduction(){
//return $this->queryResultArray['name'];
return $this->queryResultArray['introduction'];
}
/**
@ -121,7 +143,7 @@ class Theme {
* @since 2.0.0
*/
public function getLearnTime(){
//return $this->queryResultArray['name'];
return $this->queryResultArray['learn_time'];
}
/**

View File

@ -0,0 +1,47 @@
<?php
/**
* ThemeManager.php
*/
namespace UElearning\User;
require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
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>,
* 'name' => <主題名稱>,
* 'learn_time' => <預估的學習時間>,
* 'introduction' => <主題介紹>,
* 'build_time' => <主題建立時間>,
* 'modify_time' => <主題資料修改時間>
* )
* );
*
* @since 2.0.0
*/
public function getInfoList() {
$db = new Database\DBTheme();
$queryResult = $db->queryAllTheme();
return $queryResult;
}
}

View File

@ -27,20 +27,18 @@ class UserGroupAdmin {
*
* 建立使用者群組範例:
*
* // 建立班級
* try {
* $groupAdmin = new User\UserGroupAdmin();
* $groupAdmin->create(
* array( 'group_id' => 'student',
* 'name' => '學生',
* 'memo' => null,
* 'auth_server_admin' => false,
* 'auth_client_admin' => false
* $classAdmin = new User\ClassGroupAdmin();
* $newClassId = $classAdmin->create(
* array( 'name' => '五年十班',
* 'memo' => null
* ));
*
* echo '你剛建立:'.$newClassId;
* }
* // 若已有重複群組ID
* catch (Exception\GroupIdExistException $e) {
* echo 'Is exist group: ', $e->getGroupId();
* // 若已有重複班級ID
* catch (Exception\ClassIdExistException $e) {
* echo 'Is exist class: ', $e->getGroupId();
* }
*
* @param array $groupArray 使用者群組資訊陣列,格式為: