From d0228f7ce216304d96cb1190f0f45af413b5a0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 26 Sep 2019 01:15:21 +0200 Subject: [PATCH] Version19.14.3 --- swad_changelog.h | 2 +- swad_game.c | 68 +++++++++++++++++++++++++++++++++++------------- swad_game.h | 1 + swad_match.c | 14 ++++++++++ swad_match.h | 2 ++ 5 files changed, 68 insertions(+), 19 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 69e09dc6a..755c03653 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -474,9 +474,9 @@ ps2pdf source.ps destination.pdf #define CSS_FILE "swad19.3.css" #define JS_FILE "swad18.130.2.js" /* -// TODO: Poner columna en listado de juegos que indique el número de partidas // TODO: Imposibilitar la edición de preguntas de un juego cuando tenga partidas + Version 19.14.3: Sep 26, 2019 Column in game row with the number of matches. (246264 lines) Version 19.14.2: Sep 26, 2019 Student can not see a match result if hidden. (246227 lines) Version 19.14.1: Sep 25, 2019 Student can not see match results if hidden. (246207 lines) Version 19.14: Sep 25, 2019 New actions to show/hide match results. (246152 lines) diff --git a/swad_game.c b/swad_game.c index d0ac42ba5..47e920dc7 100644 --- a/swad_game.c +++ b/swad_game.c @@ -101,6 +101,8 @@ static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, static void Gam_PutHiddenParamOrder (void); static void Gam_GetParamOrder (void); +static void Gam_ResetGame (struct Game *Game,long UsrCod); + static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static bool Gam_CheckIfSimilarGameExists (struct Game *Game); @@ -151,6 +153,7 @@ static void Gam_ListAllGames (void) extern const char *Txt_Games; extern const char *Txt_GAMES_ORDER_HELP[Gam_NUM_ORDERS]; extern const char *Txt_GAMES_ORDER[Gam_NUM_ORDERS]; + extern const char *Txt_Matches; extern const char *Txt_No_games; Gam_Order_t Order; struct Pagination Pagination; @@ -223,6 +226,9 @@ static void Gam_ListAllGames (void) fprintf (Gbl.F.Out,""); } + + fprintf (Gbl.F.Out,"%s",Txt_Matches); + fprintf (Gbl.F.Out,""); /***** Write all the games *****/ @@ -366,6 +372,7 @@ void Gam_ShowOneGame (long GamCod, extern const char *Txt_Today; extern const char *Txt_View_game; extern const char *Txt_No_of_questions; + extern const char *Txt_Matches; char *Anchor = NULL; static unsigned UniqueId = 0; struct Game Game; @@ -467,6 +474,24 @@ void Gam_ShowOneGame (long GamCod, fprintf (Gbl.F.Out,""); + /***** Number of matches in game *****/ + fprintf (Gbl.F.Out,""); + + Frm_StartForm (ActSeeGam); + Gam_PutParamGameCod (GamCod); + Frm_LinkFormSubmit (Txt_Matches, + Game.Status.Visible ? "ASG_TITLE" : + "ASG_TITLE_LIGHT",NULL); + if (ShowOnlyThisGame) + fprintf (Gbl.F.Out,"%s: ",Txt_Matches); + fprintf (Gbl.F.Out,"%u",Game.NumMchs); + Frm_EndForm (); + + fprintf (Gbl.F.Out,""); + /***** End 1st row of this game *****/ fprintf (Gbl.F.Out,""); @@ -482,7 +507,7 @@ void Gam_ShowOneGame (long GamCod, fprintf (Gbl.F.Out,""); /***** Text of the game *****/ - fprintf (Gbl.F.Out,""); @@ -699,6 +724,9 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /* Get number of questions */ Game->NumQsts = Gam_GetNumQstsGame (Game->GamCod); + /* Get number of matches */ + Game->NumMchs = Gam_GetNumMchsGame (Game->GamCod); + /* Can I view results of the game? Can I edit game? */ switch (Gbl.Usrs.Me.Role.Logged) @@ -730,16 +758,8 @@ void Gam_GetDataOfGameByCod (struct Game *Game) } } else - { /* Initialize to empty game */ - Game->GamCod = -1L; - Game->UsrCod = -1L; - Game->Title[0] = '\0'; - Game->NumQsts = 0; - Game->Status.Visible = true; - Game->Status.ICanViewResults = false; - Game->Status.ICanEdit = false; - } + Gam_ResetGame (Game,-1L); /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -775,6 +795,25 @@ void Gam_GetDataOfGameByCod (struct Game *Game) } } +/*****************************************************************************/ +/*************************** Initialize game to empty ************************/ +/*****************************************************************************/ + +static void Gam_ResetGame (struct Game *Game,long UsrCod) + { + /***** Initialize to empty game *****/ + Game->GamCod = -1L; + Game->UsrCod = UsrCod; + Game->TimeUTC[Dat_START_TIME] = (time_t) 0; + Game->TimeUTC[Dat_END_TIME ] = (time_t) 0; + Game->Title[0] = '\0'; + Game->NumQsts = 0; + Game->NumMchs = 0; + Game->Status.Visible = true; + Game->Status.ICanViewResults = false; + Game->Status.ICanEdit = false; + } + /*****************************************************************************/ /***************************** Free list of games ****************************/ /*****************************************************************************/ @@ -1029,14 +1068,7 @@ void Gam_RequestCreatOrEditGame (void) Lay_ShowErrorAndExit ("You can not create a new game here."); /* Initialize to empty game */ - Game.GamCod = -1L; - Game.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; - Game.TimeUTC[Dat_START_TIME] = (time_t) 0; - Game.TimeUTC[Dat_END_TIME ] = (time_t) 0; - Game.Title[0] = '\0'; - Game.NumQsts = 0; - Game.Status.Visible = true; - Game.Status.ICanViewResults = false; + Gam_ResetGame (&Game,Gbl.Usrs.Me.UsrDat.UsrCod); } else { diff --git a/swad_game.h b/swad_game.h index ab2aff075..327db4232 100644 --- a/swad_game.h +++ b/swad_game.h @@ -44,6 +44,7 @@ struct Game char Title[Gam_MAX_BYTES_TITLE + 1]; time_t TimeUTC[Dat_NUM_START_END_TIME]; unsigned NumQsts; // Number of questions in the game + unsigned NumMchs; // Number of matches in the game struct { bool Visible; // Game is not hidden diff --git a/swad_match.c b/swad_match.c index 0a7169f08..f90eae515 100644 --- a/swad_match.c +++ b/swad_match.c @@ -1976,6 +1976,20 @@ static void Mch_ShowMatchStatusForStd (struct Match *Match) fprintf (Gbl.F.Out,""); } +/*****************************************************************************/ +/******************* Get number of questions of a game *********************/ +/*****************************************************************************/ + +unsigned Gam_GetNumMchsGame (long GamCod) + { + /***** Get number of matches in a game from database *****/ + return + (unsigned) DB_QueryCOUNT ("can not get number of matches of a game", + "SELECT COUNT(*) FROM mch_matches" + " WHERE GamCod=%ld", + GamCod); + } + /*****************************************************************************/ /************ Check if I belong to any of the groups of a match **************/ /*****************************************************************************/ diff --git a/swad_match.h b/swad_match.h index 8c88ad634..27808f002 100644 --- a/swad_match.h +++ b/swad_match.h @@ -58,6 +58,8 @@ void Mch_ToggleVisibilResultsMchQst (void); void Mch_BackMatchTch (void); void Mch_ForwardMatchTch (void); +unsigned Gam_GetNumMchsGame (long GamCod); + void Mch_GetMatchBeingPlayed (void); void Mch_ShowMatchToMeAsStd (void); void Mch_RefreshMatchTch (void);