From cc02589d2d6571a2833d4210acfe6291b53e0cc0 Mon Sep 17 00:00:00 2001 From: kobayashi <3011850@gmail.com> Date: Sat, 3 Jan 2015 05:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90DBRecommand=E9=A1=9E=E5=88=A5?= =?UTF-8?q?=E4=B8=94=E5=B7=B2=E6=B8=AC=E8=A9=A6=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/Database/DBRecommand.php | 63 ++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/htdocs/lib/Database/DBRecommand.php b/htdocs/lib/Database/DBRecommand.php index c2b8003..b01061d 100644 --- a/htdocs/lib/Database/DBRecommand.php +++ b/htdocs/lib/Database/DBRecommand.php @@ -2,12 +2,18 @@ namespace UElearning\Database; -use UElearning\Exception; - +require_once UELEARNING_ROOT.'/config.php'; require_once UELEARNING_LIB_ROOT.'/Database/Database.php'; require_once UELEARNING_LIB_ROOT.'/Database/Exception.php'; +use UElearning\Exception; -class DBRecomamnd extends Database +/** + * 查推薦學習點時所需要的表格資料 + * Usage: + * + */ + +class DBRecommand extends Database { /** @@ -15,14 +21,14 @@ class DBRecomamnd extends Database * @param string $where SQL WHERE子句 * @return array 查詢結果 */ - protected function queryBelongByWhere($where) + 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; - $this->conndb->prepare($sqlString); - $this->conndb->execute(); + $query = $this->connDB->prepare($sqlString); + $query->execute(); - $queryAllResult = $this->conndb->fetchAll(); + $queryAllResult = $query->fetchAll(); if(count($queryAllResult) != 0) { @@ -30,9 +36,9 @@ class DBRecomamnd extends Database foreach ($queryAllResult as $key => $thisResult) { array_push($result, - array("Ti" => $thisResult['Ti'], - "Tj" => $thisResult['Tj'], - "MoveTime" => $thisResult['MoveTime'])); + array("current_point" => $thisResult['Ti'], + "next_point" => $thisResult['Tj'], + "move_time" => $thisResult['MoveTime'])); } return $result; @@ -40,4 +46,41 @@ class DBRecomamnd extends Database else return null; } + protected function queryBelongByWhere($where) + { + $sqlString = "SELECT ".$this->table('tbelong').".Weights FROM ".$this->table('tbelong')." WHERE ".$where; + $query = $this->connDB->prepare($sqlString); + $query->execute(); + + $queryResult = $query->fetchAll(); + + if(count($queryResult) != 0) + { + $result = array(); + foreach ($queryResult as $key => $thisResult) + { + array_push($result, array("weight" => $thisResult['Weights'])); + } + return $result; + } + else return null; + } + + 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); + $AllOfResult = $this->queryBelongByWhere($whereClause); + + if(count($AllOfResult) != 0) return $AllOfResult; + else return null; + } + + + public function queryEdgeByID($currentPoint) + { + $AllOfResult = $this->queryBelongByWhere("Ti = ".$this->connDB->quote($currentPoint)); + if(count($AllOfResult) != 0) return $AllOfResult; + else return null; + } + }