diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 03d37eb..91aa173 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -10,9 +10,11 @@ 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'; use UElearning\User; use UElearning\Study; use UElearning\Target; +use UElearning\Recommand; use UElearning\Exception; $app = new \Slim\Slim(array( @@ -1173,21 +1175,31 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { $currentTId = (int)$currentTId; - // TODO: 動作撰寫區 - - // 取得此活動的主題 - $tid = $sact->getThemeId(); + $tid = $sact->getThemeId(); // 取得此活動的主題 + $maxItemTotal = $sact->getLearnStyle(); // 取得最大推薦數 // 取得本次採用的教材風格 $materialMode = $sact->getMaterialStyle(); - // 取得主題內所有的標的資訊 - $target_manager = new Target\TargetManager(); - $output_targets = array( output_the_target_array(3, true, $materialMode), - output_the_target_array(7, true, $materialMode), - output_the_target_array(12, true, $materialMode), - ); - $recommand_total = count($output_targets); + // 取得推薦的學習點 + $recommand = new Recommand\RecommandPoint(); + $recommandResult = $recommand->recommand($currentTId, $saId); + $recommandTotal = count($recommandResult); + if($recommandTotal > $maxItemTotal) { + $result_recommand_total = $maxItemTotal; + } + else { + $result_recommand_total = $recommandTotal; + } + + + // 製作 + $output_targets = array(); + for($i=0; $i<$result_recommand_total; $i++) { + $target_id = $recommandResult[$i]['nextPoint']; + $isEntity = $recommandResult[$i]['isEntity']; + array_push($output_targets, output_the_target_array($target_id, $isEntity, $materialMode)); + } // 噴出結果 $app->render(200,array( @@ -1195,7 +1207,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'user_id' => $user_id, 'activity_id' => $sact->getId(), 'current_target_id' => $currentTId, - 'recommand_total' => $recommand_total, + 'recommand_total' => $result_recommand_total, 'recommand_target' => $output_targets, 'error' => false )); 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 c4b03cb..fd9eef1 100644 --- a/htdocs/lib/Recommand/RecommandPoint.php +++ b/htdocs/lib/Recommand/RecommandPoint.php @@ -154,7 +154,7 @@ class RecommandPoint { if($nextPoint->isNumberOfPeopleZero()) $Rj = 0; else $Rj = $nextPoint->getMj()/$nextPoint->getPLj(); - $pathCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/$moveTime + $nextPoint->getLearnTime()); + $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, 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(); }