Version19.259

This commit is contained in:
acanas 2020-08-22 13:05:15 +02:00
parent 0b26fdd87f
commit 87d987d4a2
5 changed files with 70 additions and 45 deletions

View File

@ -308,7 +308,6 @@ struct swad__getMatchStatusOutput
struct swad__answerMatchQuestionOutput struct swad__answerMatchQuestionOutput
{ {
int matchCode; int matchCode;
int answerIndex;
}; };
/* structs used in getUsers and sendMessage */ /* structs used in getUsers and sendMessage */

View File

@ -5187,7 +5187,7 @@ int swad__getMatchStatus (struct soap *soap,
if (Match.GamCod != Game.GamCod) if (Match.GamCod != Game.GamCod)
return soap_sender_fault (soap, return soap_sender_fault (soap,
"Bad game code", "Bad game code",
"Match code does not belong to game code"); "Match does not belong to game");
/***** Get some of my data *****/ /***** Get some of my data *****/
if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,Gbl.Hierarchy.Crs.CrsCod)) 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 struct swad__answerMatchQuestionOutput *answerMatchQuestionOut) // output
{ {
int ReturnCode; int ReturnCode;
// unsigned QstInd; // 0 means that the game has not started. First question has index 1.
// unsigned NumOpt; // unsigned NumOpt;
struct Gam_Game Game; struct Gam_Game Game;
struct Mch_Match Match; 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 *****/ /***** Reset game and match *****/
Gam_ResetGame (&Game); Gam_ResetGame (&Game);
@ -5283,9 +5284,17 @@ int swad__answerMatchQuestion (struct soap *soap,
API_Set_gSOAP_RuntimeEnv (soap); API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_answerMatchQuestion; Gbl.WebService.Function = API_answerMatchQuestion;
Gbl.Hierarchy.Crs.CrsCod = (long) courseCode; Gbl.Hierarchy.Crs.CrsCod = (long) courseCode;
Game.GamCod = (long) gameCode; Game.GamCod = (long) gameCode;
Match.MchCod = (long) matchCode; 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 *****/ /***** Check web service key *****/
if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK) if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK)
return ReturnCode; return ReturnCode;
@ -5314,27 +5323,28 @@ int swad__answerMatchQuestion (struct soap *soap,
"Match code must be a integer greater than 0"); "Match code must be a integer greater than 0");
Mch_GetDataOfMatchByCod (&Match); Mch_GetDataOfMatchByCod (&Match);
/* Check that match belongs to game */ /***** Check that match belongs to game *****/
if (Match.GamCod != Game.GamCod) if (Match.GamCod != Game.GamCod)
return soap_sender_fault (soap, return soap_sender_fault (soap,
"Bad game code", "Bad game code",
"Match code does not belong to game code"); "Match does not belong to game");
// TODO: Write the code /***** Check question index *****/
if (questionIndex > 0 && numOption > 0) if (questionIndex <= 0)
{ return soap_sender_fault (soap,
// QstInd = (unsigned) questionIndex; "Bad question index",
// NumOpt = (unsigned) numOption; "The question index should be greater than 0");
answerMatchQuestionOut->matchCode = matchCode; QstInd = (unsigned) questionIndex;
answerMatchQuestionOut->answerIndex = 1; // TODO: Return the current answer index
} /***** Check number of option selected by student *****/
else if (numOption < 0)
{ return soap_sender_fault (soap,
// QstInd = 0; "Bad number of option",
// NumOpt = 0; "The number of option should be greater or equal than 0");
answerMatchQuestionOut->matchCode = -1; UsrAnswer.NumOpt = (unsigned) numOption;
answerMatchQuestionOut->answerIndex = -1;
} /***** Store answer *****/
Mch_StoreQuestionAnswer (&Match,QstInd,&UsrAnswer);
return SOAP_OK; return SOAP_OK;
} }

View File

@ -565,7 +565,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf 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 CSS_FILE "swad19.253.css"
#define JS_FILE "swad19.254.js" #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. "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 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.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.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) Version 19.256: Jun 24, 2020 Code refactoring in tests, exams and matches results. (303841 lines)

View File

@ -3932,9 +3932,7 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
void Mch_ReceiveQuestionAnswer (void) void Mch_ReceiveQuestionAnswer (void)
{ {
struct Mch_Match Match; struct Mch_Match Match;
unsigned QstInd; unsigned QstInd; // 0 means that the game has not started. First question has index 1.
unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION];
struct Mch_UsrAnswer PreviousUsrAnswer;
struct Mch_UsrAnswer UsrAnswer; struct Mch_UsrAnswer UsrAnswer;
/***** Reset match *****/ /***** Reset match *****/
@ -3947,14 +3945,36 @@ void Mch_ReceiveQuestionAnswer (void)
/***** Get question index from form *****/ /***** Get question index from form *****/
QstInd = Gam_GetParamQstInd (); 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 /***** Check that teacher's screen is showing answers
and question index is the current one being played *****/ and question index is the current one being played *****/
if (Match.Status.Playing && // Match is being played if (Match->Status.Playing && // Match is being played
Match.Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers
QstInd == Match.Status.QstInd) // Receiving an answer to the current question being played QstInd == Match->Status.QstInd) // Receiving an answer to the current question being played
{ {
/***** Get indexes for this question from database *****/ /***** 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 *****/ /***** Get answer index *****/
/* /*
@ -3969,34 +3989,28 @@ void Mch_ReceiveQuestionAnswer (void)
| c | 2 | 1 | Y | <---- User press button #2 (index = 1, correct) | c | 2 | 1 | Y | <---- User press button #2 (index = 1, correct)
| d | 3 | 2 | | | d | 3 | 2 | |
+--------+--------+----------+---------+ +--------+--------+----------+---------+
UsrAnswer.NumOpt = 2 UsrAnswer->NumOpt = 2
UsrAnswer.AnsInd = 1 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 /***** Get previous student's answer to this question
(<0 ==> no answer) *****/ (<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); &PreviousUsrAnswer);
/***** Store student's answer *****/ /***** Store student's answer *****/
if (UsrAnswer.NumOpt >= 0 && if (UsrAnswer->NumOpt >= 0 &&
UsrAnswer.AnsInd >= 0 && UsrAnswer->AnsInd >= 0 &&
UsrAnswer.AnsInd != PreviousUsrAnswer.AnsInd) UsrAnswer->AnsInd != PreviousUsrAnswer.AnsInd)
{ {
/***** Update my answer to this question *****/ /***** Update my answer to this question *****/
Mch_UpdateMyAnswerToMatchQuestion (&Match,&UsrAnswer); Mch_UpdateMyAnswerToMatchQuestion (Match,UsrAnswer);
/***** Compute score and update my match result *****/ /***** 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 ();
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -145,6 +145,8 @@ void Mch_RefreshMatchStd (void);
void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd, void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
struct Mch_UsrAnswer *UsrAnswer); struct Mch_UsrAnswer *UsrAnswer);
void Mch_ReceiveQuestionAnswer (void); void Mch_ReceiveQuestionAnswer (void);
void Mch_StoreQuestionAnswer (struct Mch_Match *Match,unsigned QstInd,
struct Mch_UsrAnswer *UsrAnswer);
void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print); void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print);