新增離開學習點時會回傳給伺服端回答問題狀態

This commit is contained in:
Yuan Chiu 2016-05-03 05:22:37 +08:00
parent 8620db35bc
commit 8845d3509f
2 changed files with 70 additions and 0 deletions

View File

@ -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/Target.php';
require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php'; require_once UELEARNING_LIB_ROOT.'/Target/TargetManager.php';
require_once UELEARNING_LIB_ROOT.'/Database/DBInfo.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.'/Recommand/RecommandPoint.php';
require_once UELEARNING_LIB_ROOT.'/Log/Log.php'; require_once UELEARNING_LIB_ROOT.'/Log/Log.php';
use UElearning\User; 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->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 { try {
// 查詢使用者 // 查詢使用者
$session = new User\UserSession(); $session = new User\UserSession();
@ -1123,10 +1136,17 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
try { try {
$sact->toOutTarget($tId); $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( $app->render(201,array(
'token' => $token, 'token' => $token,
'user_id' => $user_id, 'user_id' => $user_id,
'answers' => $ans_json,
'activity_id' => $sact->getId(), 'activity_id' => $sact->getId(),
'error' => false 'error' => false
)); ));
@ -1138,6 +1158,21 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
$sact->toInTarget($tId, true); $sact->toInTarget($tId, true);
$sact->toOutTarget($tId); $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( $app->render(201,array(
'token' => $token, 'token' => $token,

View File

@ -0,0 +1,35 @@
<?php
/**
* DBQuestion.php
*
*/
namespace UElearning\Database;
use UElearning\Exception;
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
class DBQuestion extends Database {
public function insert($activity_id, $target_id, $question_time, $answer_time, $question_id, $answer, $correct){
$sqlString = "INSERT INTO ".$this->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();
}
}