diff --git a/sql/cambios.sql b/sql/cambios.sql index 71550f867..ef9640cb9 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -12868,3 +12868,7 @@ SELECT COUNT(*) FROM degrees WHERE CtrCod=2 AND FullName='M SELECT UNIX_TIMESTAMP(MIN(StartTime)),UNIX_TIMESTAMP(MAX(EndTime)) FROM gam_matches WHERE GamCod=1; +---------------------- + + +SELECT MchCod,GamCod,UsrCod,UNIX_TIMESTAMP(StartTime),UNIX_TIMESTAMP(EndTime),Title,QstInd,QstCod,UNIX_TIMESTAMP(QstStartTime),ShowingAnswers,Finished FROM gam_matches WHERE GamCod=7 ORDER BY MchCod; diff --git a/swad_action.c b/swad_action.c index 855be5678..264f11b27 100644 --- a/swad_action.c +++ b/swad_action.c @@ -613,10 +613,10 @@ Assessment: 457. ActNxtMch Show next question when playing a game (by a teacher) NEW. ActShoMch Show finished match results - NEW. ActPlyMchStd Show current question when playing a game (by a student) - NEW. ActRefMchStd Refresh current question when playing a game (by a student) + NEW. ActPlyMchStd Show current question when playing a game (as student) + NEW. ActRefMchStd Refresh current question when playing a game (as student) + 459. ActAnsMchQstStd Answer a match question (as student) - 459. ActAnsGam Answer a game 460. ActFrmNewGam Form to create a new game 461. ActEdiOneGam Edit one game 462. ActNewGam Create new game @@ -2154,8 +2154,8 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* 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}, + /* ActAnsMchQstStd */{1651,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_204_NO_CONT,NULL ,Gam_ReceiveQstAnsFromStd ,NULL}, - /* ActAnsGam */{1651,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ReceiveGameAnswers ,NULL}, /* ActFrmNewGam */{1652,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, /* ActEdiOneGam */{1653,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL}, /* ActNewGam */{1654,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RecFormGame ,NULL}, @@ -4857,7 +4857,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActChgCtrPlcCfg, // #1648 ActSeeAllGam, // #1649 ActSeeGam, // #1650 - ActAnsGam, // #1651 + ActAnsMchQstStd, // #1651 ActFrmNewGam, // #1652 ActEdiOneGam, // #1653 ActNewGam, // #1654 diff --git a/swad_action.h b/swad_action.h index ee96c70fb..fab01cc48 100644 --- a/swad_action.h +++ b/swad_action.h @@ -616,7 +616,7 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActShoMch (ActChgCrsTT1stDay + 123) #define ActPlyMchStd (ActChgCrsTT1stDay + 124) #define ActRefMchStd (ActChgCrsTT1stDay + 125) -#define ActAnsGam (ActChgCrsTT1stDay + 126) +#define ActAnsMchQstStd (ActChgCrsTT1stDay + 126) #define ActFrmNewGam (ActChgCrsTT1stDay + 127) #define ActEdiOneGam (ActChgCrsTT1stDay + 128) #define ActNewGam (ActChgCrsTT1stDay + 129) diff --git a/swad_changelog.h b/swad_changelog.h index c12b80ff9..05f495926 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -458,10 +458,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.131 (2019-07-04)" +#define Log_PLATFORM_VERSION "SWAD 18.132 (2019-07-09)" #define CSS_FILE "swad18.131.css" #define JS_FILE "swad18.130.2.js" /* + Version 18.132: Jul 09, 2019 Reception of student answer to a match question. Not finished. (243461 lines) Version 18.131: Jul 04, 2019 Changes in matches. (243426 lines) Version 18.130.2: Jul 04, 2019 Changes in listing of games and matches for students. (243429 lines) 1 change necessary in database: diff --git a/swad_game.c b/swad_game.c index b1ec339c5..68519448c 100644 --- a/swad_game.c +++ b/swad_game.c @@ -172,8 +172,8 @@ static void Gam_ExchangeQuestions (long GamCod, static void Gam_ListMatches (struct Game *Game,bool PutFormNewMatch); static void Gam_PutIconToPlayNewMatch (void); static void Gam_ListOneOrMoreMatches (struct Game *Game, - unsigned NumMatches, - MYSQL_RES *mysql_res); + unsigned NumMatches, + MYSQL_RES *mysql_res); static void Gam_GetMatchDataFromRow (MYSQL_RES *mysql_res, struct Match *Match); static void Gam_PutButtonNewMatch (long GamCod); @@ -190,9 +190,9 @@ static void Gam_PutBigButton (long MchCod,const char *Txt,const char *Icon); static void Gam_ShowMatchStatusForStd (struct Match *Match); -static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod); +static void Gam_ReceiveAndStoreStdAnswerToQst (struct Match *Match); static void Gam_IncreaseAnswerInDB (long QstCod,unsigned AnsInd); -static void Gam_RegisterIHaveAnsweredGame (long GamCod); +// static void Gam_RegisterIHaveAnsweredGame (long GamCod); static bool Gam_CheckIfIHaveAnsweredGame (long GamCod); static unsigned Gam_GetNumUsrsWhoHaveAnsweredGame (long GamCod); @@ -840,7 +840,7 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /***** Get start and end times from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", "SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0] - "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] + "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] " FROM gam_matches" " WHERE GamCod=%ld", Game->GamCod); @@ -2785,8 +2785,8 @@ static void Gam_PutIconToPlayNewMatch (void) /*****************************************************************************/ static void Gam_ListOneOrMoreMatches (struct Game *Game, - unsigned NumMatches, - MYSQL_RES *mysql_res) + unsigned NumMatches, + MYSQL_RES *mysql_res) { extern const char *Txt_No_INDEX; extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; @@ -3617,8 +3617,13 @@ void Gam_RefreshCurrentMatchStd (void) static void Gam_ShowMatchStatusForStd (struct Match *Match) { bool IBelongToGroups; + bool Shuffle = false; // TODO: Read shuffle from question + MYSQL_RES *mysql_res; + MYSQL_ROW row; unsigned NumOptions; unsigned NumOpt; + unsigned Index; + bool ErrorInIndex = false; /***** Do I belong to valid groups to play this match? *****/ IBelongToGroups = Gbl.Usrs.Me.IBelongToCurrentCrs && @@ -3648,42 +3653,83 @@ static void Gam_ShowMatchStatusForStd (struct Match *Match) fprintf (Gbl.F.Out,"
"); - /* Write answers? */ + /* Write buttons for answers? */ if (Match->Status.ShowingAnswers) - { - if (Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod)) - { - /***** Start table *****/ - Tbl_StartTableWide (8); + { + if (Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod)) + { + /***** Start table *****/ + Tbl_StartTableWide (8); - /***** Write answers *****/ - NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod); - for (NumOpt = 0; - NumOpt < NumOptions; - NumOpt++) - { - // if (NumOpt % 2 == 0) - fprintf (Gbl.F.Out,""); + /***** Write answers *****/ + NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod); - /***** Write letter for this option *****/ - fprintf (Gbl.F.Out,"" - "
" - "%c" - "
" - "", - 'A' + (char) NumOpt, - 'a' + (char) NumOpt); + /***** Get answers of a question from database *****/ + Shuffle = false; + NumOptions = Tst_GetAnswersQst (Match->Status.QstCod,&mysql_res,Shuffle); + /* + row[0] AnsInd + row[1] Answer + row[2] Feedback + row[3] MedCod + row[4] Correct + */ - // if (NumOpt % 2 == 1) - fprintf (Gbl.F.Out,""); - } + for (NumOpt = 0; + NumOpt < NumOptions; + NumOpt++) + { + /***** Get next answer *****/ + row = mysql_fetch_row (mysql_res); - /***** End table *****/ - Tbl_EndTable (); - } - else - Ale_ShowAlert (Ale_ERROR,"Type of answer not valid in a game."); - } + /***** Assign index (row[0]). + Index is 0,1,2,3... if no shuffle + or 1,3,0,2... (example) if shuffle *****/ + if (sscanf (row[0],"%u",&Index) == 1) + { + if (Index >= Tst_MAX_OPTIONS_PER_QUESTION) + ErrorInIndex = true; + } + else + ErrorInIndex = true; + if (ErrorInIndex) + Lay_ShowErrorAndExit ("Wrong index of answer when showing a test."); + + /***** Start row *****/ + // if (NumOpt % 2 == 0) + fprintf (Gbl.F.Out,""); + + /***** Write letter for this option *****/ + /* Start table cell */ + fprintf (Gbl.F.Out,""); + + /* Form with button */ + Frm_StartForm (ActAnsMchQstStd); + Gam_PutParamMatchCod (Match->MchCod); // Current match being played + Gam_PutParamQstInd (Match->Status.QstInd); // Current question index shown + Par_PutHiddenParamUnsigned ("Ans",Index); // Index for this option + fprintf (Gbl.F.Out,"", + 'A' + (char) NumOpt, + 'a' + (char) NumOpt); + Frm_EndForm (); + + /* End table cell */ + fprintf (Gbl.F.Out,""); + + /***** End row *****/ + // if (NumOpt % 2 == 1) + fprintf (Gbl.F.Out,""); + } + + /***** End table *****/ + Tbl_EndTable (); + } + else + Ale_ShowAlert (Ale_ERROR,"Type of answer not valid in a game."); + } fprintf (Gbl.F.Out,"
"); } @@ -3691,44 +3737,31 @@ static void Gam_ShowMatchStatusForStd (struct Match *Match) } /*****************************************************************************/ -/************************ Receive answers of a game ************************/ +/********* Receive question answer from student when playing a match *********/ /*****************************************************************************/ -void Gam_ReceiveGameAnswers (void) +void Gam_ReceiveQstAnsFromStd (void) { - extern const char *Txt_You_already_played_this_game_before; extern const char *Txt_Thanks_for_playing_the_game; - struct Game Game; + struct Match Match; - /***** Get game code *****/ - if ((Game.GamCod = Gam_GetParamGameCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of game is missing."); + /***** Get match code *****/ + if ((Match.MchCod = Gam_GetParamMatchCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of match is missing."); - /***** Get data of the game from database *****/ - Gam_GetDataOfGameByCod (&Game); + /***** Get data of the match from database *****/ + Gam_GetDataOfMatchByCod (&Match); - /***** Check if I have no answered this game formerly *****/ - if (Game.Status.IHaveAnswered) - Ale_ShowAlert (Ale_WARNING,Txt_You_already_played_this_game_before); - else - { - /***** Receive and store user's answers *****/ - Gam_ReceiveAndStoreUserAnswersToAGame (Game.GamCod); - Ale_ShowAlert (Ale_INFO,Txt_Thanks_for_playing_the_game); - } - - /***** Show current game *****/ - Gam_ShowOneGame (Game.GamCod, - true, // Show only this game - true, // List game questions - false); // Do not put form to start new match + /***** Receive and store user's answer *****/ + Gam_ReceiveAndStoreStdAnswerToQst (&Match); + Ale_ShowAlert (Ale_INFO,Txt_Thanks_for_playing_the_game); } /*****************************************************************************/ -/**************** Get and store user's answers to a game *******************/ +/************* Get and store user's answer to a match question ***************/ /*****************************************************************************/ -static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod) +static void Gam_ReceiveAndStoreStdAnswerToQst (struct Match *Match) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -3741,11 +3774,17 @@ static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod) char UnsignedStr[10 + 1]; unsigned AnsInd; - /***** Get questions of this game from database *****/ + /***** Get question index from form *****/ + + + /***** Check that question index is the current one being played *****/ + + + /***** Get question of this game from database *****/ NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions of a game", "SELECT QstCod FROM gam_questions" " WHERE GamCod=%ld ORDER BY QstCod", - GamCod); + Match->GamCod); if (NumQsts) // The game has questions { /***** Get questions *****/ @@ -3784,7 +3823,7 @@ static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod) DB_FreeMySQLResult (&mysql_res); /***** Register that you have answered this game *****/ - Gam_RegisterIHaveAnsweredGame (GamCod); + // Gam_RegisterIHaveAnsweredGame (GamCod); } /*****************************************************************************/ @@ -3804,7 +3843,7 @@ static void Gam_IncreaseAnswerInDB (long QstCod,unsigned AnsInd) /*****************************************************************************/ /******************* Register that I have answered a game ********************/ /*****************************************************************************/ - +/* static void Gam_RegisterIHaveAnsweredGame (long GamCod) { DB_QueryINSERT ("can not register that you have answered the game", @@ -3814,7 +3853,7 @@ static void Gam_RegisterIHaveAnsweredGame (long GamCod) " (%ld,%ld)", GamCod,Gbl.Usrs.Me.UsrDat.UsrCod); } - +*/ /*****************************************************************************/ /******************** Check if I have answered a game ************************/ /*****************************************************************************/ diff --git a/swad_game.h b/swad_game.h index 2dbb54a5c..d4c462ffd 100644 --- a/swad_game.h +++ b/swad_game.h @@ -123,7 +123,7 @@ void Gam_RemoveMatch (void); void Gam_RequestNewMatch (void); // void Gam_PlayMatchStd (void); -void Gam_ReceiveGameAnswers (void); +void Gam_ReceiveQstAnsFromStd (void); void Gam_CreateNewMatch (void); void Gam_ResumeUnfinishedMatch (void); void Gam_NextStatusMatch (void); diff --git a/swad_text.c b/swad_text.c index e658bd70a..705cfea77 100644 --- a/swad_text.c +++ b/swad_text.c @@ -53741,7 +53741,7 @@ const char *Txt_You_already_answered_this_survey_before = #elif L==9 // pt "Você já respondeu a esso inquérito antes."; #endif - +/* const char *Txt_You_already_played_this_game_before = #if L==1 // ca "Vostè ja ha jugat aquest joc abans."; @@ -53762,7 +53762,7 @@ const char *Txt_You_already_played_this_game_before = #elif L==9 // pt "Você já jogou este jogo antes."; #endif - +*/ const char *Txt_You_are_now_LOGGED_IN_as_X = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "Vostè està ara %s com a %s.";