From 705958aacfcd41f1669b7689db79e29e82ae01b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 8 Dec 2019 13:34:12 +0100 Subject: [PATCH] Version19.87 --- swad_action.c | 4 +- swad_changelog.h | 5 +- swad_game.c | 22 ++- swad_game.h | 2 +- swad_global.h | 10 +- swad_match_result.c | 381 ++++++++++++++++++++++++++++---------------- swad_match_result.h | 7 +- 7 files changed, 267 insertions(+), 164 deletions(-) diff --git a/swad_action.c b/swad_action.c index ac0d0c1e..61a2d329 100644 --- a/swad_action.c +++ b/swad_action.c @@ -2168,12 +2168,12 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActRefMchStd ] = {1782,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Mch_GetMatchBeingPlayed ,Mch_RefreshMatchStd ,NULL}, [ActSeeAllMyMchRes ] = {1796,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowMyMchRes ,NULL}, - [ActSeeGamMyMchRes ] = {1810,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowMyMchRes ,NULL}, + [ActSeeGamMyMchRes ] = {1810,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowMyMchResInGame ,NULL}, [ActSeeOneMchResMe ] = {1797,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowOneMchResult ,NULL}, [ActReqSeeAllMchRes ] = {1798,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dat_SetIniEndDates ,McR_SelUsrsToViewUsrsMchRes ,NULL}, [ActSeeAllMchRes ] = {1799,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_GetUsrsAndShowMchRes ,NULL}, - [ActSeeGamMchRes ] = {1811,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_GetUsrsAndShowMchResInGame ,NULL}, + [ActSeeGamMchRes ] = {1811,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowUsrsMchResultsInGame ,NULL}, [ActSeeOneMchResOth ] = {1800,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,McR_ShowOneMchResult ,NULL}, [ActChgVisResMchUsr ] = {1801,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mch_ToggleVisibilResultsMchUsr ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index d36e6f50..ef2b279b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -490,14 +490,15 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.86.1 (2019-12-07)" +#define Log_PLATFORM_VERSION "SWAD 19.87 (2019-12-07)" #define CSS_FILE "swad19.85.css" #define JS_FILE "swad19.70.js" /* // TODO: Hacer un nuevo rol en los TFG: tutor externo (profesor de áreas no vinculadas con el centro, profesionales de empresas, etc.) // TODO: Impedir la creación y edición de proyectos si no son editables. -// TODO: En cada juego, poder listar los resultados en una tabla como la de resultados globales +// TODO: En cada partida, poder listar los resultados en una tabla como la de resultados globales + Version 19.87: Dec 08, 2019 Show matches results in a game for all students. (247990 lines) Version 19.86.1: Dec 07, 2019 Show matches results in a game for a student. (247901 lines) Version 19.86: Dec 07, 2019 New actions to show the matches results in a game. (247905 lines) 2 changes necessary in database: diff --git a/swad_game.c b/swad_game.c index 82a24524..00fb7dec 100644 --- a/swad_game.c +++ b/swad_game.c @@ -805,37 +805,35 @@ void Gam_GetListGames (Gam_Order_t SelectedOrder) /*****************************************************************************/ /********************* Get list of game events selected **********************/ /*****************************************************************************/ -// Return number of games selected -unsigned Gam_GetListSelectedGamCods (char **StrGamCodsSelected) +void Gam_GetListSelectedGamCods (void) { unsigned MaxSizeListGamCodsSelected; unsigned NumGame; const char *Ptr; long GamCod; char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - unsigned NumGamesSelected; /***** Allocate memory for list of games selected *****/ MaxSizeListGamCodsSelected = Gbl.Games.Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); - if ((*StrGamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL) + if ((Gbl.Games.GamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL) Lay_NotEnoughMemoryExit (); /***** Get parameter multiple with list of games selected *****/ - Par_GetParMultiToText ("GamCod",*StrGamCodsSelected,MaxSizeListGamCodsSelected); + Par_GetParMultiToText ("GamCod",Gbl.Games.GamCodsSelected,MaxSizeListGamCodsSelected); /***** Set which games will be shown as selected (checkboxes on) *****/ - if ((*StrGamCodsSelected)[0]) // There are games selected + if (Gbl.Games.GamCodsSelected[0]) // Some games selected { /* Reset selection */ for (NumGame = 0; NumGame < Gbl.Games.Num; NumGame++) Gbl.Games.Lst[NumGame].Selected = false; - NumGamesSelected = 0; + Gbl.Games.NumSelected = 0; /* Set some games as selected */ - for (Ptr = *StrGamCodsSelected; + for (Ptr = Gbl.Games.GamCodsSelected; *Ptr; ) { @@ -850,22 +848,20 @@ unsigned Gam_GetListSelectedGamCods (char **StrGamCodsSelected) if (Gbl.Games.Lst[NumGame].GamCod == GamCod) { Gbl.Games.Lst[NumGame].Selected = true; - NumGamesSelected++; + Gbl.Games.NumSelected++; break; } } } - else // No games selected + else // No games selected { /***** Set all games as selected *****/ for (NumGame = 0; NumGame < Gbl.Games.Num; NumGame++) Gbl.Games.Lst[NumGame].Selected = true; - NumGamesSelected = Gbl.Games.Num; + Gbl.Games.NumSelected = Gbl.Games.Num; } - - return NumGamesSelected; } /*****************************************************************************/ diff --git a/swad_game.h b/swad_game.h index 66c12a35..85328afc 100644 --- a/swad_game.h +++ b/swad_game.h @@ -94,7 +94,7 @@ long Gam_GetParamGameCod (void); long Gam_GetParams (void); void Gam_GetListGames (Gam_Order_t SelectedOrder); -unsigned Gam_GetListSelectedGamCods (char **StrGamCodsSelected); +void Gam_GetListSelectedGamCods (void); void Gam_GetDataOfGameByCod (struct Game *Gam); void Gam_GetDataOfGameByFolder (struct Game *Gam); void Gam_FreeListGames (void); diff --git a/swad_global.h b/swad_global.h index 25b99169..49af4849 100644 --- a/swad_global.h +++ b/swad_global.h @@ -703,14 +703,16 @@ struct Globals } DateRange; struct { - bool LstIsRead; // Is the list already read from database, or it needs to be read? - unsigned Num; // Number of games - struct GameSelected *Lst; // List of games + bool LstIsRead; // Is the list already read from database... + // ...or it needs to be read? + unsigned Num; // Total number of games + unsigned NumSelected; // Number of games selected + struct GameSelected *Lst; // List of games Gam_Order_t SelectedOrder; unsigned CurrentPage; char *ListQuestions; long MchCodBeingPlayed; // Used to refresh game via AJAX - char *StrGamCodsSelected; + char *GamCodsSelected; // String with selected game codes separated by separator multiple } Games; struct { diff --git a/swad_match_result.c b/swad_match_result.c index cf27fd40..3a8402d5 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -74,8 +74,10 @@ extern struct Globals Gbl; static void McR_ShowUsrsMchResults (void); static void McR_ListGamesToSelect (void); static void McR_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther); + +static void McR_BuildGamesSelectedCommas (char *GamesSelectedCommas); static void McR_ShowMchResults (Usr_MeOrOther_t MeOrOther, - unsigned NumGamesSelected); + const char *GamesSelectedSeparatedByCommas); static void McR_ShowMchResultsSummaryRow (unsigned NumResults, unsigned NumTotalQsts, unsigned NumTotalQstsNotBlank, @@ -90,65 +92,6 @@ static void McR_GetMatchResultDataByMchCod (long MchCod,long UsrCod, static bool McR_CheckIfICanSeeMatchResult (long MchCod,long UsrCod); static bool McR_GetVisibilityMchResultFromDB (long MchCod); -/*****************************************************************************/ -/*************************** Show my matches results *************************/ -/*****************************************************************************/ - -void McR_ShowMyMchRes (void) - { - extern const char *Hlp_ASSESSMENT_Games_results; - extern const char *Hlp_ASSESSMENT_Games_results; - extern const char *Txt_Results; - extern const char *Txt_No_games; - unsigned NumGamesSelected; - - /***** Get list of games *****/ - Gam_GetListGames (Gam_ORDER_BY_TITLE); - - /***** Get list of game codes selected *****/ - NumGamesSelected = Gam_GetListSelectedGamCods (&Gbl.Games.StrGamCodsSelected); - - if (NumGamesSelected) - { - /***** Begin box *****/ - Box_BoxBegin (NULL,Txt_Results,NULL, - Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); - - /***** List games to select *****/ - McR_ListGamesToSelect (); - - /***** Start section with match results table *****/ - HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); - - /***** Begin table *****/ - HTM_TABLE_BeginWidePadding (2); - - /***** Header of the table with the list of users *****/ - McR_ShowHeaderMchResults (Usr_ME); - - /***** List my matches results *****/ - Tst_GetConfigTstFromDB (); // To get feedback type - McR_ShowMchResults (Usr_ME,NumGamesSelected); - - /***** End table *****/ - HTM_TABLE_End (); - - /***** End section with match results table *****/ - HTM_SECTION_End (); - - /***** End box *****/ - Box_BoxEnd (); - } - else - Ale_ShowAlert (Ale_WARNING,Txt_No_games); - - /***** Free memory for list of game events selected *****/ - free (Gbl.Games.StrGamCodsSelected); - - /***** Free list of games *****/ - Gam_FreeListGames (); - } - /*****************************************************************************/ /*********** Select users and dates to show their matches results ************/ /*****************************************************************************/ @@ -249,6 +192,101 @@ void McR_SelUsrsToViewUsrsMchRes (void) Grp_FreeListCodSelectedGrps (); } +/*****************************************************************************/ +/*************************** Show my matches results *************************/ +/*****************************************************************************/ + +void McR_ShowMyMchRes (void) + { + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Txt_Results; + extern const char *Txt_No_games; + char *GamesSelectedCommas = NULL; // Initialized to avoid warning + + /***** Get list of games *****/ + Gam_GetListGames (Gam_ORDER_BY_TITLE); + Gam_GetListSelectedGamCods (); + McR_BuildGamesSelectedCommas (GamesSelectedCommas); + + if (Gbl.Games.NumSelected) + { + /***** Get feedback type *****/ + Tst_GetConfigTstFromDB (); + + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Results,NULL, + Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); + + /***** Start section with match results table *****/ + HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); + HTM_TABLE_BeginWidePadding (2); + McR_ShowHeaderMchResults (Usr_ME); + + /***** List my matches results *****/ + McR_ShowMchResults (Usr_ME,GamesSelectedCommas); + + /***** End section with match results table *****/ + HTM_TABLE_End (); + HTM_SECTION_End (); + + /***** End box *****/ + Box_BoxEnd (); + } + else + Ale_ShowAlert (Ale_WARNING,Txt_No_games); + + /***** Free list of games *****/ + free (GamesSelectedCommas); + free (Gbl.Games.GamCodsSelected); + Gam_FreeListGames (); + } + +/*****************************************************************************/ +/***************** Show my matches results in a given game *******************/ +/*****************************************************************************/ + +void McR_ShowMyMchResInGame (void) + { + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Txt_Results; + extern const char *Txt_No_games; + long GamCod; + char *GamesSelectedCommas; + + /***** Get game code *****/ + if ((GamCod = Gam_GetParamGameCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of game is missing."); + if (asprintf (&GamesSelectedCommas,"%ld",GamCod) < 0) + Lay_NotEnoughMemoryExit (); + + /***** Get feedback type *****/ + Tst_GetConfigTstFromDB (); + + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Results,NULL, + Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); + + /***** Start section with match results table *****/ + HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); + HTM_TABLE_BeginWidePadding (2); + McR_ShowHeaderMchResults (Usr_ME); + + /***** List my matches results *****/ + McR_ShowMchResults (Usr_ME,GamesSelectedCommas); + + /***** End section with match results table *****/ + HTM_TABLE_End (); + HTM_SECTION_End (); + + /***** End box *****/ + Box_BoxEnd (); + + /***** Free string with list of selected games separated by commas *****/ + free (GamesSelectedCommas); + } + /*****************************************************************************/ /****************** Get users and show their matches results *****************/ /*****************************************************************************/ @@ -260,11 +298,6 @@ void McR_GetUsrsAndShowMchRes (void) McR_SelUsrsToViewUsrsMchRes); } -void McR_GetUsrsAndShowMchResInGame (void) - { - // TODO: Implement!!! - } - /*****************************************************************************/ /****************** Show matches results for several users *******************/ /*****************************************************************************/ @@ -274,68 +307,127 @@ static void McR_ShowUsrsMchResults (void) extern const char *Hlp_ASSESSMENT_Games_results; extern const char *Txt_Results; extern const char *Txt_No_games; - unsigned NumGamesSelected; + char *GamesSelectedCommas = NULL; // Initialized to avoid warning const char *Ptr; /***** Get list of games *****/ Gam_GetListGames (Gam_ORDER_BY_TITLE); + Gam_GetListSelectedGamCods (); + McR_BuildGamesSelectedCommas (GamesSelectedCommas); - /***** Get list of game codes selected *****/ - NumGamesSelected = Gam_GetListSelectedGamCods (&Gbl.Games.StrGamCodsSelected); + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Results,NULL, + Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); - if (NumGamesSelected) + /***** List games to select *****/ + McR_ListGamesToSelect (); + + /***** Start section with match results table *****/ + HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); + HTM_TABLE_BeginWidePadding (2); + McR_ShowHeaderMchResults (Usr_OTHER); + + /***** List the matches results of the selected users *****/ + Ptr = Gbl.Usrs.Selected.List[Rol_UNK]; + while (*Ptr) { - /***** Begin box *****/ - Box_BoxBegin (NULL,Txt_Results,NULL, - Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); - - /***** List games to select *****/ - McR_ListGamesToSelect (); - - /***** Start section with match results table *****/ - HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); - - /***** Begin table *****/ - HTM_TABLE_BeginWidePadding (2); - - /***** Header of the table with the list of users *****/ - McR_ShowHeaderMchResults (Usr_OTHER); - - /***** List the matches results of the selected users *****/ - Ptr = Gbl.Usrs.Selected.List[Rol_UNK]; - while (*Ptr) - { - Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod, - Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); - Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); - if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) - if (Usr_CheckIfICanViewMch (&Gbl.Usrs.Other.UsrDat)) - { - /***** Show matches results *****/ - Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); - McR_ShowMchResults (Usr_OTHER,NumGamesSelected); - } - } - - /***** End table *****/ - HTM_TABLE_End (); - - /***** End section with match results table *****/ - HTM_SECTION_End (); - - /***** End box *****/ - Box_BoxEnd (); + Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod, + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); + Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) + if (Usr_CheckIfICanViewMch (&Gbl.Usrs.Other.UsrDat)) + { + /***** Show matches results *****/ + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); + McR_ShowMchResults (Usr_OTHER,GamesSelectedCommas); + } } - else - Ale_ShowAlert (Ale_WARNING,Txt_No_games); - /***** Free memory for list of game events selected *****/ - free (Gbl.Games.StrGamCodsSelected); + /***** End section with match results table *****/ + HTM_TABLE_End (); + HTM_SECTION_End (); + + /***** End box *****/ + Box_BoxEnd (); /***** Free list of games *****/ + free (GamesSelectedCommas); + free (Gbl.Games.GamCodsSelected); Gam_FreeListGames (); } +/*****************************************************************************/ +/** Show matches results of a game for the users who answered in that game ***/ +/*****************************************************************************/ + +void McR_ShowUsrsMchResultsInGame (void) + { + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Txt_Results; + long GamCod; + char *GamesSelectedCommas; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumUsrs; + unsigned long NumUsr; + + /***** Get game code *****/ + if ((GamCod = Gam_GetParamGameCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of game is missing."); + if (asprintf (&GamesSelectedCommas,"%ld",GamCod) < 0) + Lay_NotEnoughMemoryExit (); + + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Results,NULL, + Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE); + + /***** Make database query *****/ + NumUsrs = DB_QuerySELECT (&mysql_res,"can not get matches results of a user", + "SELECT DISTINCT mch_answers.UsrCod" // row[0] + " FROM mch_matches,mch_answers" + " WHERE mch_matches.GamCod=%ld" + " AND mch_matches.MchCod=mch_answers.MchCod" + " ORDER BY mch_answers.UsrCod", // TODO: Order by name + GamCod); + if (NumUsrs) + { + /***** Start section with match results table *****/ + HTM_SECTION_Begin (McR_RESULTS_TABLE_ID); + HTM_TABLE_BeginWidePadding (2); + McR_ShowHeaderMchResults (Usr_OTHER); + + for (NumUsr = 0; + NumUsr < NumUsrs; + NumUsr++) + { + row = mysql_fetch_row (mysql_res); + + /* Get match code (row[0]) */ + if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) + if (Usr_CheckIfICanViewMch (&Gbl.Usrs.Other.UsrDat)) + { + /***** Show matches results *****/ + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); + McR_ShowMchResults (Usr_OTHER,GamesSelectedCommas); + } + } + + /***** End section with match results table *****/ + HTM_TABLE_End (); + HTM_SECTION_End (); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + /***** End box *****/ + Box_BoxEnd (); + + /***** Free string with list of selected games separated by commas *****/ + free (GamesSelectedCommas); + } + /*****************************************************************************/ /********** Write list of those attendance events that have students *********/ /*****************************************************************************/ @@ -457,21 +549,47 @@ static void McR_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther) HTM_TR_End (); } +/*****************************************************************************/ +/******* Build string with list of selected games separated by commas ********/ +/******* from list of selected games ********/ +/*****************************************************************************/ + +static void McR_BuildGamesSelectedCommas (char *GamesSelectedCommas) + { + size_t MaxLength; + unsigned NumGame; + char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; + + /***** Allocate memory for subquery of games selected *****/ + MaxLength = (size_t) Gbl.Games.NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); + if ((GamesSelectedCommas = (char *) malloc (MaxLength + 1)) == NULL) + Lay_NotEnoughMemoryExit (); + + /***** Build subquery with list of selected games *****/ + GamesSelectedCommas[0] = '\0'; + for (NumGame = 0; + NumGame < Gbl.Games.Num; + NumGame++) + if (Gbl.Games.Lst[NumGame].Selected) + { + sprintf (LongStr,"%ld",Gbl.Games.Lst[NumGame].GamCod); + if (GamesSelectedCommas[0]) + Str_Concat (GamesSelectedCommas,",",MaxLength); + Str_Concat (GamesSelectedCommas,LongStr,MaxLength); + } + } + /*****************************************************************************/ /********* Show the matches results of a user in the current course **********/ /*****************************************************************************/ static void McR_ShowMchResults (Usr_MeOrOther_t MeOrOther, - unsigned NumGamesSelected) + const char *GamesSelectedCommas) { extern const char *Txt_Match_result; extern const char *Txt_Hidden_result; MYSQL_RES *mysql_res; MYSQL_ROW row; - size_t MaxSizeGamesSubQuery; - char *GamesSubQuery; - unsigned NumGame; - char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; struct UsrData *UsrDat; bool ShowResultThisMatch; bool ShowSummaryResults = true; @@ -493,31 +611,15 @@ static void McR_ShowMchResults (Usr_MeOrOther_t MeOrOther, time_t TimeUTC[Dat_NUM_START_END_TIME]; /***** Trivial check: there should be games selected *****/ - if (!NumGamesSelected) + if (!GamesSelectedCommas) + return; + if (!GamesSelectedCommas[0]) return; /***** Set user *****/ UsrDat = (MeOrOther == Usr_ME) ? &Gbl.Usrs.Me.UsrDat : &Gbl.Usrs.Other.UsrDat; - /***** Allocate memory for subquery of games selected *****/ - MaxSizeGamesSubQuery = (size_t) NumGamesSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); - if ((GamesSubQuery = (char *) malloc (MaxSizeGamesSubQuery + 1)) == NULL) - Lay_NotEnoughMemoryExit (); - - /***** Build subquery with list of selected games *****/ - GamesSubQuery[0] = '\0'; - for (NumGame = 0; - NumGame < Gbl.Games.Num; - NumGame++) - if (Gbl.Games.Lst[NumGame].Selected) - { - sprintf (LongStr,"%ld",Gbl.Games.Lst[NumGame].GamCod); - if (GamesSubQuery[0]) - Str_Concat (GamesSubQuery,",",MaxSizeGamesSubQuery); - Str_Concat (GamesSubQuery,LongStr,MaxSizeGamesSubQuery); - } - /***** Make database query *****/ NumResults = (unsigned) DB_QuerySELECT (&mysql_res,"can not get matches results of a user", @@ -534,11 +636,10 @@ static void McR_ShowMchResults (Usr_MeOrOther_t MeOrOther, " AND mch_matches.GamCod=gam_games.GamCod" " AND gam_games.CrsCod=%ld" // Extra check " AND gam_games.GamCod IN (%s)" - " ORDER BY gam_games.Title", + " ORDER BY mch_matches.Title", UsrDat->UsrCod, Gbl.Hierarchy.Crs.CrsCod, - GamesSubQuery); - free (GamesSubQuery); + GamesSelectedCommas); /***** Show user's data *****/ HTM_TR_Begin (NULL); diff --git a/swad_match_result.h b/swad_match_result.h index e452e7cb..8af05fcf 100644 --- a/swad_match_result.h +++ b/swad_match_result.h @@ -35,10 +35,13 @@ /***************************** Public prototypes *****************************/ /*****************************************************************************/ -void McR_ShowMyMchRes (void); void McR_SelUsrsToViewUsrsMchRes (void); + +void McR_ShowMyMchRes (void); +void McR_ShowMyMchResInGame (void); void McR_GetUsrsAndShowMchRes (void); -void McR_GetUsrsAndShowMchResInGame (void); +void McR_ShowUsrsMchResultsInGame (void); + void McR_ShowOneMchResult (void); void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, unsigned *NumQsts,unsigned *NumQstsNotBlank);