diff --git a/soap/swad_web_service.h b/soap/swad_web_service.h index 27355e8cd..a0ac7e779 100644 --- a/soap/swad_web_service.h +++ b/soap/swad_web_service.h @@ -308,7 +308,6 @@ struct swad__getMatchStatusOutput struct swad__answerMatchQuestionOutput { int matchCode; - int answerIndex; }; /* structs used in getUsers and sendMessage */ diff --git a/swad_API.c b/swad_API.c index 9920953f8..7ad9e6054 100644 --- a/swad_API.c +++ b/swad_API.c @@ -5187,7 +5187,7 @@ int swad__getMatchStatus (struct soap *soap, if (Match.GamCod != Game.GamCod) return soap_sender_fault (soap, "Bad game code", - "Match code does not belong to game code"); + "Match does not belong to game"); /***** Get some of my data *****/ if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,Gbl.Hierarchy.Crs.CrsCod)) @@ -5270,10 +5270,11 @@ int swad__answerMatchQuestion (struct soap *soap, struct swad__answerMatchQuestionOutput *answerMatchQuestionOut) // output { int ReturnCode; - // unsigned QstInd; // 0 means that the game has not started. First question has index 1. // unsigned NumOpt; struct Gam_Game Game; struct Mch_Match Match; + unsigned QstInd; // 0 means that the game has not started. First question has index 1. + struct Mch_UsrAnswer UsrAnswer; /***** Reset game and match *****/ Gam_ResetGame (&Game); @@ -5283,9 +5284,17 @@ int swad__answerMatchQuestion (struct soap *soap, API_Set_gSOAP_RuntimeEnv (soap); Gbl.WebService.Function = API_answerMatchQuestion; Gbl.Hierarchy.Crs.CrsCod = (long) courseCode; - Game.GamCod = (long) gameCode; + Game.GamCod = (long) gameCode; Match.MchCod = (long) matchCode; + /***** Set default output *****/ + /* + > 0 if the answer was saved + = 0 if the answer was not saved because the match is in pause or in another question + < 0 on error + */ + answerMatchQuestionOut->matchCode = -1; + /***** Check web service key *****/ if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK) return ReturnCode; @@ -5314,27 +5323,28 @@ int swad__answerMatchQuestion (struct soap *soap, "Match code must be a integer greater than 0"); Mch_GetDataOfMatchByCod (&Match); - /* Check that match belongs to game */ + /***** Check that match belongs to game *****/ if (Match.GamCod != Game.GamCod) return soap_sender_fault (soap, "Bad game code", - "Match code does not belong to game code"); + "Match does not belong to game"); - // TODO: Write the code - if (questionIndex > 0 && numOption > 0) - { - // QstInd = (unsigned) questionIndex; - // NumOpt = (unsigned) numOption; - answerMatchQuestionOut->matchCode = matchCode; - answerMatchQuestionOut->answerIndex = 1; // TODO: Return the current answer index - } - else - { - // QstInd = 0; - // NumOpt = 0; - answerMatchQuestionOut->matchCode = -1; - answerMatchQuestionOut->answerIndex = -1; - } + /***** Check question index *****/ + if (questionIndex <= 0) + return soap_sender_fault (soap, + "Bad question index", + "The question index should be greater than 0"); + QstInd = (unsigned) questionIndex; + + /***** Check number of option selected by student *****/ + if (numOption < 0) + return soap_sender_fault (soap, + "Bad number of option", + "The number of option should be greater or equal than 0"); + UsrAnswer.NumOpt = (unsigned) numOption; + + /***** Store answer *****/ + Mch_StoreQuestionAnswer (&Match,QstInd,&UsrAnswer); return SOAP_OK; } diff --git a/swad_changelog.h b/swad_changelog.h index a21c7d058..eafeb9c32 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -565,7 +565,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.258 (2020-08-11)" +#define Log_PLATFORM_VERSION "SWAD 19.259 (2020-08-22)" #define CSS_FILE "swad19.253.css" #define JS_FILE "swad19.254.js" /* @@ -582,8 +582,8 @@ TODO: Create module swad_test_result "sudo apt install webp" en Ubuntu, y "yum install libwebp libwebp-tools" en CentOS, para decodificar imágenes Web/ug reportado por Javier Fernández Baldomero. TODO: Escribir la función getAvailableRoles -TODO: Escribir correctamente la función swad__answerMatchQuestion + Version 19.259: Aug 22, 2020 Changes in API function answerMatchQuestion. (303969 lines) Version 19.258: Aug 11, 2020 Changes in API functions related to games and matches. (303951 lines) Version 19.257: Jun 24, 2020 New module swad_match_print. (303887 lines) Version 19.256: Jun 24, 2020 Code refactoring in tests, exams and matches results. (303841 lines) diff --git a/swad_match.c b/swad_match.c index 53fdac5b0..994980b7a 100644 --- a/swad_match.c +++ b/swad_match.c @@ -3932,9 +3932,7 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd, void Mch_ReceiveQuestionAnswer (void) { struct Mch_Match Match; - unsigned QstInd; - unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; - struct Mch_UsrAnswer PreviousUsrAnswer; + unsigned QstInd; // 0 means that the game has not started. First question has index 1. struct Mch_UsrAnswer UsrAnswer; /***** Reset match *****/ @@ -3947,14 +3945,36 @@ void Mch_ReceiveQuestionAnswer (void) /***** Get question index from form *****/ QstInd = Gam_GetParamQstInd (); + /***** Get number of option selected by student from form *****/ + UsrAnswer.NumOpt = Mch_GetParamNumOpt (); + + /***** Store answer *****/ + Mch_StoreQuestionAnswer (&Match,QstInd,&UsrAnswer); + + /***** Show current match status *****/ + HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\""); + Mch_ShowMatchStatusForStd (&Match,Mch_CHANGE_STATUS_BY_STUDENT); + HTM_DIV_End (); + } + +/*****************************************************************************/ +/********** Store question answer from student when playing a match **********/ +/*****************************************************************************/ + +void Mch_StoreQuestionAnswer (struct Mch_Match *Match,unsigned QstInd, + struct Mch_UsrAnswer *UsrAnswer) + { + unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; + struct Mch_UsrAnswer PreviousUsrAnswer; + /***** Check that teacher's screen is showing answers and question index is the current one being played *****/ - if (Match.Status.Playing && // Match is being played - Match.Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers - QstInd == Match.Status.QstInd) // Receiving an answer to the current question being played + if (Match->Status.Playing && // Match is being played + Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers + QstInd == Match->Status.QstInd) // Receiving an answer to the current question being played { /***** Get indexes for this question from database *****/ - Mch_GetIndexes (Match.MchCod,Match.Status.QstInd,Indexes); + Mch_GetIndexes (Match->MchCod,Match->Status.QstInd,Indexes); /***** Get answer index *****/ /* @@ -3969,34 +3989,28 @@ void Mch_ReceiveQuestionAnswer (void) | c | 2 | 1 | Y | <---- User press button #2 (index = 1, correct) | d | 3 | 2 | | +--------+--------+----------+---------+ - UsrAnswer.NumOpt = 2 - UsrAnswer.AnsInd = 1 + UsrAnswer->NumOpt = 2 + UsrAnswer->AnsInd = 1 */ - UsrAnswer.NumOpt = Mch_GetParamNumOpt (); - UsrAnswer.AnsInd = Indexes[UsrAnswer.NumOpt]; + UsrAnswer->AnsInd = Indexes[UsrAnswer->NumOpt]; /***** Get previous student's answer to this question (<0 ==> no answer) *****/ - Mch_GetQstAnsFromDB (Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod,Match.Status.QstInd, + Mch_GetQstAnsFromDB (Match->MchCod,Gbl.Usrs.Me.UsrDat.UsrCod,Match->Status.QstInd, &PreviousUsrAnswer); /***** Store student's answer *****/ - if (UsrAnswer.NumOpt >= 0 && - UsrAnswer.AnsInd >= 0 && - UsrAnswer.AnsInd != PreviousUsrAnswer.AnsInd) + if (UsrAnswer->NumOpt >= 0 && + UsrAnswer->AnsInd >= 0 && + UsrAnswer->AnsInd != PreviousUsrAnswer.AnsInd) { /***** Update my answer to this question *****/ - Mch_UpdateMyAnswerToMatchQuestion (&Match,&UsrAnswer); + Mch_UpdateMyAnswerToMatchQuestion (Match,UsrAnswer); /***** Compute score and update my match result *****/ - MchPrn_ComputeScoreAndUpdateMyMatchPrintInDB (Match.MchCod); + MchPrn_ComputeScoreAndUpdateMyMatchPrintInDB (Match->MchCod); } } - - /***** Show current match status *****/ - HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\""); - Mch_ShowMatchStatusForStd (&Match,Mch_CHANGE_STATUS_BY_STUDENT); - HTM_DIV_End (); } /*****************************************************************************/ diff --git a/swad_match.h b/swad_match.h index 374f951dc..f76aa6228 100644 --- a/swad_match.h +++ b/swad_match.h @@ -145,6 +145,8 @@ void Mch_RefreshMatchStd (void); void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd, struct Mch_UsrAnswer *UsrAnswer); void Mch_ReceiveQuestionAnswer (void); +void Mch_StoreQuestionAnswer (struct Mch_Match *Match,unsigned QstInd, + struct Mch_UsrAnswer *UsrAnswer); void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print);