diff --git a/htdocs/lib/Database/DBRecommand.php b/htdocs/lib/Database/DBRecommand.php index 043a28d..f839f16 100644 --- a/htdocs/lib/Database/DBRecommand.php +++ b/htdocs/lib/Database/DBRecommand.php @@ -89,7 +89,7 @@ class DBRecommand extends Database /** * 以目前的學習點編號查詢下一個學習點的資訊 * @param string $currentPoint 目前的學習點編號 - * @return array 查詢結果 + * @return array */ public function queryEdgeByID($currentPoint) { diff --git a/htdocs/lib/Database/DBStudy.php b/htdocs/lib/Database/DBStudy.php index ad10220..283d231 100644 --- a/htdocs/lib/Database/DBStudy.php +++ b/htdocs/lib/Database/DBStudy.php @@ -266,7 +266,7 @@ class DBStudy extends Database { * @param string $study_id 此記錄編號 * @since 2.0.0 */ - public function toOutTaeget($study_id) + public function toOutTarget($study_id) { // 寫入 @@ -285,7 +285,7 @@ class DBStudy extends Database { * @param string $activity_id 活動編號 * @since 2.0.0 */ - public function allToOutTaeget($activity_id) + public function alltoOutTarget($activity_id) { // 寫入 diff --git a/htdocs/lib/Database/DBTarget.php b/htdocs/lib/Database/DBTarget.php index 0dba41a..405f32b 100644 --- a/htdocs/lib/Database/DBTarget.php +++ b/htdocs/lib/Database/DBTarget.php @@ -51,17 +51,17 @@ class DBTarget extends Database { foreach($queryResultAll as $key => $thisResult) { array_push($result, - array( 'target_id' => $thisResult['TID'], - 'area_id' => $thisResult['AID'], - 'hall_id' => $thisResult['HID'], - 'target_number' => $thisResult['TNum'], + array( 'target_id' => (int)$thisResult['TID'], + 'area_id' => (int)$thisResult['AID'], + 'hall_id' => (int)$thisResult['HID'], + 'target_number' => (int)$thisResult['TNum'], 'name' => $thisResult['TName'], 'map_url' => $thisResult['TMapID'], - 'learn_time' => $thisResult['TLearnTime'], - 'PLj' => $thisResult['PLj'], - 'Mj' => $thisResult['Mj'], - 'S' => $thisResult['S'], - 'Fj' => $thisResult['Fj'] + 'learn_time' => (int)$thisResult['TLearnTime'], + 'PLj' => (int)$thisResult['PLj'], + 'Mj' => (int)$thisResult['Mj'], + 'S' => (int)$thisResult['S'], + 'Fj' => (int)$thisResult['Fj'] )); } return $result; diff --git a/htdocs/lib/Recommand/RecommandPoint.php b/htdocs/lib/Recommand/RecommandPoint.php index df903e5..fd9eef1 100644 --- a/htdocs/lib/Recommand/RecommandPoint.php +++ b/htdocs/lib/Recommand/RecommandPoint.php @@ -1,4 +1,7 @@ recommand->queryEdgeByID('0'); - $theme = new Study\Theme($theme_number); for($i=0;$irecommand->queryBelongByID($next_point,$theme->getId()); + $belong = $this->recommand->queryBelongByID($next_point,$theme_number); $weight = $belong["weight"]; $VirtualSum += $weight / $next_target->getLearnTime(); @@ -76,12 +84,91 @@ class RecommandPoint return $EntitySum/$VirtualSum; } + + /** + * 是否為可以學習的標的 + * @param $target_id 標的編號 + * @return bool enable or not + */ + private function isEnableTargetId($activityObj,$target_id) + { + $target = new Target\Target($target_id); + if(!$activityObj->isTargetLearned($target_id)) return true; + else return false; + } + + /** + * 過濾非法的標的 + * + * @param array $point_list 全部的標的清單 + * @param StudyActivity $activityObj 學習活動物件 + * @return array 合法的學習點 + */ + private function excludeIrregularTarget($point_list,$activityObj) + { + $regularTarget = array(); + for($i=0;$iisEnableTargetId($activityObj,$nextPoint)) { + array_push($regularTarget,$point_list[$i]); + } + } + return $regularTarget; + } + /** * 推薦學習點 + * @param int $current_point 目前的標的編號 + * @param int $theme_number 主題編號 + * @param int activity_number 學習活動編號 * @return array 學習點清單 */ - public function recommand($current_point,$theme_number,$activity_number) + public function recommand($current_point,$activity_number) { + $this->activity = new Study\StudyActivity($activity_number); + $themeID = $this->activity->getThemeId(); + $this->theme = new Study\Theme($themeID); + $this->gamma = $this->computeNormalizationParameter($themeID); + $pointList = $this->recommand->queryEdgeByID($current_point); + $targetList = $this->excludeIrregularTarget($pointList,$this->activity); + //計算路徑的權重值 + $pathCost = 0; + $VirtualPathCost = 0; + $recommand = array(); + $isEntity = true; + for($i=0;$itheme->getWeightByNextTarget($next_point); + if($nextPoint->isFullPeople()) + { + $pastCost = 0; + $virtualCost = RecommandPoint::ALPHA * $this->gamma * ($wright/$nextPoint->getLearnTime()); + $isEntity=false; + } + else + { + if($nextPoint->isNumberOfPeopleZero()) $Rj = 0; + else $Rj = $nextPoint->getMj()/$nextPoint->getPLj(); + $pathCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/($moveTime + $nextPoint->getLearnTime())); + $virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime()); + } + array_push($recommand,array("nextPoint"=>$next_point, + "isEntity" => $isEntity, + "PathCost"=>$pathCost, + "VirtualCost"=>$virtualCost)); + } + + foreach($recommand as $key=>$value) + { + $tmp[$key] = $value["PathCost"]; + } + array_multisort($tmp,SORT_DESC,$recommand,SORT_DESC); + + return $recommand; } } diff --git a/htdocs/lib/Recommand/here b/htdocs/lib/Recommand/here deleted file mode 100644 index e69de29..0000000 diff --git a/htdocs/lib/Study/Study.php b/htdocs/lib/Study/Study.php index 25405f2..34cceff 100644 --- a/htdocs/lib/Study/Study.php +++ b/htdocs/lib/Study/Study.php @@ -7,7 +7,9 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Target.php'; use UElearning\Database; +use UElearning\Target; use UElearning\Exception; /** @@ -173,7 +175,15 @@ class Study { * @since 2.0.0 */ public function toOut() { + + // 將資料庫內容標示已離開 $db = new Database\DBStudy(); - $db->toOutTaeget($this->id); + $db->toOutTarget($this->id); + + // 將標的目前人數-1 + if($this->isEntity()) { + $target = new Target\Target($this->getTargetId); + $target->addMj(-1); + } } } diff --git a/htdocs/lib/Study/StudyActivity.php b/htdocs/lib/Study/StudyActivity.php index 86d7f47..de99a18 100644 --- a/htdocs/lib/Study/StudyActivity.php +++ b/htdocs/lib/Study/StudyActivity.php @@ -438,6 +438,20 @@ class StudyActivity { // ======================================================================== + /** + * 取得目前已進入的學習點 + * + * @return int 標的編號,若無則null + */ + public function getCurrentInTarget() { + + // 活動編號 + $saId = $this->id; + + $sct = new StudyManager(); + return $sct->getCurrentInTargetId($saId); + } + /** * 此標的是否已學習過 * diff --git a/htdocs/lib/Study/StudyManager.php b/htdocs/lib/Study/StudyManager.php index a1051c1..dd12778 100644 --- a/htdocs/lib/Study/StudyManager.php +++ b/htdocs/lib/Study/StudyManager.php @@ -7,7 +7,10 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Target.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Exception.php'; use UElearning\Database; +use UElearning\Target; use UElearning\Exception; /** @@ -68,14 +71,24 @@ class StudyManager { * @param int $activity_id 活動編號 * @param int $target_id 標的編號 * @param bool $is_entity 是否為現場學習 + * @throw UElearning\Exception\TargetNoFoundException * return int 進出紀錄編號 */ public function toInTarget($activity_id, $target_id, $is_entity) { // 若沒有任一個點正在學習中 if($this->getCurrentInTargetId($activity_id) == null) { + // 紀錄進資料庫 $db = new Database\DBStudy(); - return $db->toInTaeget($activity_id, $target_id, $is_entity); + $id = $db->toInTaeget($activity_id, $target_id, $is_entity); + + // 將標的目前人數+1 + if($is_entity) { + $target = new Target\Target($target_id); + $target->addMj(1); + } + + return $id; } else { throw new Exception\InLearningException(); @@ -93,12 +106,22 @@ class StudyManager { // 從資料庫取得此活動此標的學習中資料 $db = new Database\DBStudy(); $learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id); + $target = new Target\Target($target_id); + // 找到正在學習中的資料 if(isset($learning_array)) { + // 將所有此標的的進入紀錄全部標示 foreach($learning_array as $thisArray) { - $db->toOutTaeget($thisArray['study_id']); + // 將此紀錄標示為已離開 + $db->toOutTarget($thisArray['study_id']); + + // 將標的目前人數-1 + if($thisArray['is_entity'] = true) { + $target = new Target\Target($target_id); + $target->addMj(-1); + } } } } diff --git a/htdocs/lib/Study/Theme.php b/htdocs/lib/Study/Theme.php index d4213fe..cb68b44 100644 --- a/htdocs/lib/Study/Theme.php +++ b/htdocs/lib/Study/Theme.php @@ -6,6 +6,7 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php'; +require_once UELEARNING_LIB_ROOT.'/Database/DBRecommand.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; use UElearning\Database; use UElearning\Exception; @@ -176,4 +177,16 @@ class Theme { return $this->queryResultArray['modify_time']; } + /** + * 取得下一個標的所屬主題的權重 + * @param string $next_point + * @return int weight 權重 + * @since 2.0.0 + */ + public function getWeightByNextTarget($next_point){ + $belong = new Database\DBRecommand(); + $weight = $belong->queryBelongByID($next_point,$this->id); + return $weight['weight']; + } + } diff --git a/htdocs/lib/Target/Target.php b/htdocs/lib/Target/Target.php index f9ceb9c..7c72a88 100644 --- a/htdocs/lib/Target/Target.php +++ b/htdocs/lib/Target/Target.php @@ -105,7 +105,7 @@ class Target { * @since 2.0.0 */ public function __construct($inputTID){ - $this->tId = $inputTID; + $this->tId = (int)$inputTID; $this->getQuery(); }