diff --git a/sql/swad.sql b/sql/swad.sql index 98e1a42c3..2cfc8ba85 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -639,8 +639,8 @@ CREATE TABLE IF NOT EXISTS gam_matches ( QstInd INT NOT NULL DEFAULT 0, QstCod INT NOT NULL DEFAULT -1, QstStartTime DATETIME NOT NULL, - ShowingAnswers ENUM('N','Y') NOT NULL DEFAULT 'N', ShowResults ENUM('N','Y') NOT NULL DEFAULT 'N', + Showing ENUM('stem','answers','results') NOT NULL DEFAULT 'stem', UNIQUE INDEX(MchCod), INDEX(GamCod)); -- diff --git a/swad_action.c b/swad_action.c index 46454356a..fe84a3a20 100644 --- a/swad_action.c +++ b/swad_action.c @@ -615,9 +615,10 @@ Assessment: NEW. ActPlyMchTch Play/resume current match (by a teacher) NEW. ActShoSteMchTch Show stem of current question, hiding answers, when playing a match (by a teacher) NEW. ActShoAnsMchTch Show full current question, including answers, when playing a match (by a teacher) + NEW. ActShoResMchTch Show results when playing a match (by a teacher) NEW. ActPrvQstMchTch Show previous question when playing a match (by a teacher) 457. ActNxtQstMchTch Show next question when playing a match (by a teacher) - NEW. ActChgDisResMchTch Change display of results when playing a match (by a teacher) + NEW. ActChgShoResMchTch Change display of results when playing a match (by a teacher) NEW. ActRefMchTch Refresh current question when playing a match (as teacher) NEW. ActShoMchTch Show finished match results @@ -2161,9 +2162,10 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActPlyMchTch */{1789,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ResumeMatchTch ,NULL}, /* ActShoSteMchTch */{1792,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ShowStemQstMatchTch ,NULL}, /* ActShoAnsMchTch */{1793,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ShowAnssQstMatchTch ,NULL}, + /* ActShoResMchTch */{1795,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ShowRessQstMatchTch ,NULL}, /* ActPrvQstMchTch */{1790,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_PrevQstMatchTch ,NULL}, /* ActNxtQstMchTch */{1672,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_NextQstMatchTch ,NULL}, - /* ActChgDisResMchTch*/{1794,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_CurrQstMatchTch ,NULL}, + /* ActChgShoResMchTch*/{1794,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_CurrQstMatchTch ,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}, @@ -5015,7 +5017,8 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActPauMchTch, // #1791 ActShoSteMchTch, // #1792 ActShoAnsMchTch, // #1793 - ActChgDisResMchTch, // #1794 + ActChgShoResMchTch, // #1794 + ActShoResMchTch, // #1795 }; /*****************************************************************************/ diff --git a/swad_action.h b/swad_action.h index dd64dd343..64651f3c7 100644 --- a/swad_action.h +++ b/swad_action.h @@ -64,9 +64,9 @@ typedef enum typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action -#define Act_NUM_ACTIONS (1 + 4 + 64 + 38 + 12 + 42 + 36 + 19 + 110 + 175 + 437 + 176 + 169 + 16 + 68) +#define Act_NUM_ACTIONS (1 + 4 + 64 + 38 + 12 + 42 + 36 + 19 + 110 + 176 + 437 + 176 + 169 + 16 + 68) -#define Act_MAX_ACTION_COD 1794 +#define Act_MAX_ACTION_COD 1795 #define Act_MAX_OPTIONS_IN_MENU_PER_TAB 13 @@ -616,58 +616,59 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActPlyMchTch (ActChgCrsTT1stDay + 123) #define ActShoSteMchTch (ActChgCrsTT1stDay + 124) #define ActShoAnsMchTch (ActChgCrsTT1stDay + 125) -#define ActPrvQstMchTch (ActChgCrsTT1stDay + 126) -#define ActNxtQstMchTch (ActChgCrsTT1stDay + 127) -#define ActChgDisResMchTch (ActChgCrsTT1stDay + 128) -#define ActRefMchTch (ActChgCrsTT1stDay + 129) -#define ActShoMchTch (ActChgCrsTT1stDay + 130) -#define ActPlyMchStd (ActChgCrsTT1stDay + 131) -#define ActRefMchStd (ActChgCrsTT1stDay + 132) -#define ActAnsMchQstStd (ActChgCrsTT1stDay + 133) -#define ActFrmNewGam (ActChgCrsTT1stDay + 134) -#define ActEdiOneGam (ActChgCrsTT1stDay + 135) -#define ActNewGam (ActChgCrsTT1stDay + 136) -#define ActChgGam (ActChgCrsTT1stDay + 137) -#define ActReqRemGam (ActChgCrsTT1stDay + 138) -#define ActRemGam (ActChgCrsTT1stDay + 139) -#define ActReqRstGam (ActChgCrsTT1stDay + 140) -#define ActRstGam (ActChgCrsTT1stDay + 141) -#define ActHidGam (ActChgCrsTT1stDay + 142) -#define ActShoGam (ActChgCrsTT1stDay + 143) -#define ActAddOneGamQst (ActChgCrsTT1stDay + 144) -#define ActGamLstTstQst (ActChgCrsTT1stDay + 145) -#define ActAddTstQstToGam (ActChgCrsTT1stDay + 146) -#define ActReqRemGamQst (ActChgCrsTT1stDay + 147) -#define ActRemGamQst (ActChgCrsTT1stDay + 148) -#define ActUp_GamQst (ActChgCrsTT1stDay + 149) -#define ActDwnGamQst (ActChgCrsTT1stDay + 150) +#define ActShoResMchTch (ActChgCrsTT1stDay + 126) +#define ActPrvQstMchTch (ActChgCrsTT1stDay + 127) +#define ActNxtQstMchTch (ActChgCrsTT1stDay + 128) +#define ActChgShoResMchTch (ActChgCrsTT1stDay + 129) +#define ActRefMchTch (ActChgCrsTT1stDay + 130) +#define ActShoMchTch (ActChgCrsTT1stDay + 131) +#define ActPlyMchStd (ActChgCrsTT1stDay + 132) +#define ActRefMchStd (ActChgCrsTT1stDay + 133) +#define ActAnsMchQstStd (ActChgCrsTT1stDay + 134) +#define ActFrmNewGam (ActChgCrsTT1stDay + 135) +#define ActEdiOneGam (ActChgCrsTT1stDay + 136) +#define ActNewGam (ActChgCrsTT1stDay + 137) +#define ActChgGam (ActChgCrsTT1stDay + 138) +#define ActReqRemGam (ActChgCrsTT1stDay + 139) +#define ActRemGam (ActChgCrsTT1stDay + 140) +#define ActReqRstGam (ActChgCrsTT1stDay + 141) +#define ActRstGam (ActChgCrsTT1stDay + 142) +#define ActHidGam (ActChgCrsTT1stDay + 143) +#define ActShoGam (ActChgCrsTT1stDay + 144) +#define ActAddOneGamQst (ActChgCrsTT1stDay + 145) +#define ActGamLstTstQst (ActChgCrsTT1stDay + 146) +#define ActAddTstQstToGam (ActChgCrsTT1stDay + 147) +#define ActReqRemGamQst (ActChgCrsTT1stDay + 148) +#define ActRemGamQst (ActChgCrsTT1stDay + 149) +#define ActUp_GamQst (ActChgCrsTT1stDay + 150) +#define ActDwnGamQst (ActChgCrsTT1stDay + 151) -#define ActSeeSvy (ActChgCrsTT1stDay + 151) -#define ActAnsSvy (ActChgCrsTT1stDay + 152) -#define ActFrmNewSvy (ActChgCrsTT1stDay + 153) -#define ActEdiOneSvy (ActChgCrsTT1stDay + 154) -#define ActNewSvy (ActChgCrsTT1stDay + 155) -#define ActChgSvy (ActChgCrsTT1stDay + 156) -#define ActReqRemSvy (ActChgCrsTT1stDay + 157) -#define ActRemSvy (ActChgCrsTT1stDay + 158) -#define ActReqRstSvy (ActChgCrsTT1stDay + 159) -#define ActRstSvy (ActChgCrsTT1stDay + 160) -#define ActHidSvy (ActChgCrsTT1stDay + 161) -#define ActShoSvy (ActChgCrsTT1stDay + 162) -#define ActEdiOneSvyQst (ActChgCrsTT1stDay + 163) -#define ActRcvSvyQst (ActChgCrsTT1stDay + 164) -#define ActReqRemSvyQst (ActChgCrsTT1stDay + 165) -#define ActRemSvyQst (ActChgCrsTT1stDay + 166) +#define ActSeeSvy (ActChgCrsTT1stDay + 152) +#define ActAnsSvy (ActChgCrsTT1stDay + 153) +#define ActFrmNewSvy (ActChgCrsTT1stDay + 154) +#define ActEdiOneSvy (ActChgCrsTT1stDay + 155) +#define ActNewSvy (ActChgCrsTT1stDay + 156) +#define ActChgSvy (ActChgCrsTT1stDay + 157) +#define ActReqRemSvy (ActChgCrsTT1stDay + 158) +#define ActRemSvy (ActChgCrsTT1stDay + 159) +#define ActReqRstSvy (ActChgCrsTT1stDay + 160) +#define ActRstSvy (ActChgCrsTT1stDay + 161) +#define ActHidSvy (ActChgCrsTT1stDay + 162) +#define ActShoSvy (ActChgCrsTT1stDay + 163) +#define ActEdiOneSvyQst (ActChgCrsTT1stDay + 164) +#define ActRcvSvyQst (ActChgCrsTT1stDay + 165) +#define ActReqRemSvyQst (ActChgCrsTT1stDay + 166) +#define ActRemSvyQst (ActChgCrsTT1stDay + 167) -#define ActSeeOneExaAnn (ActChgCrsTT1stDay + 167) -#define ActSeeDatExaAnn (ActChgCrsTT1stDay + 168) -#define ActEdiExaAnn (ActChgCrsTT1stDay + 169) -#define ActRcvExaAnn (ActChgCrsTT1stDay + 170) -#define ActPrnExaAnn (ActChgCrsTT1stDay + 171) -#define ActReqRemExaAnn (ActChgCrsTT1stDay + 172) -#define ActRemExaAnn (ActChgCrsTT1stDay + 173) -#define ActHidExaAnn (ActChgCrsTT1stDay + 174) -#define ActShoExaAnn (ActChgCrsTT1stDay + 175) +#define ActSeeOneExaAnn (ActChgCrsTT1stDay + 168) +#define ActSeeDatExaAnn (ActChgCrsTT1stDay + 169) +#define ActEdiExaAnn (ActChgCrsTT1stDay + 170) +#define ActRcvExaAnn (ActChgCrsTT1stDay + 171) +#define ActPrnExaAnn (ActChgCrsTT1stDay + 172) +#define ActReqRemExaAnn (ActChgCrsTT1stDay + 173) +#define ActRemExaAnn (ActChgCrsTT1stDay + 174) +#define ActHidExaAnn (ActChgCrsTT1stDay + 175) +#define ActShoExaAnn (ActChgCrsTT1stDay + 176) /*****************************************************************************/ /******************************** Files tab **********************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 8f8ffe418..b12dec6d4 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -460,10 +460,16 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.143 (2019-09-10)" +#define Log_PLATFORM_VERSION "SWAD 18.144 (2019-09-10)" #define CSS_FILE "swad18.138.css" #define JS_FILE "swad18.130.2.js" /* + Version 18.144: Sep 10, 2019 Show question results in match. (244641 lines) + 3 changes necessary in database: +ALTER TABLE gam_matches DROP COLUMN ShowingAnswers,DROP COLUMN ShowResults; +ALTER TABLE gam_matches ADD COLUMN ShowResults ENUM('N','Y') NOT NULL DEFAULT 'N' AFTER QstStartTime; +ALTER TABLE gam_matches ADD COLUMN Showing ENUM('stem','answers','results') NOT NULL DEFAULT 'stem' AFTER ShowResults; + Version 18.143: Sep 10, 2019 Checkbox to show results in matches. (244543 lines) 2 changes necessary in database: ALTER TABLE gam_matches ADD COLUMN ShowResults ENUM('N','Y') NOT NULL DEFAULT 'N' AFTER ShowingAnswers; diff --git a/swad_database.c b/swad_database.c index 02a7d8d68..82691bb66 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1369,21 +1369,21 @@ mysql> DESCRIBE gam_grp; /***** Table gam_matches *****/ /* mysql> DESCRIBE gam_matches; -+----------------+---------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+----------------+---------------+------+-----+---------+----------------+ -| MchCod | int(11) | NO | PRI | NULL | auto_increment | -| GamCod | int(11) | NO | MUL | NULL | | -| UsrCod | int(11) | NO | | NULL | | -| StartTime | datetime | NO | | NULL | | -| EndTime | datetime | NO | | NULL | | -| Title | varchar(2047) | NO | | NULL | | -| QstInd | int(11) | NO | | 0 | | -| QstCod | int(11) | NO | | -1 | | -| QstStartTime | datetime | NO | | NULL | | -| ShowingAnswers | enum('N','Y') | NO | | N | | -| ShowResults | enum('N','Y') | NO | | N | | -+----------------+---------------+------+-----+---------+----------------+ ++--------------+----------------------------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++--------------+----------------------------------+------+-----+---------+----------------+ +| MchCod | int(11) | NO | PRI | NULL | auto_increment | +| GamCod | int(11) | NO | MUL | NULL | | +| UsrCod | int(11) | NO | | NULL | | +| StartTime | datetime | NO | | NULL | | +| EndTime | datetime | NO | | NULL | | +| Title | varchar(2047) | NO | | NULL | | +| QstInd | int(11) | NO | | 0 | | +| QstCod | int(11) | NO | | -1 | | +| QstStartTime | datetime | NO | | NULL | | +| ShowResults | enum('N','Y') | NO | | N | | +| Showing | enum('stem','answers','results') | NO | | stem | | ++--------------+----------------------------------+------+-----+---------+----------------+ 11 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_matches (" @@ -1396,8 +1396,8 @@ mysql> DESCRIBE gam_matches; "QstInd INT NOT NULL DEFAULT 0," "QstCod INT NOT NULL DEFAULT -1," "QstStartTime DATETIME NOT NULL," - "ShowingAnswers ENUM('N','Y') NOT NULL DEFAULT 'N'," "ShowResults ENUM('N','Y') NOT NULL DEFAULT 'N'," + "Showing ENUM('stem','answers','results') NOT NULL DEFAULT 'stem'," "UNIQUE INDEX(MchCod)," "INDEX(GamCod)"); diff --git a/swad_game.c b/swad_game.c index eac21d9e9..e6e0ac66b 100644 --- a/swad_game.c +++ b/swad_game.c @@ -88,19 +88,29 @@ const char *Gam_StrAnswerTypesDB[Gam_NUM_ANS_TYPES] = #define Gam_ICON_CLOSE "fas fa-times" #define Gam_ICON_PLAY "fas fa-play" #define Gam_ICON_PAUSE "fas fa-pause" -#define Gam_ICON_STEM "fas fa-step-backward" -// #define Gam_ICON_STEM "fas fa-angle-up" -#define Gam_ICON_START "fas fa-step-backward" #define Gam_ICON_PREVIOUS "fas fa-step-backward" -#define Gam_ICON_FINISH "fas fa-step-forward" #define Gam_ICON_NEXT "fas fa-step-forward" -#define Gam_ICON_ANSWERS "fas fa-step-forward" -// #define Gam_ICON_ANSWERS "fas fa-angle-down" /*****************************************************************************/ /******************************* Private types *******************************/ /*****************************************************************************/ +#define Gam_NUM_SHOWING 3 +typedef enum + { + Gam_SHOWING_WORDING, // Showing only the question wording + Gam_SHOWING_ANSWERS, // Showing the question wording and the answers + Gam_REQUEST_RESULTS, // Requesting confirmation to show the results + Gam_SHOWING_RESULTS, // Showing the results + } Gam_Showing_t; +#define Gam_SHOWING_DEFAULT Gam_SHOWING_WORDING +const char *Gam_ShowingStringsDB[Gam_NUM_SHOWING] = + { + "stem", + "answers", + "results", + }; + struct Match { long MchCod; @@ -113,8 +123,8 @@ struct Match unsigned QstInd; // 0 means that the game has not started. First question has index 0. long QstCod; time_t QstStartTimeUTC; - bool ShowingAnswers; bool ShowResults; + Gam_Showing_t Showing; bool BeingPlayed; unsigned NumPlayers; } Status; @@ -171,6 +181,7 @@ static unsigned Gam_GetParamQstInd (void); static void Gam_PutParamAnswer (unsigned AnsInd); static unsigned Gam_GetParamAnswer (void); static unsigned Gam_GetQstIndFromStr (const char *UnsignedStr); +static Gam_Showing_t Gam_GetShowingFromStr (const char *Str); static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd); static long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd); @@ -1790,6 +1801,23 @@ static unsigned Gam_GetQstIndFromStr (const char *UnsignedStr) 0; } +/*****************************************************************************/ +/****************** Get parameter with what is being shown *******************/ +/*****************************************************************************/ + +static Gam_Showing_t Gam_GetShowingFromStr (const char *Str) + { + Gam_Showing_t Showing; + + for (Showing = (Gam_Showing_t) 0; + Showing <= (Gam_Showing_t) (Gam_NUM_SHOWING - 1); + Showing++) + if (!strcmp (Str,Gam_ShowingStringsDB[Showing])) + return Showing; + + return (Gam_Showing_t) Gam_SHOWING_DEFAULT; + } + /*****************************************************************************/ /********************** Remove answers of a game question ********************/ /*****************************************************************************/ @@ -2700,11 +2728,11 @@ static void Gam_ListMatches (struct Game *Game,bool PutFormNewMatch) "UNIX_TIMESTAMP(StartTime)," // row[ 3] "UNIX_TIMESTAMP(EndTime)," // row[ 4] "Title," // row[ 5] - "QstInd," // row[ 6] - "QstCod," // row[ 7] - "UNIX_TIMESTAMP(QstStartTime)," // row[ 8] - "ShowingAnswers," // row[ 9] - "ShowResults" // row[10] + "ShowResults," // row[ 6] + "QstInd," // row[ 7] + "QstCod," // row[ 8] + "UNIX_TIMESTAMP(QstStartTime)," // row[ 9] + "Showing" // row[10] " FROM gam_matches" " WHERE GamCod=%ld%s" " ORDER BY MchCod", @@ -2762,11 +2790,11 @@ void Gam_GetDataOfMatchByCod (struct Match *Match) "UNIX_TIMESTAMP(StartTime)," // row[ 3] "UNIX_TIMESTAMP(EndTime)," // row[ 4] "Title," // row[ 5] - "QstInd," // row[ 6] - "QstCod," // row[ 7] - "UNIX_TIMESTAMP(QstStartTime)," // row[ 8] - "ShowingAnswers," // row[ 9] - "ShowResults" // row[10] + "ShowResults," // row[ 6] + "QstInd," // row[ 7] + "QstCod," // row[ 8] + "UNIX_TIMESTAMP(QstStartTime)," // row[ 9] + "Showing" // row[10] " FROM gam_matches" " WHERE MchCod=%ld" " AND GamCod IN" // Extra check @@ -2789,8 +2817,8 @@ void Gam_GetDataOfMatchByCod (struct Match *Match) Match->Status.QstInd = 0; Match->Status.QstCod = -1L; Match->Status.QstStartTimeUTC = (time_t) 0; - Match->Status.ShowingAnswers = false; Match->Status.ShowResults = false; + Match->Status.Showing = Gam_SHOWING_WORDING; Match->Status.BeingPlayed = false; } @@ -3000,6 +3028,7 @@ static void Gam_GetMatchDataFromRow (MYSQL_RES *mysql_res, row[ 3] UNIX_TIMESTAMP(StartTime) row[ 4] UNIX_TIMESTAMP(EndTime) row[ 5] Title + row[ 6] ShowResults */ /***** Get match data *****/ /* Code of the match (row[0]) */ @@ -3026,28 +3055,27 @@ static void Gam_GetMatchDataFromRow (MYSQL_RES *mysql_res, else Match->Title[0] = '\0'; + /* Get whether to show results or not (row(6)) */ + Match->Status.ShowResults = (row[6][0] == 'Y'); + /***** Get current match status *****/ /* - row[ 6] QstInd - row[ 7] QstCod - row[ 8] UNIX_TIMESTAMP(QstStartTime) - row[ 9] ShowingAnswers - row[10] ShowResults + row[ 7] QstInd + row[ 8] QstCod + row[ 9] UNIX_TIMESTAMP(QstStartTime) + row[10] Showing */ - /* Current question index (row[6]) */ - Match->Status.QstInd = Gam_GetQstIndFromStr (row[6]); + /* Current question index (row[7]) */ + Match->Status.QstInd = Gam_GetQstIndFromStr (row[7]); - /* Current question code (row[7]) */ - Match->Status.QstCod = Str_ConvertStrCodToLongCod (row[7]); + /* Current question code (row[8]) */ + Match->Status.QstCod = Str_ConvertStrCodToLongCod (row[8]); - /* Get question start date (row[8] holds the start UTC time) */ - Match->Status.QstStartTimeUTC = Dat_GetUNIXTimeFromStr (row[8]); + /* Get question start date (row[9] holds the start UTC time) */ + Match->Status.QstStartTimeUTC = Dat_GetUNIXTimeFromStr (row[9]); - /* Get whether to show question answers or not (row(9)) */ - Match->Status.ShowingAnswers = (row[9][0] == 'Y'); - - /* Get whether to show results or not (row(10)) */ - Match->Status.ShowResults = (row[10][0] == 'Y'); + /* Get what to show (stem, answers, results) (row(10)) */ + Match->Status.Showing = Gam_GetShowingFromStr (row[10]); /***** Get whether the match is being played or not *****/ if (Match->Status.QstInd >= Gam_AFTER_LAST_QUESTION) // Finished @@ -3332,23 +3360,23 @@ static long Gam_CreateMatch (long GamCod,char Title[Gam_MAX_BYTES_TITLE + 1]) /***** Insert this new match into database *****/ MchCod = DB_QueryINSERTandReturnCode ("can not create match", "INSERT gam_matches" - " (GamCod,UsrCod,StartTime,EndTime,Title," - "QstInd,QstCod,QstStartTime," - "ShowingAnswers,ShowResults)" + " (GamCod,UsrCod,StartTime,EndTime,Title,ShowResults," + "QstInd,QstCod,QstStartTime,Showing)" " VALUES" " (%ld," // GamCod "%ld," // UsrCod "NOW()," // StartTime "NOW()," // EndTime "'%s'," // Title + "'N'," // ShowResults: Don't show results initially "0," // QstInd: Match has not started, so not the first question yet "-1," // QstCod: Non-existent question "NOW()," // QstStartTime - "'N'," // ShowingAnswers: Don't show answers initially - "'N')", // ShowResults: Don't show results initially + "'%s'", // What is being shown GamCod, Gbl.Usrs.Me.UsrDat.UsrCod, // Game creator - Title); + Title, + Gam_ShowingStringsDB[Gam_SHOWING_DEFAULT]); /***** Create groups associated to the match *****/ if (Gbl.Crs.Grps.LstGrpsSel.NumGrps) @@ -3370,16 +3398,12 @@ static void Gam_UpdateMatchStatusInDB (struct Match *Match) "gam_matches.QstInd=%u," "gam_matches.QstCod=%ld," "gam_matches.QstStartTime=NOW()," - "gam_matches.ShowingAnswers='%c'," - "gam_matches.ShowResults='%c'" + "gam_matches.Showing='%s'" " WHERE gam_matches.MchCod=%ld" " AND gam_matches.GamCod=games.GamCod" " AND games.CrsCod=%ld", // Extra check Match->Status.QstInd,Match->Status.QstCod, - Match->Status.ShowingAnswers ? 'Y' : - 'N', - Match->Status.ShowResults ? 'Y' : - 'N', + Gam_ShowingStringsDB[Match->Status.Showing], Match->MchCod,Gbl.Hierarchy.Crs.CrsCod); if (Match->Status.BeingPlayed) @@ -3563,7 +3587,7 @@ void Gam_ShowStemQstMatchTch (void) Gam_GetDataOfMatchByCod (&Match); /***** Update status *****/ - Match.Status.ShowingAnswers = false; // Do not show answers + Match.Status.Showing = Gam_SHOWING_WORDING; // Show only the stem /***** Update match status in database *****/ Gam_UpdateMatchStatusInDB (&Match); @@ -3591,7 +3615,35 @@ void Gam_ShowAnssQstMatchTch (void) Gam_GetDataOfMatchByCod (&Match); /***** Update status *****/ - Match.Status.ShowingAnswers = true; // Show answers + Match.Status.Showing = Gam_SHOWING_ANSWERS; // Show answers + + /***** Update match status in database *****/ + Gam_UpdateMatchStatusInDB (&Match); + + /***** Show current match status *****/ + fprintf (Gbl.F.Out,"
"); + Gam_ShowMatchStatusForTch (&Match); + fprintf (Gbl.F.Out,"
"); + } + +/*****************************************************************************/ +/******** Show results of current question in a match (by a teacher) *********/ +/*****************************************************************************/ + +void Gam_ShowRessQstMatchTch (void) + { + struct Match Match; + + /***** Remove old players. + This function must be called before getting match status. *****/ + Gam_RemoveOldPlayers (); + + /***** Get data of the match from database *****/ + Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Gam_GetDataOfMatchByCod (&Match); + + /***** Update status *****/ + Match.Status.Showing = Gam_REQUEST_RESULTS; // Show results /***** Update match status in database *****/ Gam_UpdateMatchStatusInDB (&Match); @@ -3674,8 +3726,7 @@ void Gam_CurrQstMatchTch (void) Match.MchCod = Gbl.Games.MchCodBeingPlayed; Gam_GetDataOfMatchByCod (&Match); - /***** Get if results should be displayed *****/ - // Match.Status.ShowResults = Par_GetParToBool ("ShowResults"); + /***** Toggle display of results *****/ Match.Status.ShowResults = !Match.Status.ShowResults; /***** Update match status in database *****/ @@ -3704,7 +3755,17 @@ static void Gam_SetMatchStatusToPrevQuestion (struct Match *Match) else Match->Status.QstCod = Gam_GetQstCodFromQstInd (Match->GamCod, Match->Status.QstInd); - Match->Status.ShowingAnswers = Match->Status.BeingPlayed; // Show answers only if being played + + /***** What to show *****/ + if (Match->Status.BeingPlayed) + { + if (Match->Status.ShowResults) + Match->Status.Showing = Gam_REQUEST_RESULTS; // Show results + else + Match->Status.Showing = Gam_SHOWING_ANSWERS; // Show answers + } + else + Match->Status.Showing = Gam_SHOWING_WORDING; // Show only stem } /*****************************************************************************/ @@ -3724,7 +3785,7 @@ static void Gam_SetMatchStatusToNextQuestion (struct Match *Match) Match->Status.QstCod = -1L; // No more questions Match->Status.BeingPlayed = false; } - Match->Status.ShowingAnswers = false; // Don't show answers + Match->Status.Showing = Gam_SHOWING_WORDING; // Show only the stem } /*****************************************************************************/ @@ -3855,8 +3916,7 @@ static void Gam_ShowLeftColumnTch (struct Match *Match) Gam_ShowNumPlayers (Match); /***** Number of users who have answered *****/ - if (Match->Status.BeingPlayed && - Match->Status.ShowingAnswers) + if (Match->Status.BeingPlayed) { NumAnswerers = Gam_GetNumAnswerers (Match); fprintf (Gbl.F.Out,"
" @@ -3904,6 +3964,7 @@ static void Gam_PutMatchControlButtons (struct Match *Match) extern const char *Txt_Resume; extern const char *Txt_Next_QUESTION; extern const char *Txt_Answers; + extern const char *Txt_View_results; extern const char *Txt_Finish; unsigned PrvQstInd; // Previous question index unsigned NxtQstInd; // Next question index @@ -3915,17 +3976,33 @@ static void Gam_PutMatchControlButtons (struct Match *Match) fprintf (Gbl.F.Out,"
"); if (Match->Status.QstInd < Gam_AFTER_LAST_QUESTION) // Unfinished { - if (Match->Status.BeingPlayed && - Match->Status.ShowingAnswers) - /* Put button to show stem of current question, hiding answers */ - Gam_PutBigButton (ActShoSteMchTch,Match->MchCod, - Gam_ICON_STEM,Txt_Stem); + if (Match->Status.BeingPlayed) + { + switch (Match->Status.Showing) + { + case Gam_SHOWING_WORDING: + /* Put button to show stem of current question, hiding answers */ + Gam_PutBigButton (ActPrvQstMchTch,Match->MchCod, + Gam_ICON_PREVIOUS,Txt_Previous_QUESTION); + break; + case Gam_SHOWING_ANSWERS: + /* Put button to show stem of current question, hiding answers */ + Gam_PutBigButton (ActShoSteMchTch,Match->MchCod, + Gam_ICON_PREVIOUS,Txt_Stem); + break; + case Gam_REQUEST_RESULTS: + /* Put button to show stem of current question, hiding answers */ + Gam_PutBigButton (ActShoAnsMchTch,Match->MchCod, + Gam_ICON_PREVIOUS,Txt_Stem); + break; + } + } else if (Match->Status.QstInd == 0) { if (Match->Status.BeingPlayed) /* Put button to go to start of match before first question */ Gam_PutBigButton (ActPrvQstMchTch,Match->MchCod, - Gam_ICON_START,Txt_MATCH_Start); + Gam_ICON_PREVIOUS,Txt_MATCH_Start); else // Not being played /* Put button to close browser tab */ Gam_PutBigButtonClose (); @@ -3938,7 +4015,7 @@ static void Gam_PutMatchControlButtons (struct Match *Match) if (PrvQstInd == 0) // There is not a previous question /* Put button to resume match before first question */ Gam_PutBigButton (ActPrvQstMchTch,Match->MchCod, - Gam_ICON_START,Txt_MATCH_Start); + Gam_ICON_PREVIOUS,Txt_MATCH_Start); else // There is a previous question /* Put button to show previous question */ Gam_PutBigButton (ActPrvQstMchTch,Match->MchCod, @@ -3982,24 +4059,46 @@ static void Gam_PutMatchControlButtons (struct Match *Match) /* Get index of the next question */ NxtQstInd = Gam_GetNextQuestionIndexInGame (Match->GamCod, Match->Status.QstInd); - if (Match->Status.BeingPlayed && - !Match->Status.ShowingAnswers) + if (Match->Status.BeingPlayed) // Being played { - if (Match->Status.QstInd == 0) - /* Put button to show first question */ - Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, - Gam_ICON_NEXT,Txt_Next_QUESTION); - else - /* Put button to show answers */ - Gam_PutBigButton (ActShoAnsMchTch,Match->MchCod, - Gam_ICON_ANSWERS,Txt_Answers); + if (Match->Status.Showing == Gam_SHOWING_WORDING) // Not showing answers + { + if (Match->Status.QstInd == 0) + /* Put button to show first question */ + Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, + Gam_ICON_NEXT,Txt_Next_QUESTION); + else + /* Put button to show answers */ + Gam_PutBigButton (ActShoAnsMchTch,Match->MchCod, + Gam_ICON_NEXT,Txt_Answers); + } + else // Showing answers + { + if (Match->Status.ShowResults) // Show results + { + /* Put button to show results */ + Gam_PutBigButton (ActShoResMchTch,Match->MchCod, + Gam_ICON_NEXT,Txt_View_results); + } + else // Don't show results + { + if (NxtQstInd >= Gam_AFTER_LAST_QUESTION) // No more questions + /* Put button to finish */ + Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, + Gam_ICON_NEXT,Txt_Finish); + else // There are more questions + /* Put button to show next question */ + Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, + Gam_ICON_NEXT,Txt_Next_QUESTION); + } + } } - else + else // Not being played { if (NxtQstInd >= Gam_AFTER_LAST_QUESTION) // No more questions /* Put button to finish */ Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, - Gam_ICON_FINISH,Txt_Finish); + Gam_ICON_NEXT,Txt_Finish); else // There are more questions /* Put button to show next question */ Gam_PutBigButton (ActNxtQstMchTch,Match->MchCod, @@ -4024,7 +4123,7 @@ static void Gam_PutCheckboxResult (struct Match *Match) fprintf (Gbl.F.Out,"
"); /***** Start form *****/ - Frm_StartForm (ActChgDisResMchTch); + Frm_StartForm (ActChgShoResMchTch); Gam_PutParamMatchCod (Match->MchCod); // Current match being played /***** Put icon with link *****/ @@ -4142,7 +4241,7 @@ static void Gam_ShowQuestionAndAnswersTch (struct Match *Match) "TEST_MED_EDIT_LIST_STEM"); /* Write answers? */ - if (Match->Status.ShowingAnswers) + if (Match->Status.Showing == Gam_SHOWING_ANSWERS) /* Write answers */ Tst_WriteAnswersGameResult (Match->GamCod, Match->Status.QstInd, @@ -4169,7 +4268,7 @@ static void Gam_ShowQuestionAndAnswersStd (struct Match *Match) /***** Show question *****/ /* Write buttons for answers? */ - if (Match->Status.ShowingAnswers) + if (Match->Status.Showing == Gam_SHOWING_ANSWERS) { if (Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod)) { diff --git a/swad_game.h b/swad_game.h index d3c7d50b9..4d86a3771 100644 --- a/swad_game.h +++ b/swad_game.h @@ -125,6 +125,7 @@ void Gam_PauseMatchTch (void); void Gam_ResumeMatchTch (void); void Gam_ShowStemQstMatchTch (void); void Gam_ShowAnssQstMatchTch (void); +void Gam_ShowRessQstMatchTch (void); void Gam_PrevQstMatchTch (void); void Gam_NextQstMatchTch (void); void Gam_CurrQstMatchTch (void); diff --git a/swad_layout.c b/swad_layout.c index 41f3f2f5c..807a4083c 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -700,9 +700,10 @@ static void Lay_WriteScriptInit (void) case ActPlyMchTch: case ActShoSteMchTch: case ActShoAnsMchTch: + case ActShoResMchTch: case ActPrvQstMchTch: case ActNxtQstMchTch: - case ActChgDisResMchTch: + case ActChgShoResMchTch: case ActPlyMchStd: case ActAnsMchQstStd: RefreshGame = true; @@ -825,9 +826,10 @@ static void Lay_WriteScriptParamsAJAX (void) case ActPlyMchTch: case ActShoSteMchTch: case ActShoAnsMchTch: + case ActShoResMchTch: case ActPrvQstMchTch: case ActNxtQstMchTch: - case ActChgDisResMchTch: + case ActChgShoResMchTch: fprintf (Gbl.F.Out,"var RefreshParamNxtActGam = \"act=%ld\";\n" "var RefreshParamMchCod = \"MchCod=%ld\";\n", Act_GetActCod (ActRefMchTch),