This commit is contained in:
yang 2015-01-18 13:24:40 +08:00
commit 0cd8ba2d16
11 changed files with 1140 additions and 62 deletions

View File

@ -7,6 +7,7 @@ require_once UELEARNING_LIB_ROOT.'/User/UserSession.php';
require_once UELEARNING_LIB_ROOT.'/User/UserAdmin.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivityManager.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php';
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
use UElearning\User;
@ -78,10 +79,14 @@ function login($user_id = null) {
$user = $session->getUser($loginToken);
$sessionInfo = $session->getTokenInfo($loginToken);
//取得現在時間,用字串的形式
$nowDate = date("Y-m-d H:i:s");
// 輸出結果
$app->render(201,array(
'user_id' => $user_id,
'token' => $loginToken,
'browser' => $browser,
'user_id' => $user_id,
'token' => $loginToken,
'browser' => $browser,
'user' => array(
'id' => $user->getId(),
'user_id' => $user->getId(),
@ -100,10 +105,11 @@ function login($user_id = null) {
'email' => $user->getEmail(),
'memo' => $user->getMemo(),
),
'login_time' => $sessionInfo['login_date'],
'error' => false,
'msg' => '\''.$user_id.'\' is logined',
'msg_cht' => '\''.$user_id.'\'使用者已登入'
'login_time' => $sessionInfo['login_date'],
'current_time' => $nowDate,
'error' => false,
'msg' => '\''.$user_id.'\' is logined',
'msg_cht' => '\''.$user_id.'\'使用者已登入'
));
}
catch (Exception\UserNoFoundException $e) {
@ -849,6 +855,231 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
}
});
/*
* 取得此標的資料
* GET http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}
*/
$app->get('/:token/activitys/:said/points/:tid', function ($token, $saId, $tId) use ($app) {
try {
// 查詢使用者
$session = new User\UserSession();
$user_id = $session->getUserId($token);
// 取得開始後的學習活動資訊
$sact = new Study\StudyActivity($saId);
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
// 取得此活動的主題
$thid = $sact->getThemeId();
// 取得本次採用的教材風格
$materialMode = $sact->getMaterialStyle();
// 取得主題內所有的標的資訊
$target = new Target\Target($thid);
$materialUrl = $target->getMaterialUrl(true, $materialMode);
$virtualMaterialUrl = $target->getMaterialUrl(false, $materialMode);
// 處理噴出結果
$output_targets = array(
'theme_id' => $thid,
'target_id' => $target->getId(),
'hall_id' => $target->getHallId(),
//'hall_name' => $thisTargetArray['hall_name'],
'area_id' => $target->getAreaId(),
//'area_name' => $thisTargetArray['area_name'],
//'floor' => $thisTargetArray['floor'],
//'area_number' => $thisTargetArray['area_number'],
'target_number' => $target->getNumber(),
'name' => $target->getName(),
'map_url' => $target->getMapUrl(),
'material_url' => $materialUrl,
'virtual_material_url' => $virtualMaterialUrl,
'learn_time' => $target->getLearnTime(),
'PLj' => $target->getPLj(),
'Mj' => $target->getMj(),
'S' => $target->getS(),
'Fj' => $target->getFj()
);
// 噴出結果
$app->render(200,array(
'token' => $token,
'user_id' => $user_id,
'activity_id' => $sact->getId(),
'target' => $output_targets,
'error' => false
));
}
// 若非本人所有,則視同無此活動
else {
throw new Exception\StudyActivityNoFoundException($saId);
}
}
catch (Exception\LoginTokenNoFoundException $e) {
$app->render(401,array(
'token' => $token,
'error' => true,
'msg' => 'No \''.$token.'\' session. Please login again.',
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
'substatus' => 204
));
}
catch (Exception\StudyActivityNoFoundException $e) {
$app->render(404,array(
'token' => $token,
'error' => true,
'msg' => 'No found this activity.',
'msg_cht' => '沒有此學習活動'
));
}
});
/*
* 進入此學習點
* POST http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}/toin
*/
$app->post('/:token/activitys/:said/points/:tid/toin', function ($token, $saId, $tId) use ($app) {
// 取得帶來的參數
$cType = $app->request->getContentType();
if($cType == 'application/x-www-form-urlencoded') {
$is_entity = isset($_POST['is_entity']) ? $_POST['is_entity'] : true;
}
else /*if($cType == 'application/json')*/ {
$postData = $app->request->getBody();
$postDataArray = json_decode($postData);
$is_entity = isset($postDataArray->is_entity)
? $postDataArray->is_entity : true;
}
/*else {
$app->render(400, array(
'Content-Type'=> $cType,
'error' => true,
'msg' => '',
'msg_cht' => '輸入參數的Content-Type不在支援範圍內 或是沒有輸入',
'substatus' => 102
)
);
}*/
try {
// 查詢使用者
$session = new User\UserSession();
$user_id = $session->getUserId($token);
// 取得開始後的學習活動資訊
$sact = new Study\StudyActivity($saId);
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
// 進入學習點
try{
$sid = $sact->toInTarget($tId, $is_entity);
}
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
catch (Exception\InLearningException $e) {
$sact->toOutTarget($tId);
$sid = $sact->toInTarget($tId, $is_entity);
}
// 噴出結果
$app->render(200,array(
'token' => $token,
'user_id' => $user_id,
'activity_id' => $sact->getId(),
'study_id' => $sid,
'error' => false
));
}
// 若非本人所有,則視同無此活動
else {
throw new Exception\StudyActivityNoFoundException($saId);
}
}
catch (Exception\LoginTokenNoFoundException $e) {
$app->render(401,array(
'token' => $token,
'error' => true,
'msg' => 'No \''.$token.'\' session. Please login again.',
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
'substatus' => 204
));
}
catch (Exception\StudyActivityNoFoundException $e) {
$app->render(404,array(
'token' => $token,
'error' => true,
'msg' => 'No found this activity.',
'msg_cht' => '沒有此學習活動'
));
}
});
/*
* 進入此學習點
* POST http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/points/{標的編號}/toout
*/
$app->post('/:token/activitys/:said/points/:tid/toout', function ($token, $saId, $tId) use ($app) {
try {
// 查詢使用者
$session = new User\UserSession();
$user_id = $session->getUserId($token);
// 取得開始後的學習活動資訊
$sact = new Study\StudyActivity($saId);
// 確認此學習活動是否為本人所有
if($sact->getUserId() == $user_id) {
// 離開學習點
$sact->toOutTarget($tId);
// 噴出結果
$app->render(201,array(
'token' => $token,
'user_id' => $user_id,
'activity_id' => $sact->getId(),
'error' => false
));
}
// 若非本人所有,則視同無此活動
else {
throw new Exception\StudyActivityNoFoundException($saId);
}
}
catch (Exception\LoginTokenNoFoundException $e) {
$app->render(401,array(
'token' => $token,
'error' => true,
'msg' => 'No \''.$token.'\' session. Please login again.',
'msg_cht' => '沒有\''.$token.'\'登入階段,請重新登入',
'substatus' => 204
));
}
catch (Exception\StudyActivityNoFoundException $e) {
$app->render(404,array(
'token' => $token,
'error' => true,
'msg' => 'No found this activity.',
'msg_cht' => '沒有此學習活動'
));
}
});
});
// ============================================================================
@ -873,9 +1104,14 @@ else {
// API首頁
$app->get('/', 'APIrequest', function () use ($app) {
//取得現在時間,用字串的形式
$nowDate = date("Y-m-d H:i:s");
$app->render(200, array(
'title' => '',
'version' => '2.0',
'current_time' => $nowDate,
'error' => false,
));
});

View File

@ -21,9 +21,10 @@ class DBRecommand extends Database
* @param string $where SQL WHERE子句
* @return array 查詢結果
*/
protected function queryEdgeByWhere($where)
{
$sqlString = "SELECT DISTINCT ".$this->table('Edge').".Ti, ".$this->table('Edge').".Tj, ".$this->table('Edge').".MoveTime".
protected function queryEdgeByWhere($where)
{
$sqlString = "SELECT DISTINCT ".$this->table('Edge').".Ti, ".$this->table('Edge').".Tj, ".$this->table('Edge').".MoveTime".
" FROM ".$this->table('Edge')." WHERE ".$where;
$query = $this->connDB->prepare($sqlString);
$query->execute();
@ -44,11 +45,16 @@ class DBRecommand extends Database
return $result;
}
else return null;
}
}
/**
* 內部查詢用
* @param string $where SQL WHERE子句
* @return array 查詢結果
*/
protected function queryBelongByWhere($where)
{
$sqlString = "SELECT ".$this->table('tbelong').".Weights FROM ".$this->table('tbelong')." WHERE ".$where;
$sqlString = "SELECT ".$this->table('TBelong').".Weights FROM ".$this->table('TBelong')." WHERE ".$where;
$query = $this->connDB->prepare($sqlString);
$query->execute();
@ -66,19 +72,29 @@ class DBRecommand extends Database
else return null;
}
/**
* 以下一個學習點和主題編號查詢屬於的權重資料
* @param string $next_point 下一個學習點編號
* @return array 查詢結果
*/
public function queryBelongByID($next_point,$theme_number)
{
$whereClause = $this->table('tbelong').".thID = ".$this->connDB->quote($theme_number)." AND ".$this->table('tbelong').".TID = ".$this->connDB->quote($next_point);
$whereClause = $this->table('TBelong').".ThID = ".$this->connDB->quote($theme_number)." AND ".$this->table('TBelong').".TID = ".$this->connDB->quote($next_point);
$AllOfResult = $this->queryBelongByWhere($whereClause);
if(count($AllOfResult) != 0) return $AllOfResult;
if(count($AllOfResult) != 0) return $AllOfResult[0];
else return null;
}
/**
* 以目前的學習點編號查詢下一個學習點的資訊
* @param string $currentPoint 目前的學習點編號
* @return array 查詢結果
*/
public function queryEdgeByID($currentPoint)
{
$AllOfResult = $this->queryBelongByWhere("Ti = ".$this->connDB->quote($currentPoint));
//echo "EEEEEEEEE";
$AllOfResult = $this->queryEdgeByWhere($this->table('Edge').".Ti = ".$this->connDB->quote($currentPoint));
if(count($AllOfResult) != 0) return $AllOfResult;
else return null;
}

