diff --git a/swad_changelog.h b/swad_changelog.h index cc357f085..fff2727e5 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -460,10 +460,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.0 (2019-09-12)" +#define Log_PLATFORM_VERSION "SWAD 19.0.1 (2019-09-13)" #define CSS_FILE "swad18.138.css" #define JS_FILE "swad18.130.2.js" /* + Version 19.0.1: Sep 13, 2019 Show results of questions in matches. (244583 lines) Version 19.0: Sep 12, 2019 Changes in behaviour of matches. (244585 lines) 3 changes necessary in database: ALTER TABLE gam_matches DROP COLUMN ShowResults,DROP COLUMN Showing; diff --git a/swad_game.c b/swad_game.c index e99e79a3d..f8acced8e 100644 --- a/swad_game.c +++ b/swad_game.c @@ -191,7 +191,7 @@ static void Gam_FreeListsSelectedQuestions (void); static unsigned Gam_CountNumQuestionsInList (void); static unsigned Gam_GetNumAnswerers (struct Match *Match); -static unsigned Gam_GetNumUsrsWhoAnswered (long GamCod,unsigned QstInd,unsigned AnsInd); +static unsigned Gam_GetNumUsrsWhoAnswered (long MchCod,unsigned QstInd,unsigned AnsInd); static void Gam_DrawBarNumUsrs (unsigned NumUsrs,unsigned MaxUsrs); static void Gam_PutParamsOneQst (void); @@ -2179,8 +2179,8 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, Tst_WriteQstFeedback (row[4],"TEST_EDI_LIGHT"); /* Show answers */ - Tst_WriteAnswersGameResult (GamCod,QstInd,QstCod, - "TEST_EDI",true); // Show result + Tst_WriteAnswersMatchResult (-1L,QstInd,QstCod, + "TEST_EDI",false); // Don't show result fprintf (Gbl.F.Out,"" ""); @@ -2344,12 +2344,12 @@ static unsigned Gam_CountNumQuestionsInList (void) /*** Get number of users who selected this answer and draw proportional bar **/ /*****************************************************************************/ -void Gam_GetAndDrawBarNumUsrsWhoAnswered (long GamCod,unsigned QstInd,unsigned AnsInd,unsigned NumUsrs) +void Gam_GetAndDrawBarNumUsrsWhoAnswered (long MchCod,unsigned QstInd,unsigned AnsInd,unsigned NumUsrs) { unsigned NumUsrsThisAnswer; /***** Get number of users who selected this answer *****/ - NumUsrsThisAnswer = Gam_GetNumUsrsWhoAnswered (GamCod,QstInd,AnsInd); + NumUsrsThisAnswer = Gam_GetNumUsrsWhoAnswered (MchCod,QstInd,AnsInd); /***** Show stats of this answer *****/ Gam_DrawBarNumUsrs (NumUsrsThisAnswer,NumUsrs); @@ -2373,25 +2373,17 @@ static unsigned Gam_GetNumAnswerers (struct Match *Match) /**** Get number of users who selected a given answer of a game question *****/ /*****************************************************************************/ -static unsigned Gam_GetNumUsrsWhoAnswered (long GamCod,unsigned QstInd,unsigned AnsInd) +static unsigned Gam_GetNumUsrsWhoAnswered (long MchCod,unsigned QstInd,unsigned AnsInd) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumUsrs = 0; // Default returned value - - /***** Get answers of a question from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get number of users who answered", - "SELECT NumUsrs FROM gam_answers" - " WHERE GamCod=%ld AND QstInd=%u AND AnsInd=%u", - GamCod,QstInd,AnsInd)) - { - row = mysql_fetch_row (mysql_res); - if (row[0]) // There are users who selected this answer - if (sscanf (row[0],"%u",&NumUsrs) != 1) - Lay_ShowErrorAndExit ("Error when getting number of users who answered."); - } - - return NumUsrs; + /***** Get number of users who have chosen + an answer of a question from database *****/ + return (unsigned) DB_QueryCOUNT ("can not get number of users who answered", + "SELECT COUNT(*)" + " FROM gam_answers" + " WHERE MchCod=%ld" + " AND QstInd=%u" + " AND AnsInd=%u", + MchCod,QstInd,AnsInd); } /*****************************************************************************/ @@ -4111,10 +4103,10 @@ static void Gam_ShowQuestionAndAnswersTch (struct Match *Match) case Gam_ANSWERS: if (Match->Status.BeingPlayed) /* Write answers */ - Tst_WriteAnswersGameResult (Match->GamCod, - Match->Status.QstInd, - Match->Status.QstCod, - "MATCH_TCH_QST",false); // Don't show result + Tst_WriteAnswersMatchResult (Match->MchCod, + Match->Status.QstInd, + Match->Status.QstCod, + "MATCH_TCH_QST",false); // Don't show result else // Not being played Gam_ShowWaitImage (Txt_MATCH_Paused); break; @@ -4124,8 +4116,11 @@ static void Gam_ShowQuestionAndAnswersTch (struct Match *Match) Gam_ICON_RESULTS,Txt_View_results); break; case Gam_RESULTS: - /* Show results */ - fprintf (Gbl.F.Out,"%s","Resultados aquí"); // TODO: Show results here + /* Write answers with results */ + Tst_WriteAnswersMatchResult (Match->MchCod, + Match->Status.QstInd, + Match->Status.QstCod, + "MATCH_TCH_QST",true); // Show result break; } diff --git a/swad_game.h b/swad_game.h index 6806899b4..4552060ac 100644 --- a/swad_game.h +++ b/swad_game.h @@ -104,7 +104,7 @@ void Gam_RemoveGames (Hie_Level_t Scope,long Cod); void Gam_RequestNewQuestion (void); -void Gam_GetAndDrawBarNumUsrsWhoAnswered (long GamCod,unsigned QstInd,unsigned AnsInd,unsigned NumUsrs); +void Gam_GetAndDrawBarNumUsrsWhoAnswered (long MchCod,unsigned QstInd,unsigned AnsInd,unsigned NumUsrs); void Gam_AddTstQuestionsToGame (void); diff --git a/swad_test.c b/swad_test.c index 8fc802792..5a4571b43 100644 --- a/swad_test.c +++ b/swad_test.c @@ -157,7 +157,7 @@ static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res); static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank,double *TotalScore); static void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions, struct UsrData *UsrDat, - long GamCod,unsigned NumQst,long QstCod,MYSQL_ROW row, + long MchCod,unsigned NumQst,long QstCod,MYSQL_ROW row, double *ScoreThisQst,bool *AnswerIsNotBlank); static void Tst_PutFormToEditQstMedia (struct Media *Media,int NumMediaInForm, bool OptionsDisabled); @@ -209,7 +209,7 @@ static void Tst_WriteChoiceAnsViewTest (unsigned NumQst,long QstCod,bool Shuffle static void Tst_WriteChoiceAnsAssessTest (struct UsrData *UsrDat, unsigned NumQst,MYSQL_RES *mysql_res, double *ScoreThisQst,bool *AnswerIsNotBlank); -static void Tst_WriteChoiceAnsViewGame (long GamCod,unsigned QstInd,long QstCod, +static void Tst_WriteChoiceAnsViewGame (long MchCod,unsigned QstInd,long QstCod, const char *Class, bool ShowResult); @@ -1007,7 +1007,7 @@ static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank static void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions, struct UsrData *UsrDat, - long GamCod,unsigned NumQst,long QstCod,MYSQL_ROW row, + long MchCod,unsigned NumQst,long QstCod,MYSQL_ROW row, double *ScoreThisQst,bool *AnswerIsNotBlank) { extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES]; @@ -1071,12 +1071,12 @@ static void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWith case Tst_SELECT_QUESTIONS_FOR_GAME: break; case Tst_SHOW_GAME_TO_ANSWER: - Tst_WriteAnswersGameResult (GamCod,NumQst,QstCod, - "MATCH_QST",false); // Don't show result + Tst_WriteAnswersMatchResult (MchCod,NumQst,QstCod, + "MATCH_QST",false); // Don't show result break; case Tst_SHOW_GAME_RESULT: - Tst_WriteAnswersGameResult (GamCod,NumQst,QstCod, - "MATCH_QST",true); // Show result + Tst_WriteAnswersMatchResult (MchCod,NumQst,QstCod, + "MATCH_QST",true); // Show result break; } fprintf (Gbl.F.Out,"" @@ -3522,15 +3522,15 @@ static void Tst_WriteAnswersTestResult (struct UsrData *UsrDat, } /*****************************************************************************/ -/************** Write answers of a question when viewing a game **************/ +/************* Write answers of a question when viewing a match **************/ /*****************************************************************************/ -void Tst_WriteAnswersGameResult (long GamCod,unsigned QstInd,long QstCod, - const char *Class,bool ShowResult) +void Tst_WriteAnswersMatchResult (long MchCod,unsigned QstInd,long QstCod, + const char *Class,bool ShowResult) { /***** Write answer depending on type *****/ if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE) - Tst_WriteChoiceAnsViewGame (GamCod,QstInd,QstCod, + Tst_WriteChoiceAnsViewGame (MchCod,QstInd,QstCod, Class,ShowResult); else Ale_ShowAlert (Ale_ERROR,"Type of answer not valid in a game."); @@ -4044,7 +4044,7 @@ static void Tst_WriteChoiceAnsAssessTest (struct UsrData *UsrDat, /******** Write single or multiple choice answer when viewing a test *********/ /*****************************************************************************/ -static void Tst_WriteChoiceAnsViewGame (long GamCod,unsigned QstInd,long QstCod, +static void Tst_WriteChoiceAnsViewGame (long MchCod,unsigned QstInd,long QstCod, const char *Class, bool ShowResult) { @@ -4142,7 +4142,7 @@ static void Tst_WriteChoiceAnsViewGame (long GamCod,unsigned QstInd,long QstCod, ""); /* Get number of users who selected this answer and draw proportional bar */ - Gam_GetAndDrawBarNumUsrsWhoAnswered (GamCod,QstInd,AnsInd, + Gam_GetAndDrawBarNumUsrsWhoAnswered (MchCod,QstInd,AnsInd, 0); // TODO: NumUsrs fprintf (Gbl.F.Out,"" ""); diff --git a/swad_test.h b/swad_test.h index 8085adf02..41ae75d82 100644 --- a/swad_test.h +++ b/swad_test.h @@ -154,8 +154,8 @@ bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res); void Tst_WriteParamEditQst (void); unsigned Tst_GetNumAnswersQst (long QstCod); unsigned Tst_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res,bool Shuffle); -void Tst_WriteAnswersGameResult (long GamCod,unsigned QstInd,long QstCod, - const char *Class,bool ShowResult); +void Tst_WriteAnswersMatchResult (long MchCod,unsigned QstInd,long QstCod, + const char *Class,bool ShowResult); bool Tst_CheckIfQuestionIsValidForGame (long QstCod); void Tst_WriteAnsTF (char AnsTF); void Tst_CheckIfNumberOfAnswersIsOne (void);