From 51f1483a772771ee1070c652d5cb756e43acf5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sat, 3 Aug 2019 16:34:05 +0200 Subject: [PATCH] Version18.139.1 --- swad_changelog.h | 3 +- swad_game.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 29b375181..e9da5eeaa 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -460,10 +460,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.139 (2019-08-03)" +#define Log_PLATFORM_VERSION "SWAD 18.139.1 (2019-08-03)" #define CSS_FILE "swad18.138.css" #define JS_FILE "swad18.130.2.js" /* + Version 18.139.1: Aug 03, 2019 Get elapsed time in a question and in a match. (244216 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)); diff --git a/swad_game.c b/swad_game.c index d54a5aab9..9aa96612e 100644 --- a/swad_game.c +++ b/swad_game.c @@ -187,7 +187,12 @@ 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_GetElapsedTimeInQuestion (struct Match *Match, + char HHHMMSS[3 + 1 + 2 + 1 + 2 + 1]); +static void Gam_GetElapsedTimeInMatch (struct Match *Match, + char HHHMMSS[3 + 1 + 2 + 1 + 2 + 1]); static void Gam_SetMatchStatusToPrevQuestion (struct Match *Match); static void Gam_SetMatchStatusToNextQuestion (struct Match *Match); @@ -3344,7 +3349,7 @@ static void Gam_UpdateMatchStatusInDB (struct Match *Match) } /*****************************************************************************/ -/** Update elapsed time in current question (by a teacher) **/ +/********** Update elapsed time in current question (by a teacher) ***********/ /*****************************************************************************/ static void Gam_UpdateElapsedTimeInQuestion (struct Match *Match) @@ -3363,6 +3368,77 @@ static void Gam_UpdateElapsedTimeInQuestion (struct Match *Match) Cfg_SECONDS_TO_REFRESH_GAME); } +/*****************************************************************************/ +/******************* Get elapsed time in a match question ********************/ +/*****************************************************************************/ + +static void Gam_GetElapsedTimeInQuestion (struct Match *Match, + char HHHMMSS[3 + 1 + 2 + 1 + 2 + 1]) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumRows; + + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time", + "SELECT ElapsedTime" + " FROM gam_time" + " WHERE MchCod=%ld AND QstInd=%u", + Match->MchCod,Match->Status.QstInd); + if (NumRows) + { + row = mysql_fetch_row (mysql_res); + + /* Get the elapsed time (row[0]) */ + if (strlen (row[0]) > 2 + 1 + 2 + 1 + 2) + Str_Copy (HHHMMSS,"+99:59:59", + Gam_MAX_BYTES_TITLE); + else + Str_Copy (HHHMMSS,row[0], + Gam_MAX_BYTES_TITLE); + } + else + Str_Copy (HHHMMSS,"00:00:00", + Gam_MAX_BYTES_TITLE); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/*********************** Get elapsed time in a match *************************/ +/*****************************************************************************/ + +static void Gam_GetElapsedTimeInMatch (struct Match *Match, + char HHHMMSS[3 + 1 + 2 + 1 + 2 + 1]) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumRows; + + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time", + "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))" + " FROM gam_time WHERE MchCod=%ld", + Match->MchCod); + if (NumRows) + { + row = mysql_fetch_row (mysql_res); + + /* Get the elapsed time (row[0]) */ + if (strlen (row[0]) > 2 + 1 + 2 + 1 + 2) + Str_Copy (HHHMMSS,"+99:59:59", + Gam_MAX_BYTES_TITLE); + else + Str_Copy (HHHMMSS,row[0], + Gam_MAX_BYTES_TITLE); + } + else + Str_Copy (HHHMMSS,"00:00:00", + Gam_MAX_BYTES_TITLE); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + /*****************************************************************************/ /** Show current match status (current question, answers...) (by a teacher) **/ /*****************************************************************************/