diff --git a/sql/cambios.sql b/sql/cambios.sql index ef9640cb9..e5f1fb4a2 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -12872,3 +12872,10 @@ SELECT UNIX_TIMESTAMP(MIN(StartTime)),UNIX_TIMESTAMP(MAX(EndTime)) FROM gam_matc 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; + + +REPLACE gam_time (MchCod,QstInd,ElapsedTime) VALUES (61,1,ADDTIME(ElapsedTime,SEC_TO_TIME(1))); + +INSERT INTO gam_time (MchCod,QstInd) VALUES (61,1,SEC_TO_TIME(1)) ON DUPLICATE KEY UPDATE ElapsedTime=ADDTIME(ElapsedTime,SEC_TO_TIME(1)); + + diff --git a/sql/swad.sql b/sql/swad.sql index 4f344d22e..268857379 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -667,6 +667,14 @@ CREATE TABLE IF NOT EXISTS gam_questions ( INDEX(GamCod), INDEX(QstCod)); -- +-- Table gam_time: stores the elapsed time in every question in every match played +-- +CREATE TABLE IF NOT EXISTS gam_time ( + MchCod INT NOT NULL, + QstInd INT NOT NULL, + ElapsedTime TIME NOT NULL DEFAULT 0, + UNIQUE INDEX(MchCod,QstInd)); +-- -- Table hidden_params: stores some hidden parameters passed from a page to another using database instead of forms -- CREATE TABLE IF NOT EXISTS hidden_params ( diff --git a/swad_changelog.h b/swad_changelog.h index c5a410a26..29b375181 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -460,12 +460,15 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.138.6 (2019-08-02)" +#define Log_PLATFORM_VERSION "SWAD 18.139 (2019-08-03)" #define CSS_FILE "swad18.138.css" #define JS_FILE "swad18.130.2.js" /* - Version 18.138.7: Aug 01, 2019 Time of current match and current match question are stored in database. (? lines) - Version 18.138.6: Aug 02, 2019 Matches finished can be played again from list of matches. (? lines) + Version 18.139: Aug 03, 2019 Time of current match and current match question are stored in database. (244150 lines) + 1 change necessary in database: +CREATE TABLE IF NOT EXISTS gam_time (MchCod INT NOT NULL,QstInd INT NOT NULL,ElapsedTime TIME NOT NULL DEFAULT 0,UNIQUE INDEX(MchCod,QstInd)); + + Version 18.138.6: Aug 02, 2019 Matches finished can be played again from list of matches. (244102 lines) Version 18.138.5: Aug 01, 2019 Finished column in matches replaced by a special value in question index. (244108 lines) 1 change necessary in database: ALTER TABLE gam_matches DROP COLUMN Finished; diff --git a/swad_database.c b/swad_database.c index cbe34fc83..ecc749afe 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1452,6 +1452,24 @@ mysql> DESCRIBE gam_questions; "INDEX(GamCod)," "INDEX(QstCod))"); + /***** Table gam_time *****/ +/* +mysql> DESCRIBE gam_time; ++-------------+---------+------+-----+----------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------------+---------+------+-----+----------+-------+ +| MchCod | int(11) | NO | PRI | NULL | | +| QstInd | int(11) | NO | PRI | NULL | | +| ElapsedTime | time | NO | | 00:00:00 | | ++-------------+---------+------+-----+----------+-------+ +3 rows in set (0.00 sec) +*/ + DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_time (" + "MchCod INT NOT NULL," + "QstInd INT NOT NULL," + "ElapsedTime TIME NOT NULL DEFAULT 0," + "UNIQUE INDEX(MchCod,QstInd))"); + /***** Table hidden_params *****/ /* mysql> DESCRIBE hidden_params; diff --git a/swad_game.c b/swad_game.c index 18a1aa570..d54a5aab9 100644 --- a/swad_game.c +++ b/swad_game.c @@ -187,6 +187,7 @@ static void Gam_PutFormNewMatch (struct Game *Game); static long Gam_CreateMatch (long GamCod,char Title[Gam_MAX_BYTES_TITLE + 1]); static void Gam_UpdateMatchStatusInDB (struct Match *Match); +static void Gam_UpdateElapsedTimeInQuestion (struct Match *Match); static void Gam_SetMatchStatusToPrevQuestion (struct Match *Match); static void Gam_SetMatchStatusToNextQuestion (struct Match *Match); @@ -3342,6 +3343,26 @@ static void Gam_UpdateMatchStatusInDB (struct Match *Match) Gam_SetMatchAsNotBeingPlayed (Match->MchCod); } +/*****************************************************************************/ +/** Update elapsed time in current question (by a teacher) **/ +/*****************************************************************************/ + +static void Gam_UpdateElapsedTimeInQuestion (struct Match *Match) + { + /***** Update elapsed time in current question in database *****/ + if (Match->Status.BeingPlayed && + Match->Status.QstInd > 0 && + Match->Status.QstInd < Gam_AFTER_LAST_QUESTION) + DB_QueryINSERT ("can not update elapsed time in question", + "INSERT INTO gam_time (MchCod,QstInd,ElapsedTime)" + " VALUES (%ld,%u,SEC_TO_TIME(%u))" + " ON DUPLICATE KEY" + " UPDATE ElapsedTime=ADDTIME(ElapsedTime,SEC_TO_TIME(%u))", + Match->MchCod,Match->Status.QstInd, + Cfg_SECONDS_TO_REFRESH_GAME, + Cfg_SECONDS_TO_REFRESH_GAME); + } + /*****************************************************************************/ /** Show current match status (current question, answers...) (by a teacher) **/ /*****************************************************************************/ @@ -4168,6 +4189,9 @@ void Gam_RefreshMatchTch (void) /***** Update match status in database *****/ Gam_UpdateMatchStatusInDB (&Match); + /***** Update elapsed time in this question *****/ + Gam_UpdateElapsedTimeInQuestion (&Match); + /***** Show current match status *****/ Gam_ShowMatchStatusForTch (&Match); }