完成DBRecommand類別且已測試完成

This commit is contained in:
kobayashi 2015-01-03 05:35:39 +08:00
parent 5d5c2d786c
commit cc02589d2d

View File

@ -2,12 +2,18 @@
namespace UElearning\Database; 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/Database.php';
require_once UELEARNING_LIB_ROOT.'/Database/Exception.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子句 * @param string $where SQL WHERE子句
* @return array 查詢結果 * @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". $sqlString = "SELECT DISTINCT ".$this->table('Edge').".Ti, ".$this->table('Edge').".Tj, ".$this->table('Edge').".MoveTime".
" FROM ".$this->table('Edge')." WHERE ".$where; " FROM ".$this->table('Edge')." WHERE ".$where;
$this->conndb->prepare($sqlString); $query = $this->connDB->prepare($sqlString);
$this->conndb->execute(); $query->execute();
$queryAllResult = $this->conndb->fetchAll(); $queryAllResult = $query->fetchAll();
if(count($queryAllResult) != 0) if(count($queryAllResult) != 0)
{ {
@ -30,9 +36,9 @@ class DBRecomamnd extends Database
foreach ($queryAllResult as $key => $thisResult) foreach ($queryAllResult as $key => $thisResult)
{ {
array_push($result, array_push($result,
array("Ti" => $thisResult['Ti'], array("current_point" => $thisResult['Ti'],
"Tj" => $thisResult['Tj'], "next_point" => $thisResult['Tj'],
"MoveTime" => $thisResult['MoveTime'])); "move_time" => $thisResult['MoveTime']));
} }
return $result; return $result;
@ -40,4 +46,41 @@ class DBRecomamnd extends Database
else return null; 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;
}
} }