From 1d0695f2234192f726c7e3f2fc5445bd3ea061d7 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 5 Feb 2015 15:23:49 +0800 Subject: [PATCH] add placeinfo and map --- htdocs/api/v2/index.php | 22 +++++++++ htdocs/lib/Database/DBInfo.php | 85 ++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 htdocs/lib/Database/DBInfo.php diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 03d37eb..5931592 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -10,10 +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.'/Database/DBInfo.php'; use UElearning\User; use UElearning\Study; use UElearning\Target; use UElearning\Exception; +use UElearning\Database; $app = new \Slim\Slim(array( 'templates.path' => './', // 設定Path @@ -1239,6 +1241,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; + } + } + +}