diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index f35299e..03d37eb 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -504,8 +504,50 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { // 取得開始後的學習活動資訊 $sact = new Study\StudyActivity($studyId); + // 取得此活動的主題 + $tid = $sact->getThemeId(); - // 噴出資訊 + // 取得主題內所有的標的資訊 + $target_manager = new Target\TargetManager(); + $all_targets = $target_manager->getAllTargetInfoByTheme($tid); + + // 取得本次採用的教材風格 + $materialMode = $sact->getMaterialStyle(); + + // 處理噴出結果 + $output_targets = array(); + foreach($all_targets as $thisTargetArray) { + + // 取得教材路徑 + $targetObject = new Target\Target($thisTargetArray['target_id']); + $materialUrl = $targetObject->getMaterialUrl(true, $materialMode); + $virtualMaterialUrl = $targetObject->getMaterialUrl(false, $materialMode); + + $thisOutput = array( + 'theme_id' => $thisTargetArray['theme_id'], + 'target_id' => $thisTargetArray['target_id'], + 'weights' => $thisTargetArray['weights'], + 'hall_id' => $thisTargetArray['hall_id'], + 'hall_name' => $thisTargetArray['hall_name'], + 'area_id' => $thisTargetArray['area_id'], + 'area_name' => $thisTargetArray['area_name'], + 'floor' => $thisTargetArray['floor'], + 'area_number' => $thisTargetArray['area_number'], + 'target_number' => $thisTargetArray['target_number'], + 'name' => $thisTargetArray['name'], + 'map_url' => $thisTargetArray['map_url'], + 'material_url' => $materialUrl, + 'virtual_material_url' => $virtualMaterialUrl, + 'learn_time' => $thisTargetArray['learn_time'], + 'PLj' => $thisTargetArray['PLj'], + 'Mj' => $thisTargetArray['Mj'], + 'S' => $thisTargetArray['S'], + 'Fj' => $thisTargetArray['Fj'] + ); + array_push($output_targets, $thisOutput); + } + + // 噴出結果 $app->render(200,array( 'token' => $token, 'user_id' => $user_id, @@ -514,6 +556,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'activity_id' => $sact->getId(), 'theme_id' => $sact->getThemeId(), 'theme_name' => $sact->getThemeName(), + 'start_target_id' => $sact->getStartTargetId(), 'start_time' => $sact->getStartTime(), 'expired_time' => $sact->getExpiredTime(), 'have_time' => $sact->getRealLearnTime(), @@ -528,6 +571,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'target_total' => $sact->getPointTotal(), 'learned_total' => $sact->getLearnedPointTotal() ), + 'targets' => $output_targets, 'error' => false )); } @@ -565,9 +609,54 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { // 取得開始後的學習活動資訊 $sact = new Study\StudyActivity($saId); + // TODO: 取得主題內所有的標的資訊 + // 確認此學習活動是否為本人所有 if($sact->getUserId() == $user_id) { + // 取得此活動的主題 + $tid = $sact->getThemeId(); + + // 取得主題內所有的標的資訊 + $target_manager = new Target\TargetManager(); + $all_targets = $target_manager->getAllTargetInfoByTheme($tid); + + // 取得本次採用的教材風格 + $materialMode = $sact->getMaterialStyle(); + + // 處理噴出結果 + $output_targets = array(); + foreach($all_targets as $thisTargetArray) { + + // 取得教材路徑 + $targetObject = new Target\Target($thisTargetArray['target_id']); + $materialUrl = $targetObject->getMaterialUrl(true, $materialMode); + $virtualMaterialUrl = $targetObject->getMaterialUrl(false, $materialMode); + + $thisOutput = array( + 'theme_id' => $thisTargetArray['theme_id'], + 'target_id' => $thisTargetArray['target_id'], + 'weights' => $thisTargetArray['weights'], + 'hall_id' => $thisTargetArray['hall_id'], + 'hall_name' => $thisTargetArray['hall_name'], + 'area_id' => $thisTargetArray['area_id'], + 'area_name' => $thisTargetArray['area_name'], + 'floor' => $thisTargetArray['floor'], + 'area_number' => $thisTargetArray['area_number'], + 'target_number' => $thisTargetArray['target_number'], + 'name' => $thisTargetArray['name'], + 'map_url' => $thisTargetArray['map_url'], + 'material_url' => $materialUrl, + 'virtual_material_url' => $virtualMaterialUrl, + 'learn_time' => $thisTargetArray['learn_time'], + 'PLj' => $thisTargetArray['PLj'], + 'Mj' => $thisTargetArray['Mj'], + 'S' => $thisTargetArray['S'], + 'Fj' => $thisTargetArray['Fj'] + ); + array_push($output_targets, $thisOutput); + } + // 噴出資訊 $app->render(200,array( 'token' => $token, @@ -577,6 +666,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'activity_id' => $sact->getId(), 'theme_id' => $sact->getThemeId(), 'theme_name' => $sact->getThemeName(), + 'start_target_id' => $sact->getStartTargetId(), 'start_time' => $sact->getStartTime(), 'expired_time' => $sact->getExpiredTime(), 'have_time' => $sact->getRealLearnTime(), @@ -591,6 +681,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'target_total' => $sact->getPointTotal(), 'learned_total' => $sact->getLearnedPointTotal() ), + 'targets' => $output_targets, 'error' => false )); } @@ -1037,6 +1128,113 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { } }); + + /* + * 推薦學習點 + * GET http://localhost/api/v2/tokens/{登入Token}/activitys/{學習中活動編號}/recommand?current_point={目前所在的學習點編號} + */ + $app->get('/:token/activitys/:said/recommand', function ($token, $saId) use ($app) { + if(isset($_GET['current_point'])) { $currentTId = $_GET['current_point']; } + + function output_the_target_array($tId, $isEntity, $materialMode) { + $thisOutput = array(); + $target = new Target\Target($tId); + $thisOutput = array( + 'target_id' => $target->getId(), + 'is_entity' => $isEntity, + 'hall_id' => $target->getHallId(), + 'area_id' => $target->getAreaId(), + 'target_number' => $target->getNumber(), + 'name' => $target->getName(), + 'map_url' => $target->getMapUrl(), + 'material_url' => $target->getMaterialUrl($isEntity, $materialMode), + 'learn_time' => $target->getLearnTime(), + 'PLj' => $target->getPLj(), + 'Mj' => $target->getMj(), + 'S' => $target->getS(), + 'Fj' => $target->getFj() + ); + return $thisOutput; + } + + try { + // 查詢使用者 + $session = new User\UserSession(); + $user_id = $session->getUserId($token); + + // 取得開始後的學習活動資訊 + $sact = new Study\StudyActivity($saId); + + // 確認此學習活動是否為本人所有 + if($sact->getUserId() == $user_id) { + + // 必填參數有填 + if( isset($currentTId) ) { + + $currentTId = (int)$currentTId; + + // TODO: 動作撰寫區 + + // 取得此活動的主題 + $tid = $sact->getThemeId(); + + // 取得本次採用的教材風格 + $materialMode = $sact->getMaterialStyle(); + + // 取得主題內所有的標的資訊 + $target_manager = new Target\TargetManager(); + $output_targets = array( output_the_target_array(3, true, $materialMode), + output_the_target_array(7, true, $materialMode), + output_the_target_array(12, true, $materialMode), + ); + $recommand_total = count($output_targets); + + // 噴出結果 + $app->render(200,array( + 'token' => $token, + 'user_id' => $user_id, + 'activity_id' => $sact->getId(), + 'current_target_id' => $currentTId, + 'recommand_total' => $recommand_total, + 'recommand_target' => $output_targets, + 'error' => false + )); + + } + else { + $app->render(400,array( + 'token' => $token, + 'error' => true, + 'msg' => 'No input \'current_point\' param.', + 'msg_cht' => '缺少 \'current_point\' 參數' + )); + } + + } + // 若非本人所有,則視同無此活動 + 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' => '沒有此學習活動' + )); + } + }); }); // ============================================================================ diff --git a/htdocs/lib/Database/DBTheme.php b/htdocs/lib/Database/DBTheme.php index 1714767..256f460 100644 --- a/htdocs/lib/Database/DBTheme.php +++ b/htdocs/lib/Database/DBTheme.php @@ -28,7 +28,7 @@ class DBTheme extends Database { protected function queryThemeByWhere($where) { $sqlString = "SELECT `ThID`, `ThName`, ". - "`ThLearnTime`, `ThIntroduction`, ". + "`ThLearnTime`, `StartTID`, `ThIntroduction`, ". "`ThBuildTime`, `ThModifyTime`, ". "(SELECT count(`TID`) FROM `chu__TBelong` AS `belong` WHERE `belong`.`ThID` = `theme`.`ThID`) AS `TargetTotal`". @@ -46,13 +46,14 @@ class DBTheme extends Database { 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'] ) + array( 'theme_id' => $thisResult['ThID'], + 'name' => $thisResult['ThName'], + 'learn_time' => $thisResult['ThLearnTime'], + 'start_target_id' => $thisResult['StartTID'], + 'introduction' => $thisResult['ThIntroduction'], + 'target_total' => $thisResult['TargetTotal'], + 'build_time' => $thisResult['ThBuildTime'], + 'modify_time' => $thisResult['ThModifyTime'] ) ); } return $result; diff --git a/htdocs/lib/Study/StudyActivity.php b/htdocs/lib/Study/StudyActivity.php index d4effd3..86d7f47 100644 --- a/htdocs/lib/Study/StudyActivity.php +++ b/htdocs/lib/Study/StudyActivity.php @@ -425,6 +425,19 @@ class StudyActivity { // ======================================================================== + /** + * 取得此主題的標的起始點 + * + * @return int 標的編號 + * @since 2.0.0 + */ + public function getStartTargetId(){ + $theme = new Theme( $this->getThemeId() ); + return $theme->getStartTargetId(); + } + + // ======================================================================== + /** * 此標的是否已學習過 * diff --git a/htdocs/lib/Study/Theme.php b/htdocs/lib/Study/Theme.php index a03e734..cb68b44 100644 --- a/htdocs/lib/Study/Theme.php +++ b/htdocs/lib/Study/Theme.php @@ -147,6 +147,16 @@ class Theme { return $this->queryResultArray['learn_time']; } + /** + * 取得此主題的標的起始點 + * + * @return int 標的編號 + * @since 2.0.0 + */ + public function getStartTargetId(){ + return (int)$this->queryResultArray['start_target_id']; + } + /** * 取得建立時間 * diff --git a/htdocs/lib/Target/Target.php b/htdocs/lib/Target/Target.php index af82b26..f9ceb9c 100644 --- a/htdocs/lib/Target/Target.php +++ b/htdocs/lib/Target/Target.php @@ -198,20 +198,23 @@ class Target { $db = new Database\DBMaterial(); $query = $db->queryAllMaterialByTargetId($this->tId); - foreach($query as $thisData) { + if(count($query) > 0) { - if($thisData['is_entity'] != 0) { - $thisEntiry = true; - } - else { $thisEntiry = false; } + foreach($query as $thisData) { + if($thisData['is_entity'] != 0) { + $thisEntiry = true; + } + else { $thisEntiry = false; } - if($thisEntiry==$isEntity && $thisData['mode'] == $mode) { - return $thisData['url']; - break; + if($thisEntiry==$isEntity && $thisData['mode'] == $mode) { + return $thisData['url']; + break; + } } } - - return null; + else { + return null; + } } // ======================================================================== diff --git a/sql/UElearning.sql b/sql/UElearning.sql index 4744aa9..7f7652c 100644 --- a/sql/UElearning.sql +++ b/sql/UElearning.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- 主機: localhost --- 產生時間: 2015 年 01 月 06 日 12:56 +-- 產生時間: 2015 年 01 月 19 日 15:32 -- 伺服器版本: 5.6.16 -- PHP 版本: 5.5.9 @@ -547,7 +547,7 @@ CREATE TABLE IF NOT EXISTS `chu__Target` ( -- INSERT INTO `chu__Target` (`TID`, `AID`, `TNum`, `TName`, `TMapID`, `TLearnTime`, `PLj`, `Mj`, `S`) VALUES -(0, NULL, NULL, '入口', NULL, 0, 100000, 0, NULL), +(0, 1, NULL, '入口', '1F.gif', 0, 1000000000, 0, NULL), (1, 1, NULL, '含有生物遺跡的岩石', 'map_01_02_03.png', 7, 2, 0, 1), (2, 1, NULL, '岩石中的紀錄', 'map_01_02_03.png', 8, 2, 0, 1), (3, 4, NULL, '生命在水中的演化', 'map_01_02_03.png', 3, 2, 0, 1), @@ -583,6 +583,7 @@ CREATE TABLE IF NOT EXISTS `chu__TBelong` ( -- INSERT INTO `chu__TBelong` (`ThID`, `TID`, `Weights`) VALUES +(1, 0, 0), (1, 1, 1), (1, 2, 2), (1, 3, 4), @@ -609,18 +610,19 @@ CREATE TABLE IF NOT EXISTS `chu__Theme` ( `ThID` int(10) unsigned NOT NULL AUTO_INCREMENT, `ThName` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '主題名稱', `ThLearnTime` int(4) NOT NULL COMMENT '學習此主題要花的總時間(m)', + `StartTID` int(10) NOT NULL COMMENT '此主題的標的起始點', `ThIntroduction` tinytext COLLATE utf8_unicode_ci COMMENT '介紹', `ThBuildTime` datetime NOT NULL, `ThModifyTime` datetime NOT NULL, PRIMARY KEY (`ThID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='主題' AUTO_INCREMENT=3 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='主題' AUTO_INCREMENT=2 ; -- -- 資料表的匯出資料 `chu__Theme` -- -INSERT INTO `chu__Theme` (`ThID`, `ThName`, `ThLearnTime`, `ThIntroduction`, `ThBuildTime`, `ThModifyTime`) VALUES -(1, '生命科學', 40, NULL, '2014-10-23 17:21:03', '2014-10-23 17:21:03'); +INSERT INTO `chu__Theme` (`ThID`, `ThName`, `ThLearnTime`, `StartTID`, `ThIntroduction`, `ThBuildTime`, `ThModifyTime`) VALUES +(1, '生命科學', 40, 0, NULL, '2014-10-23 17:21:03', '2014-10-23 17:21:03'); -- --------------------------------------------------------