From cfde9b3ae9573e11dd05c2d46a116822dfc532f5 Mon Sep 17 00:00:00 2001 From: acanas Date: Fri, 28 Aug 2020 14:45:30 +0200 Subject: [PATCH] Version19.260.2 --- swad_API.c | 49 +++++++++++++++++++++++------------------------- swad_changelog.h | 3 ++- swad_match.c | 13 ++++++------- swad_match.h | 4 ---- swad_test.c | 14 -------------- swad_test.h | 1 - 6 files changed, 31 insertions(+), 53 deletions(-) diff --git a/swad_API.c b/swad_API.c index 1efaec6ac..3a6e3648c 100644 --- a/swad_API.c +++ b/swad_API.c @@ -5186,7 +5186,6 @@ int swad__getMatchStatus (struct soap *soap, struct Gam_Game Game; struct Mch_Match Match; bool ICanPlayThisMatchBasedOnGrps; - unsigned NumOptions; struct Mch_UsrAnswer UsrAnswer; /***** Reset game and match *****/ @@ -5261,40 +5260,38 @@ int swad__getMatchStatus (struct soap *soap, "Request forbidden", "Requester can not join this match"); - /***** Check question *****/ - if (!Tst_CheckIfQuestionIsValidForGame (Match.Status.QstCod)) - return soap_receiver_fault (soap, - "Wrong question", - "Type of answer not valid in a game."); - - /***** Join match *****/ + /***** Set default match code *****/ getMatchStatusOut->matchCode = 0; // == 0 ==> wait + + /***** Set index of question inside the game *****/ + getMatchStatusOut->questionIndex = (int) Match.Status.QstInd; + if (Match.Status.Playing && // Match is being played Match.Status.Showing != Mch_END) // Unfinished + /***** Join match *****/ /* Update players */ if (Mch_RegisterMeAsPlayerInMatch (&Match)) if (Match.Status.Showing == Mch_ANSWERS) // Showing the question stem and the answers getMatchStatusOut->matchCode = (int) Match.MchCod; // > 0 ==> student is allowed to answer the question - /***** Set index of question inside the game *****/ - getMatchStatusOut->questionIndex = (int) Match.Status.QstInd; - - /***** Set number of answers (options) in question *****/ - NumOptions = Tst_GetNumAnswersQst (Match.Status.QstCod); - getMatchStatusOut->numAnswers = (int) NumOptions; - - /***** Set number of selected answer *****/ - if (NumOptions == 0) - getMatchStatusOut->answerIndex = -1; - else // Answers found + /***** Set number of answers (options) in question and student's answer (<0 ==> no answer) *****/ + switch (Match.Status.Showing) { - /***** Get student's answer to this question - (<0 ==> no answer) *****/ - Mch_GetQstAnsFromDB (Match.MchCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - Match.Status.QstInd, - &UsrAnswer); - getMatchStatusOut->answerIndex = UsrAnswer.NumOpt; + case Mch_START: // Start: don't show anything + case Mch_END: // End: don't show anything + getMatchStatusOut->numAnswers = 0; + getMatchStatusOut->answerIndex = -1; + break; + case Mch_STEM: // Showing only the question stem + case Mch_ANSWERS: // Showing the question stem and the answers + case Mch_RESULTS: // Showing the results + getMatchStatusOut->numAnswers = (int) Tst_GetNumAnswersQst (Match.Status.QstCod); + Mch_GetQstAnsFromDB (Match.MchCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + Match.Status.QstInd, + &UsrAnswer); + getMatchStatusOut->answerIndex = UsrAnswer.NumOpt; + break; } DB_QueryINSERT ("can not debug", diff --git a/swad_changelog.h b/swad_changelog.h index 4732d026a..193b6c7ea 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -555,7 +555,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.260.1 (2020-08-26)" +#define Log_PLATFORM_VERSION "SWAD 19.260.2 (2020-08-28)" #define CSS_FILE "swad19.253.css" #define JS_FILE "swad19.254.js" /* @@ -573,6 +573,7 @@ TODO: Que al generar un examen s 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. + Version 19.260.2: Aug 28, 2020 Fixed bugs in API functions related to games and matches. Reported by Sergio Díaz Rueda. (304010 lines) Version 19.260.1: Aug 26, 2020 Fixed bugs in API functions related to games and matches. Reported by Sergio Díaz Rueda. (304027 lines) Version 19.260: Aug 23, 2020 New API function getAvailableRoles. (304009 lines) Version 19.259: Aug 22, 2020 Changes in API function answerMatchQuestion. (303969 lines) diff --git a/swad_match.c b/swad_match.c index e5ed1cae5..20ed61974 100644 --- a/swad_match.c +++ b/swad_match.c @@ -203,6 +203,9 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match); static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match, struct Tst_Question *Question, const char *Class,bool ShowResult); +static void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, + struct Tst_Question *Question, + const char *Class,bool ShowResult); static bool Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer, Mch_Update_t Update); @@ -3117,9 +3120,9 @@ static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match, /******** Write single or multiple choice answer when seeing a match *********/ /*****************************************************************************/ -void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, - struct Tst_Question *Question, - const char *Class,bool ShowResult) +static void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, + struct Tst_Question *Question, + const char *Class,bool ShowResult) { unsigned NumOpt; bool RowIsOpen = false; @@ -3214,10 +3217,6 @@ static bool Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match, unsigned NumOpt; char *Class; - /***** Trivial check: this question must be valid for games *****/ - if (!Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod)) - return false; - /***** Get number of options in this question *****/ NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod); diff --git a/swad_match.h b/swad_match.h index 513619c44..6f50683ac 100644 --- a/swad_match.h +++ b/swad_match.h @@ -128,10 +128,6 @@ unsigned Mch_GetNumUnfinishedMchsInGame (long GamCod); bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Mch_Match *Match); -void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, - struct Tst_Question *Question, - const char *Class,bool ShowResult); - bool Mch_RegisterMeAsPlayerInMatch (struct Mch_Match *Match); void Mch_GetMatchBeingPlayed (void); diff --git a/swad_test.c b/swad_test.c index ccf1ac39c..888edf490 100644 --- a/swad_test.c +++ b/swad_test.c @@ -2792,20 +2792,6 @@ void Tst_WriteAnswersBank (struct Tst_Question *Question, Tst_WriteAnsBank[Question->Answer.Type] (Question,ClassTxt,ClassFeedback); } -/*****************************************************************************/ -/***************** Check if a question is valid for a game *******************/ -/*****************************************************************************/ - -bool Tst_CheckIfQuestionIsValidForGame (long QstCod) - { - /***** Check if a question is valid for a game from database *****/ - return DB_QueryCOUNT ("can not check type of a question", - "SELECT COUNT(*)" - " FROM tst_questions" - " WHERE QstCod=%ld AND AnsType='%s'", - QstCod,Tst_StrAnswerTypesDB[Tst_ANS_UNIQUE_CHOICE]) != 0; - } - /*****************************************************************************/ /****************** Write integer answer when editing a test *****************/ /*****************************************************************************/ diff --git a/swad_test.h b/swad_test.h index 202bb5e49..135ca6c0d 100644 --- a/swad_test.h +++ b/swad_test.h @@ -137,7 +137,6 @@ void Tst_ChangeFormatAnswersFeedback (struct Tst_Question *Question); void Tst_WriteAnswersBank (struct Tst_Question *Question, const char *ClassTxt, const char *ClassFeedback); -bool Tst_CheckIfQuestionIsValidForGame (long QstCod); void Tst_WriteAnsTF (char AnsTF); void Tst_WriteParamQstCod (unsigned NumQst,long QstCod);