diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index a7b6f12..ac974a2 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -11,6 +11,7 @@ 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'; +require_once UELEARNING_LIB_ROOT.'/Database/DBQuestion.php'; require_once UELEARNING_LIB_ROOT.'/Recommand/RecommandPoint.php'; require_once UELEARNING_LIB_ROOT.'/Log/Log.php'; use UElearning\User; @@ -1108,6 +1109,18 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { */ $app->post('/:token/activitys/:said/points/:tid/toout', function ($token, $saId, $tId) use ($app) { + $app = \Slim\Slim::getInstance(); + + // 取得帶來的參數 + $cType = $app->request->getContentType(); + + if($cType == 'application/json') { + $postData = $app->request->getBody(); + $postDataJson = json_decode($postData); + + $ans_json = $postDataJson->answers; + } + try { // 查詢使用者 $session = new User\UserSession(); @@ -1123,10 +1136,17 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { try { $sact->toOutTarget($tId); + // 紀錄回答問題 + $db_recommend = new Database\DBQuestion(); + foreach($ans_json as $the_ans) { + $db_recommend->insert($saId, $the_ans->target_id, $the_ans->question_time, $the_ans->answer_time, $the_ans->quest_id, $the_ans->answer, $the_ans->correct); + } + // 噴出結果 $app->render(201,array( 'token' => $token, 'user_id' => $user_id, + 'answers' => $ans_json, 'activity_id' => $sact->getId(), 'error' => false )); @@ -1138,6 +1158,21 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { $sact->toInTarget($tId, true); $sact->toOutTarget($tId); + // 紀錄回答問題 + $db_recommend = new Database\DBQuestion(); + foreach($ans_json as $the_ans) { + $db_recommend->insert($saId, $the_ans->target_id, $the_ans->question_time, $the_ans->answer_time, $the_ans->quest_id, $the_ans->answer, $the_ans->correct); + } + + // 噴出結果 + $app->render(201,array( + 'token' => $token, + 'user_id' => $user_id, + 'answers' => $ans_json, + 'activity_id' => $sact->getId(), + 'error' => false + )); + // 噴出結果 $app->render(201,array( 'token' => $token, diff --git a/htdocs/lib/Database/DBQuestion.php b/htdocs/lib/Database/DBQuestion.php new file mode 100644 index 0000000..b5f8e8b --- /dev/null +++ b/htdocs/lib/Database/DBQuestion.php @@ -0,0 +1,35 @@ +table('user_history_question'). + " (`ID`, `SaID`, `TID`, `QDate`, `ADate`, `QID`, `Ans`, `Correct`) + VALUES (NULL, :said , :tid , :qd , :ad , :qid , :ans , :cor )"; + + $query = $this->connDB->prepare($sqlString); + $query->bindParam(":said", $activity_id); + $query->bindParam(":tid", $target_id); + $query->bindParam(":qd", $question_time); + $query->bindParam(":ad", $answer_time); + $query->bindParam(":qid", $question_id); + $query->bindParam(":ans", $answer); + $query->bindParam(":cor", $correct); + $query->execute(); + + } + +}