View File

@ -0,0 +1,391 @@
<?php
/**
* DBStudy.php
*
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料庫查詢用。
*/
namespace UElearning\Database;
use UElearning\Exception;
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
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\DBStudy();
* // 查詢'yuan'的所有活動
* $data = $db->queryAllStudyByUserId('yuan');
* echo '<pre>';print_r($data);echo '</pre>';
*
* @author Yuan Chiu <chyuaner@gmail.com>
* @version 2.0.0
* @package UElearning
* @subpackage Database
*/
class DBStudy extends Database {
/**
* 內部使用的查詢動作
* @param string $where 查詢語法
* @return array 查詢結果陣列
*/
protected function queryByWhere($where) {
$sqlString = "SELECT `SID`, `SaID`, ".
"`TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime` ".
"FROM `".$this->table('Study')."` ".
"WHERE ".$where;
$query = $this->connDB->prepare($sqlString);
$query->execute();
$queryResultAll = $query->fetchAll();
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
// 製作回傳結果陣列
$result = array();
foreach($queryResultAll as $key => $thisResult) {
if($thisResult['IsEntity'] != '0') {
$output_entity = true;
}
else { $output_entity = false; }
array_push($result,
array( 'study_id' => (int)$thisResult['SID'],
'activity_id' => (int)$thisResult['SaID'],
'target_id' => (int)$thisResult['TID'],
'is_entity' => $output_entity,
'in_target_time' => $thisResult['In_TargetTime'],
'out_target_time' => $thisResult['Out_TargetTime']
)
);
}
return $result;
}
// 若都沒查到的話
else {
return null;
}
}
/**
* 以活動編號查詢所有進出標的資料
*
* @return array 進出標的資料陣列,格式為:
*
* array(
* array(
* 'study_id' => <流水編號>,
* 'activity_id' => <活動編號>,
* 'target_id' => <標的編號>,
* 'is_entity' => <是否為現場學習>,
* 'in_target_time' => <進入時間>,
* 'out_target_time' => <離開時間>
* )
* );
*
*/
public function queryById($id) {
$queryResultAll = $this->queryByWhere("`SID`=".$this->connDB->quote($id));
// 如果有查到一筆以上
if( count($queryResultAll) >= 1 ) {
return $queryResultAll[0];
}
// 若都沒查到的話
else {
return null;
}
}
/**
* 以活動編號查詢所有進出標的資料
*
* @return array 進出標的資料陣列,格式為:
*
* array(
* array(
* 'study_id' => <流水編號>,
* 'activity_id' => <活動編號>,
* 'target_id' => <標的編號>,
* 'is_entity' => <是否為現場學習>,
* 'in_target_time' => <進入時間>,
* 'out_target_time' => <離開時間>
* )
* );
*
*/
public function queryByActivityId($id) {
return $this->queryByWhere("`SID`=".$this->connDB->quote($id));
}
/**
* 查詢所有進出標的資料
*
* @return array 進出標的資料陣列,格式為:
*
* array(
* array(
* 'study_id' => <流水編號>,
* 'activity_id' => <活動編號>,
* 'target_id' => <標的編號>,
* 'is_entity' => <是否為現場學習>,
* 'in_target_time' => <進入時間>,
* 'out_target_time' => <離開時間>
* )
* );
*
*/
public function queryAll() {
return $this->queryByWhere("1");
}
/**
* 建立學習點進出記錄
*
* @param string $activity_id 活動編號
* @param string $target_id 標的編號
* @param string $is_entity 是否為現場學習
* @param int $in_target_time 進入時間
* @param int $out_target_time 離開時間
*
* @return int 剛新增的記錄編號
* @since 2.0.0
*/
public function insert($activity_id, $target_id,
$is_entity, $in_target_time, $out_target_time)
{
if(!isset($is_entity)) {
$is_entity = true;
}
// 寫入
$sqlString = "INSERT INTO `".$this->table('Study').
"` (`SaID`, `TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
VALUES ( :said , :tid , :entity , :intime , :outtime )";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":said", $activity_id);
$query->bindParam(":tid", $target_id);
$query->bindParam(":entity", $is_entity);
$query->bindParam(":intime", $in_target_time);
$query->bindParam(":outtime", $out_target_time);
$query->execute();
// 取得剛剛加入的ID
$sqlString = "SELECT LAST_INSERT_ID()";
$query = $this->connDB->query($sqlString);
$queryResult = $query->fetch();
$resultId = $queryResult[0];
return $resultId;
}
/**
* 移除一筆進出標的資料
* @param int $id 進出標的編號
* @since 2.0.0
*/
public function delete($id) {
$sqlString = "DELETE FROM ".$this->table('Study').
" WHERE `SID` = :id ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":id", $id);
$query->execute();
}
/**
* 移除此學習活動的所有進出標的資料
* @param int $id 學習活動編號
* @since 2.0.0
*/
public function deleteByActivityId($id) {
$sqlString = "DELETE FROM ".$this->table('Study').
" WHERE `SaID` = :id ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":id", $id);
$query->execute();
}
/**
* 進入學習點
*
* @param string $activity_id 活動編號
* @param string $target_id 標的編號
* @param string $is_entity 是否為現場學習
* @return int 剛新增的記錄編號
* @since 2.0.0
*/
public function toInTaeget($activity_id, $target_id, $is_entity)
{
if(!isset($is_entity)) {
$is_entity = true;
}
// 寫入
$sqlString = "INSERT INTO `".$this->table('Study').
"` (`SaID`, `TID`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
VALUES ( :said , :tid , :entity , NOW() , NULL )";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":said", $activity_id);
$query->bindParam(":tid", $target_id);
$query->bindParam(":entity", $is_entity);
$query->execute();
// 取得剛剛加入的ID
$sqlString = "SELECT LAST_INSERT_ID()";
$query = $this->connDB->query($sqlString);
$queryResult = $query->fetch();
$resultId = $queryResult[0];
return $resultId;
}
/**
* 離開學習點
*
* @param string $study_id 此記錄編號
* @since 2.0.0
*/
public function toOutTaeget($study_id)
{
// 寫入
$sqlString = "UPDATE `".$this->table('Study').
"` SET `Out_TargetTime` = NOW()
WHERE `SID` = :id ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":id", $study_id);
$query->execute();
}
/**
* 此活動內離開所有學習點
*
* @param string $activity_id 活動編號
* @since 2.0.0
*/
public function allToOutTaeget($activity_id)
{
// 寫入
$sqlString = "UPDATE `".$this->table('Study').
"` SET `Out_TargetTime` = NOW()
WHERE `SaID` = :id ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":id", $activity_id);
$query->execute();
}
/**
* 取得目前正在進行的標的編號
*
* @param int $activity_id 活動編號
* @return int 標的編號
* @since 2.0.0
*/
public function getCurrentInTargetId($activity_id) {
$sqlString = "SELECT `TID` FROM `".$this->table('Study')."` ".
"WHERE `Out_TargetTime` IS NULL AND `SaID` = :said ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":said", $activity_id);
$query->execute();
$queryResult = $query->fetch();
// 如果有查到一筆以上
if( count($queryResult) >= 1 ) {
return (int)$queryResult[0];
}
else {
return null;
}
}
/**
* 取得目前正在進行的紀錄編號
*
* @param int $activity_id 活動編號
* @return int 進出紀錄編號
* @since 2.0.0
*/
public function getCurrentInStudyId($activity_id) {
$sqlString = "SELECT `SID` FROM `".$this->table('Study')."` ".
"WHERE `Out_TargetTime` IS NULL AND `SaID` = :said ";
$query = $this->connDB->prepare($sqlString);
$query->bindParam(":said", $activity_id);
$query->execute();
$queryResult = $query->fetch();
// 如果有查到一筆以上
if( count($queryResult) >= 1 ) {
return (int)$queryResult[0];
}
else {
return null;
}
}
/**
* 取得所有在此標的的記錄編號
*
* 正常來說只會有一個,但考量使用者可能在這次活動內同一標的進出兩次以上,故還是以二維陣列輸出。
*
* @param int $activity_id 活動編號
* @param int $target_id 標的編號
* @return array 所有進出記錄資訊陣列
* @since 2.0.0
*/
public function getAllStudyIdByTargetId($activity_id, $target_id) {
$queryResultAll = $this->queryByWhere(
"`TID` = ".$this->connDB->quote($target_id).
" AND `SaID` = ".$this->connDB->quote($activity_id));
return $queryResultAll;
}
/**
* 取得在此標學習中的記錄編號
*
* 正常來說只會有一個,但考量使用者可能在這次活動內同一標的進出兩次以上,故還是以陣列輸出。
*
* @param int $activity_id 活動編號
* @param int $target_id 標的編號
* @return array 所有進出記錄資訊陣列
* @since 2.0.0
*/
public function getInStudyIdByTargetId($activity_id, $target_id) {
$queryResultAll = $this->queryByWhere(
"`TID` = ".$this->connDB->quote($target_id).
" AND `SaID` = ".$this->connDB->quote($activity_id).
" AND `Out_TargetTime` IS NULL");
return $queryResultAll;
}
}

