From f5f48cd08eddf10f4f2f07c04c8f27e9b0ae9dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 17 Jul 2019 18:17:44 +0200 Subject: [PATCH] Version18.135 --- sql/swad.sql | 7 +++ swad_action.c | 4 +- swad_changelog.h | 6 ++- swad_database.c | 16 +++++++ swad_game.c | 118 ++++++++++++++++++++++++++++++++--------------- swad_game.h | 4 +- swad_layout.c | 5 +- 7 files changed, 118 insertions(+), 42 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index 4fda84f48..6c7488863 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -644,6 +644,13 @@ CREATE TABLE IF NOT EXISTS gam_matches ( UNIQUE INDEX(MchCod), INDEX(GamCod)); -- +-- Table gam_mch_being_played: stores the current matches being played +-- +CREATE TABLE IF NOT EXISTS gam_mch_being_played ( + MchCod INT NOT NULL, + TS TIMESTAMP, + UNIQUE INDEX(MchCod)); +-- -- Table gam_players: stores the current match players -- CREATE TABLE IF NOT EXISTS gam_players ( diff --git a/swad_action.c b/swad_action.c index 490c81b6c..0c706176c 100644 --- a/swad_action.c +++ b/swad_action.c @@ -2154,11 +2154,11 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActResMchTch */{1785,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,Gam_GetMatchBeingPlayed ,Gam_RequestStartResumeMatchTch ,NULL}, /* ActCurMchTch */{1789,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_CurrentStatusMatchTch ,NULL}, /* ActNxtMchTch */{1672,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_NextStatusMatchTch ,NULL}, - /* ActRefMchTch */{1788,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshNumPlayersMatchTch ,NULL}, + /* ActRefMchTch */{1788,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshMatchTch ,NULL}, /* ActShoMchTch */{1786,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ShowFinishedMatchResults ,NULL}, /* ActPlyMchStd */{1780,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,Gam_GetMatchBeingPlayed ,Gam_ShowMatchToMeAsStd ,NULL}, - /* ActRefMchStd */{1782,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshCurrentMatchStd ,NULL}, + /* ActRefMchStd */{1782,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshMatchStd ,NULL}, /* ActAnsMchQstStd */{1651,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ReceiveQstAnsFromStd ,NULL}, /* ActFrmNewGam */{1652,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index 325e573f9..d78d00472 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -458,10 +458,14 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.134 (2019-07-16)" +#define Log_PLATFORM_VERSION "SWAD 18.135 (2019-07-17)" #define CSS_FILE "swad18.132.2.css" #define JS_FILE "swad18.130.2.js" /* + Version 18.135: Jul 17, 2019 A match is put in pause for students when the teacher closes the tab. (243707 lines) + 1 change necessary in database: +CREATE TABLE IF NOT EXISTS gam_mch_being_played (MchCod INT NOT NULL,TS TIMESTAMP,UNIQUE INDEX(MchCod)); + Version 18.134: Jul 17, 2019 Changes resuming a match. (243641 lines) 2 changes necessary in database: UPDATE actions SET Txt='Mostrar pregunta siguiente en partida (como profesor)' WHERE ActCod='1672' AND Language='es'; diff --git a/swad_database.c b/swad_database.c index 5c890ad74..fc190e789 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1401,6 +1401,22 @@ mysql> DESCRIBE gam_matches; "UNIQUE INDEX(MchCod)," "INDEX(GamCod)"); + /***** Table gam_mch_being_played *****/ +/* +mysql> DESCRIBE gam_mch_being_played; ++--------+-----------+------+-----+-------------------+-----------------------------+ +| Field | Type | Null | Key | Default | Extra | ++--------+-----------+------+-----+-------------------+-----------------------------+ +| MchCod | int(11) | NO | PRI | NULL | | +| TS | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | ++--------+-----------+------+-----+-------------------+-----------------------------+ +2 rows in set (0.01 sec) +*/ + DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_mch_being_played (" + "MchCod INT NOT NULL," + "TS TIMESTAMP," + "UNIQUE INDEX(MchCod))"); + /***** Table gam_players *****/ /* mysql> DESCRIBE gam_players; diff --git a/swad_game.c b/swad_game.c index 39f739c50..cf17806b9 100644 --- a/swad_game.c +++ b/swad_game.c @@ -92,6 +92,7 @@ struct Match time_t QstStartTimeUTC; bool ShowingAnswers; bool Finished; + bool BeingPlayed; } Status; }; @@ -192,7 +193,9 @@ static void Gam_PutBigButton (Act_Action_t NextAction,long MchCod, const char *Icon,const char *Txt); static void Gam_RemoveOldPlayers (void); -static void Gam_RemoveAllPlayersInMatch (long MchCod); +static void Gam_UpdateMatchAsBeingPlayed (long MchCod); +static void Gam_SetMatchAsNotBeingPlayed (long MchCod); +static bool Gam_GetIfMatchIsBeingPlayed (long MchCod); static void Gam_RegisterMeAsPlayerInMatch (long MchCod); static void Gam_GetAndShowNumPlayersInMatch (long MchCod); static unsigned Gam_GetNumPlayers (long MchCod); @@ -2779,6 +2782,7 @@ void Gam_GetDataOfMatchByCod (struct Match *Match) Match->Status.QstStartTimeUTC = (time_t) 0; Match->Status.ShowingAnswers = false; Match->Status.Finished = false; + Match->Status.BeingPlayed = false; } /***** Free structure that stores the query result *****/ @@ -3041,6 +3045,12 @@ static void Gam_GetMatchDataFromRow (MYSQL_RES *mysql_res, /* Get whether the match is finished or not (row(10)) */ Match->Status.Finished = (row[10][0] == 'Y'); + + /***** Get whether the match is being played or not *****/ + if (Match->Status.Finished) + Match->Status.BeingPlayed = false; + else + Match->Status.BeingPlayed = Gam_GetIfMatchIsBeingPlayed (Match->MchCod); } /*****************************************************************************/ @@ -3343,6 +3353,10 @@ static void Gam_UpdateMatchBeingPlayed (struct Match *Match) Match->Status.Finished ? 'Y' : 'N', Match->MchCod,Gbl.Hierarchy.Crs.CrsCod); + + if (Match->Status.Finished) + /* Update match as not being played */ + Gam_SetMatchAsNotBeingPlayed (Match->MchCod); } /*****************************************************************************/ @@ -3383,10 +3397,6 @@ void Gam_CurrentStatusMatchTch (void) /* Update match status in database */ Gam_UpdateMatchBeingPlayed (&Match); } - - /* Remove all players in this match */ - if (Match.Status.Finished) - Gam_RemoveAllPlayersInMatch (Match.MchCod); } /***** Show current match status *****/ @@ -3467,10 +3477,6 @@ void Gam_NextStatusMatchTch (void) /* Update match status in database */ Gam_UpdateMatchBeingPlayed (&Match); - - /* Remove all players in this match */ - if (Match.Status.Finished) - Gam_RemoveAllPlayersInMatch (Match.MchCod); } /***** Show current match status *****/ @@ -3493,10 +3499,16 @@ static void Gam_ShowMatchStatusForTch (struct Match *Match) { /***** Show current match status *****/ if (Match->Status.Finished) + /* Show alert */ Gam_ShowAlertFinishedMatch (); else // Unfinished match - /***** Show current question and possible answers *****/ + { + /* Show current question and possible answers */ Gam_PlayGameShowQuestionAndAnswers (Match); + + /* Update match as being played */ + Gam_UpdateMatchAsBeingPlayed (Match->MchCod); + } } /*****************************************************************************/ @@ -3635,30 +3647,57 @@ static void Gam_PutBigButton (Act_Action_t NextAction,long MchCod, static void Gam_RemoveOldPlayers (void) { - /***** Remove players who have left matches *****/ - DB_QueryDELETE ("can not remove old match players", - "DELETE FROM gam_players" - " WHERE TSMchCod); - if (Match->Status.QstInd == 0) // Not yet started - { - fprintf (Gbl.F.Out,"
" - "\"Please" - "
", - Cfg_URL_ICON_PUBLIC, - "Por favor, espere a que el juego comience..."); // TODO: Need translation!!!!! - } - else + if (Match->Status.BeingPlayed) { /***** Show question *****/ /* Write number of question */ @@ -3894,6 +3933,13 @@ static void Gam_ShowMatchStatusForStd (struct Match *Match) fprintf (Gbl.F.Out,""); } + else // Not being played + fprintf (Gbl.F.Out,"
" + "\"Please" + "
", + Cfg_URL_ICON_PUBLIC); } } diff --git a/swad_game.h b/swad_game.h index 023a21114..b89a12472 100644 --- a/swad_game.h +++ b/swad_game.h @@ -130,8 +130,8 @@ void Gam_ShowFinishedMatchResults (void); void Gam_GetMatchBeingPlayed (void); void Gam_ShowMatchToMeAsStd (void); -void Gam_RefreshNumPlayersMatchTch (void); -void Gam_RefreshCurrentMatchStd (void); +void Gam_RefreshMatchTch (void); +void Gam_RefreshMatchStd (void); void Gam_ReceiveQstAnsFromStd (void); diff --git a/swad_layout.c b/swad_layout.c index 50f46f833..313059b06 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -684,6 +684,7 @@ static void Lay_WriteScriptInit (void) break; case ActNewMchTch: case ActResMchTch: + case ActCurMchTch: case ActNxtMchTch: case ActPlyMchStd: case ActAnsMchQstStd: @@ -800,15 +801,17 @@ static void Lay_WriteScriptParamsAJAX (void) Act_GetActCod (ActRefOldSocPubUsr), Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); break; - /* Parameters related with match refreshing */ + /* Parameters related with match refreshing (for teachers) */ case ActNewMchTch: case ActResMchTch: + case ActCurMchTch: case ActNxtMchTch: fprintf (Gbl.F.Out,"var RefreshParamNxtActGam = \"act=%ld\";\n" "var RefreshParamMchCod = \"MchCod=%ld\";\n", Act_GetActCod (ActRefMchTch), Gbl.Games.MchCodBeingPlayed); break; + /* Parameters related with match refreshing (for students) */ case ActPlyMchStd: case ActAnsMchQstStd: fprintf (Gbl.F.Out,"var RefreshParamNxtActGam = \"act=%ld\";\n"