diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 0cbfbc3..de36b3b 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -10,12 +10,12 @@ 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'; -require_once UELEARNING_LIB_ROOT.'/Recommand/RecommandPoint.php'; +require_once UELEARNING_LIB_ROOT.'/Database/DBInfo.php'; use UElearning\User; use UElearning\Study; use UElearning\Target; -use UElearning\Recommand; use UElearning\Exception; +use UElearning\Database; $app = new \Slim\Slim(array( 'templates.path' => './', // 設定Path @@ -1033,38 +1033,22 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { // 進入學習點 try{ $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 - )); } // 若狀態為正在標的內學習時,強制當成離開標的,重新進入 catch (Exception\InLearningException $e) { - - // 查詢目前所在的標的 - $inTId = $sact->getCurrentInTarget(); - - // 登記離開此標的 - $sact->toOutTarget($inTId); - - // 重新登記進入此標的 + $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 - )); } + // 噴出結果 + $app->render(200,array( + 'token' => $token, + 'user_id' => $user_id, + 'activity_id' => $sact->getId(), + 'study_id' => $sid, + 'error' => false + )); + } // 若非本人所有,則視同無此活動 else { @@ -1191,8 +1175,8 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { $currentTId = (int)$currentTId; - $tid = $sact->getThemeId(); // 取得此活動的主題 - $maxItemTotal = $sact->getLearnStyle(); // 取得最大推薦數 + // 取得此活動的主題 + $tid = $sact->getThemeId(); // 取得本次採用的教材風格 $materialMode = $sact->getMaterialStyle(); @@ -1229,8 +1213,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'user_id' => $user_id, 'activity_id' => $sact->getId(), 'current_target_id' => $currentTId, - 'is_end' => $isEnd, - 'recommand_total' => $result_recommand_total, + 'recommand_total' => $recommand_total, 'recommand_target' => $output_targets, 'error' => false )); @@ -1274,6 +1257,26 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { // ============================================================================ +/* + * 推薦學習點 + * GET http://localhost/api/v2/info + */ +$app->get('/info', 'APIrequest', function () use ($app) { + + $db = new Database\DBInfo(); + $placeInfoResult = $db->queryAllPlaceInfo(); + $placeMapResult = $db->queryALLPlaceMap(); + + // 噴出結果 + $app->render(200,array( + 'place_info' => $placeInfoResult, + 'place_map' => $placeMapResult, + 'error' => false + )); +}); + +// ============================================================================ + // 取得Client要求的格式 $requestType = $app->request->headers->get('Accept'); // 若要求網頁版 diff --git a/htdocs/lib/Database/DBInfo.php b/htdocs/lib/Database/DBInfo.php new file mode 100644 index 0000000..68b8cd2 --- /dev/null +++ b/htdocs/lib/Database/DBInfo.php @@ -0,0 +1,85 @@ + + * @version 2.0.0 + * @package UElearning + * @subpackage Database + */ +class DBInfo extends Database { + + public function queryAllPlaceInfo() { + $sqlString = "SELECT * FROM `".$this->table('PlaceInfo')."` WHERE 1"; + + $query = $this->connDB->prepare($sqlString); + $query->execute(); + + $queryResultAll = $query->fetchAll(); + +// return $queryResultAll; + + // 如果有查到一筆以上 + if( count($queryResultAll) >= 1 ) { + // 製作回傳結果陣列 + $result = array(); + foreach($queryResultAll as $key => $thisResult) { + + array_push($result, + array( 'id' => $thisResult['IID'], + 'name' => $thisResult['IName'], + 'content' => $thisResult['IContent'] + )); + } + return $result; + } + // 若都沒查到的話 + else { + return null; + } + } + public function queryALLPlaceMap() { + $sqlString = "SELECT * FROM `".$this->table('PlaceMap')."` WHERE 1"; + + $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( 'id' => $thisResult['PID'], + 'name' => $thisResult['PName'], + 'url' => $thisResult['PURL'] + )); + } + return $result; + } + // 若都沒查到的話 + else { + return null; + } + } + +}