View File

@ -54,6 +54,8 @@ class DBStudyActivity extends Database {
* @param bool $learnStyle_force 拒絕前往非推薦的學習點
* @param bool $enable_virtual 是否啟用虛擬教材
* @param string $materialMode 教材模式
*
* @return int 剛新增的活動編號
* @since 2.0.0
*/
public function insertActivity($userId, $themeId, $startTime, $endTime,
@ -408,6 +410,8 @@ class DBStudyActivity extends Database {
* @param bool $enable_virtual 是否啟用虛擬教材
* @param string $materialMode 教材模式
* @param string $isLock 是否鎖定不讓學生更改
*
* @return int 剛新增的活動編號
* @since 2.0.0
*/
public function insertWillActivity($userId, $themeId, $startTime, $expiredTime,

View File

@ -1,57 +1,87 @@
<?php
require_once __DIR__.'/../config.php';
namespace UElearning\Recommand;
require_once UELEARNING_ROOT.'/config.php';
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
require_once UELEARNING_LIB_ROOT.'/Database/DBRecommand.php';
require_once UELEARNING_LIB_ROOT.'/Study/Theme.php';
require_once UELEARNING_LIB_ROOT.'/Study/Study.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
use UElearning\Target;
use UElearning\Exception;
use UElearning\Study;
use UElearning\Database;
/**
* 推薦學習點
* Usage:
* $recommand = new RecommandPoint();
* $recommand = new RecommandPoint();
*/
class RecommandPoint
{
/**
* 正規化參數
*
* @access private
* @type double
*/
private $gamma;
/**
* 正規化參數
*
* @access private
* @type double
*/
private $gamma;
/**
* 調和參數(常數)
*
* @access private
* @type double
*/
private const $ALPHA = 0.5;
/**
* 調和參數(常數)
*
* @access private
* @type double
*/
const ALPHA=0.5;
private
private $recommand;
public function __construct()
{
public function __construct()
{
$gamma = 0;
$this->recommand = new Database\DBRecommand();
}
}
/**
* 計算正規化參數
* @return double 正規化參數
*/
private function computeNormalizationParameter($theme_number)
{
$normal = 0; //正規化之後的GAMMA值
$EntitySum = 0; //實體學習點分別算銓重之後的值
$VirtualSum = 0; //虛擬學習點分別算銓重之後的值
/**
* 計算正規化參數
* @return double 正規化參數
*/
private function computeNormalizationParameter()
{
$
}
$edge = $this->recommand->queryEdgeByID('0');
$theme = new Study\Theme($theme_number);
/**
* 推薦學習點
* @return array 學習點清單
*/
public function recommand($ )
{
for($i=0;$i<count($edge);$i++)
{
$next_point = $edge[$i]["next_point"];
$move_time = $edge[$i]["move_time"];
$next_target = new Target\Target($next_point);
$belong = $this->recommand->queryBelongByID($next_point,$theme->getId());
$weight = $belong["weight"];
}
$VirtualSum += $weight / $next_target->getLearnTime();
if($next_target->isNumberOfPeopleZero()) $Rj = 0;
else $Rj = $next_target->getMj() / $next_target->getPLj();
$EntitySum += $weight * ($next_target->getS() - $Rj + 1) / ($move_time + $next_target->getLearnTime());
}
return $EntitySum/$VirtualSum;
}
/**
* 推薦學習點
* @return array 學習點清單
*/
public function recommand($current_point,$theme_number,$activity_number)
{
}
}

View File

@ -7,6 +7,54 @@ namespace UElearning\Exception;
// TODO: 將以下類別濃縮
/**
* 沒有找到此標的進出記錄
* @since 2.0.0
* @package UElearning
* @subpackage Study
*/
class StudyNoFoundException extends \UnexpectedValueException {
/**
* 指定的學習活動ID
* @type int
*/
private $id;
/**
* 使用者帳號例外
* @param int $id 輸入的標的ID
*/
public function __construct($id) {
$this->id = $id;
parent::__construct('No Study: '.$this->id);
}
/**
* 取得輸入的標的ID
* @return int 標的ID
*/
public function getId() {
return $this->id;
}
}
/**
* 正在學習中例外(難道使用者有分身?)
* @since 2.0.0
* @package UElearning
* @subpackage Study
*/
class InLearningException extends \UnexpectedValueException {
/**
* 使用者帳號例外
* @param int $id 輸入的標的ID
*/
public function __construct() {
parent::__construct('Learning');
}
}
/**
* 沒有找到此活動
* @since 2.0.0

View File

@ -0,0 +1,179 @@
<?php
/**
* Study.php
*/
namespace UElearning\Study;
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
use UElearning\Exception;
/**
* 學習點進出記錄
*
* 一個物件即代表此學習點進出記錄
*
* @version 2.0.0
* @package UElearning
* @subpackage Study
*/
class Study {
/**
* 主題ID
* @type int
*/
protected $id;
// ------------------------------------------------------------------------
/**
* 查詢到所有資訊的結果
*
* $this->getQuery() 抓取資料表中所有資訊,並放在此陣列裡
* @type array
*/
protected $queryResultArray;
/**
* 從資料庫取得查詢
*
* @throw \UElearning\Exception\ThemeNoFoundException
* @since 2.0.0
*/
protected function getQuery(){
// 從資料庫查詢
$db = new Database\DBStudy();
$info = $db->queryById($this->id);
// 判斷有沒有這個
if( $info != null ) {
$this->queryResultArray = $info;
}
else throw new Exception\StudyNoFoundException($this->id);
}
// ========================================================================
/**
* 建構子
*
* @param int $inputTID 主題ID
* @since 2.0.0
*/
public function __construct($inputID){
$this->id = $inputID;
$this->getQuery();
}
// ========================================================================
/**
* 取得本進出記錄編號
*
* @return int 進出記錄編號
* @since 2.0.0
*/
public function getId(){
return $this->id;
}
/**
* 取得本次活動編號
*
* @return int 學習活動編號
* @since 2.0.0
*/
public function getActivityId(){
return $this->queryResultArray['activity_id'];
}
/**
* 取得標的編號
*
* @return int 標的編號
* @since 2.0.0
*/
public function getTargetId(){
return $this->queryResultArray['target_id'];
}
// /**
// * 取得標的名稱
// *
// * @return int 標的名稱
// * @since 2.0.0
// */
// public function getTargetName(){
// return $this->queryResultArray['target_id'];
// }
// /**
// * 取得此紀錄的使用者ID
// *
// * @return string 使用者ID
// * @since 2.0.0
// */
// public function getUserId(){
// return $this->queryResultArray['target_id'];
// }
/**
* 是否為實體(實際抵達學習點)
*
* @return bool 是否為實體
* @since 2.0.0
*/
public function isEntity(){
return $this->queryResultArray['is_entity'];
}
/**
* 取得進入學習點時間
*
* @return string 進入學習點時間
* @since 2.0.0
*/
public function isIn(){
// TODO: 尚未測試
if($this->queryResultArray['out_target_time'] == null) {
return true;
}
else {
return false;
}
}
/**
* 取得進入學習點時間
*
* @return string 進入學習點時間
* @since 2.0.0
*/
public function getInTime(){
return $this->queryResultArray['in_target_time'];
}
/**
* 取得離開學習點時間
*
* @return string 離開學習點時間
* @since 2.0.0
*/
public function getOutTime(){
return $this->queryResultArray['out_target_time'];
}
/**
* 離開學習點
*
* @since 2.0.0
*/
public function toOut() {
$db = new Database\DBStudy();
$db->toOutTaeget($this->id);
}
}

View File

@ -8,6 +8,7 @@ namespace UElearning\Study;
require_once UELEARNING_LIB_ROOT.'/Database/DBStudyActivity.php';
require_once UELEARNING_LIB_ROOT.'/User/User.php';
require_once UELEARNING_LIB_ROOT.'/Study/Theme.php';
require_once UELEARNING_LIB_ROOT.'/Study/StudyManager.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
use UElearning\Exception;
@ -422,4 +423,61 @@ class StudyActivity {
return $this->queryResultArray['material_mode'];
}
// ========================================================================
/**
* 此標的是否已學習過
*
* @param string $target_id 標的編號
* @return bool 是否已學習過
*/
public function isTargetLearned($target_id) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
return $sct->isTargetLearned($saId, $target_id);
}
/**
* 進入標的
*
* @param int $target_id 標的編號
* @param bool $is_entity 是否為現場學習
* @throw UElearning\Exception\InLearningException
* return int 進出紀錄編號
*/
public function toInTarget($target_id, $is_entity) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
// 進入學習點
try{
return $sct->toInTarget($saId, $target_id, $is_entity);
}
// 若狀態為正在標的內學習時,強制當成離開標的,重新進入
catch (Exception\InLearningException $e) {
throw $e;
}
}
/**
* 離開標的
*
* @param int $target_id 標的編號
*/
public function toOutTarget($target_id) {
// 活動編號
$saId = $this->id;
$sct = new StudyManager();
// 離開學習點
$sct->toOutTarget($saId, $target_id);
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* StudyManager.php
*/
namespace UElearning\Study;
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
use UElearning\Database;
use UElearning\Exception;
/**
* 學習點進出記錄
*
* 一個物件即代表此學習點進出記錄
*
* @version 2.0.0
* @package UElearning
* @subpackage Study
*/
class StudyManager {
/**
* 取得目前已進入的學習點
* @param string $activity_id 活動編號
* @return string 標的編號若無則null
*/
public function getCurrentInTargetId($activity_id) {
$db = new Database\DBStudy();
return $db->getCurrentInTargetId($activity_id);
}
/**
* 取得目前已進入的學習點的進出紀錄物件
* @param string $activity_id 活動編號
* @return int 進出紀錄編號
*/
public function getCurrentInStudyId($activity_id) {
$db = new Database\DBStudy();
return $db->getCurrentInStudyId($activity_id);
}
/**
* 此標的是否已學習過
*
* @param int $activity_id 活動編號
* @param string $target_id 標的編號
* @return bool 是否已學習過
*/
public function isTargetLearned($activity_id, $target_id) {
$db = new Database\DBStudy();
$query = $db->getAllStudyIdByTargetId($activity_id, $target_id);
if(count($query) > 0) {
return true;
}
else {
return false;
}
}
/**
* 進入標的
*
* @param int $activity_id 活動編號
* @param int $target_id 標的編號
* @param bool $is_entity 是否為現場學習
* return int 進出紀錄編號
*/
public function toInTarget($activity_id, $target_id, $is_entity) {
// 若沒有任一個點正在學習中
if($this->getCurrentInTargetId($activity_id) == null) {
$db = new Database\DBStudy();
return $db->toInTaeget($activity_id, $target_id, $is_entity);
}
else {
throw new Exception\InLearningException();
}
}
/**
* 離開標的
*
* @param int $activity_id 活動編號
* @param int $target_id 標的編號
*/
public function toOutTarget($activity_id, $target_id) {
// 從資料庫取得此活動此標的學習中資料
$db = new Database\DBStudy();
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
if(isset($learning_array)) {
foreach($learning_array as $thisArray) {
$db->toOutTaeget($thisArray['study_id']);
}
}
}
}

View File

@ -96,7 +96,7 @@ class Theme {
/**
* 建構子
*
* @param int $inputTID 主題ID
* @param int $inputID 主題ID
* @since 2.0.0
*/
public function __construct($inputID){

View File

@ -293,6 +293,17 @@ class Target {
return $this->getMj();
}
/**
* 判斷目前標的人數是否為零
*
* @return bool true/此標的目前人數是空的,false/此標的目前人數不是空的
* @since 2.0.0
*/
public function isNumberOfPeopleZero(){
if($this->getCurrentPeople() == 0) return true;
else return false;
}
/**
* 增加學習標的目前人數
*