mirror of https://github.com/acanas/swad-core.git
Version 21.16.3: Sep 24, 2021 Queries moved to module swad_match_database.
This commit is contained in:
parent
1ed23c7c72
commit
1726ed6442
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.16.2 (2021-09-25)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.16.3 (2021-09-25)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.16.3: Sep 24, 2021 Queries moved to module swad_match_database. (317085 lines)
|
||||
Version 21.16.2: Sep 25, 2021 Code refactoring related to error alerts. (317087 lines)
|
||||
Version 21.16.1: Sep 24, 2021 Queries moved to module swad_match_database. (317054 lines)
|
||||
Version 21.16: Sep 24, 2021 New module swad_match_database for database queries related to game matches. (316995 lines)
|
||||
|
|
92
swad_match.c
92
swad_match.c
|
@ -218,11 +218,6 @@ static void Mch_PutBigButtonClose (void);
|
|||
|
||||
static void Mch_ShowWaitImage (const char *Txt);
|
||||
|
||||
static void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod);
|
||||
static void Mch_DB_SetMatchAsNotBeingPlayed (long MchCod);
|
||||
static bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod);
|
||||
static void Mch_DB_GetNumPlayers (struct Mch_Match *Match);
|
||||
|
||||
static void Mch_DB_UpdateMyAnswerToMatchQuestion (const struct Mch_Match *Match,
|
||||
const struct Mch_UsrAnswer *UsrAnswer);
|
||||
static void Mch_DB_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match);
|
||||
|
@ -1517,7 +1512,7 @@ void Mch_ResumeMatch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -1713,7 +1708,7 @@ static void Mch_UpdateMatchStatusInDB (const struct Mch_Match *Match)
|
|||
Mch_DB_UpdateMatchAsBeingPlayed (Match->MchCod);
|
||||
else // Match is paused, not being played
|
||||
/* Update match as not being played */
|
||||
Mch_DB_SetMatchAsNotBeingPlayed (Match->MchCod);
|
||||
Mch_DB_RemoveMatchFromBeingPlayed (Match->MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1816,7 +1811,7 @@ void Mch_PlayPauseMatch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -1853,7 +1848,7 @@ void Mch_ChangeNumColsMch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -1889,7 +1884,7 @@ void Mch_ToggleVisResultsMchQst (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -1924,7 +1919,7 @@ void Mch_BackMatch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -1956,7 +1951,7 @@ void Mch_ForwardMatch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -2293,7 +2288,7 @@ static void Mch_WriteNumRespondersQst (struct Mch_Match *Match)
|
|||
if (Match->Status.Playing) // Match is being played
|
||||
{
|
||||
/* Get current number of players */
|
||||
Mch_DB_GetNumPlayers (Match);
|
||||
Match->Status.NumPlayers = Mch_DB_GetNumPlayers (Match->MchCod);
|
||||
|
||||
/* Show current number of players */
|
||||
HTM_TxtF ("/%u",Match->Status.NumPlayers);
|
||||
|
@ -2609,12 +2604,12 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
|
|||
{
|
||||
switch (Match->Status.Showing)
|
||||
{
|
||||
case Mch_START: // Match just started, before first question
|
||||
case Mch_START: // Match just started, before first question
|
||||
/* Put button to start playing match */
|
||||
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
|
||||
Mch_ICON_PLAY,Txt_Start);
|
||||
break;
|
||||
case Mch_END: // Match over
|
||||
case Mch_END: // Match over
|
||||
/* Put disabled button to play match */
|
||||
Mch_PutBigButtonHidden (Mch_ICON_PLAY);
|
||||
break;
|
||||
|
@ -3369,69 +3364,6 @@ static void Mch_ShowWaitImage (const char *Txt)
|
|||
HTM_DIV_End ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Update match as being played *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Insert match as being played *****/
|
||||
DB_QueryREPLACE ("can not set match as being played",
|
||||
"REPLACE mch_playing"
|
||||
" (MchCod)"
|
||||
" VALUE"
|
||||
" (%ld)",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Update match as paused, not being played *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Mch_DB_SetMatchAsNotBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Delete all match players ******/
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM mch_players"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
|
||||
/***** Delete match as being played ******/
|
||||
DB_QueryDELETE ("can not set match as not being played",
|
||||
"DELETE FROM mch_playing"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get if match is being played ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Get if a match is being played or not *****/
|
||||
return (DB_QueryCOUNT ("can not get if match is being played",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM mch_playing"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Get number of players ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Mch_DB_GetNumPlayers (struct Mch_Match *Match)
|
||||
{
|
||||
/***** Get number of players who are playing a match *****/
|
||||
Match->Status.NumPlayers = (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of players",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM mch_players"
|
||||
" WHERE MchCod=%ld",
|
||||
Match->MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Register me as a player in a match **********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -3568,7 +3500,7 @@ void Mch_StartCountdown (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
@ -3602,7 +3534,7 @@ void Mch_RefreshMatchTch (void)
|
|||
/***** Remove old players.
|
||||
This function must be called by a teacher
|
||||
before getting match status. *****/
|
||||
Mch_DB_RemoveOldPlayers ();
|
||||
Mch_DB_RemoveOldPlaying ();
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Mch_GetMchCodBeingPlayed ();
|
||||
|
|
|
@ -589,6 +589,85 @@ void Mch_DB_GetIndexes (long MchCod,unsigned QstInd,
|
|||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Update match as being played *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod)
|
||||
{
|
||||
DB_QueryREPLACE ("can not set match as being played",
|
||||
"REPLACE mch_playing"
|
||||
" (MchCod)"
|
||||
" VALUE"
|
||||
" (%ld)",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get if match is being played ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod)
|
||||
{
|
||||
return (DB_QueryCOUNT ("can not get if match is being played",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM mch_playing"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Get number of players who are playing a match ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Mch_DB_GetNumPlayers (long MchCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of players",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM mch_players"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Update match as paused, not being played *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Mch_DB_RemoveMatchFromBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Delete all match players ******/
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM mch_players"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
|
||||
/***** Delete match as being played ******/
|
||||
DB_QueryDELETE ("can not set match as not being played",
|
||||
"DELETE FROM mch_playing"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Remove old players *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Mch_DB_RemoveOldPlaying (void)
|
||||
{
|
||||
/***** Delete matches not being played by teacher *****/
|
||||
DB_QueryDELETE ("can not update matches as not being played",
|
||||
"DELETE FROM mch_playing"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_MATCH_TCH*3);
|
||||
|
||||
/***** Delete players (students) who have left matches *****/
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM mch_players"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_MATCH_STD*3);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Update elapsed time in current question (by a teacher) ***********/
|
||||
/*****************************************************************************/
|
||||
|
@ -625,7 +704,6 @@ unsigned Mch_DB_GetElapsedTimeInQuestion (MYSQL_RES **mysql_res,
|
|||
QstInd);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get elapsed time in a match *************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -640,25 +718,6 @@ unsigned Mch_DB_GetElapsedTimeInMatch (MYSQL_RES **mysql_res,long MchCod)
|
|||
MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Remove old players *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Mch_DB_RemoveOldPlayers (void)
|
||||
{
|
||||
/***** Delete matches not being played by teacher *****/
|
||||
DB_QueryDELETE ("can not update matches as not being played",
|
||||
"DELETE FROM mch_playing"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_MATCH_TCH*3);
|
||||
|
||||
/***** Delete players (students) who have left matches *****/
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM mch_players"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_MATCH_STD*3);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get maximum number of users per score in match results ************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -81,6 +81,15 @@ void Mch_DB_CreateQstIndexes (long MchCod,unsigned QstInd,
|
|||
void Mch_DB_GetIndexes (long MchCod,unsigned QstInd,
|
||||
char StrIndexesOneQst[Tst_MAX_BYTES_INDEXES_ONE_QST + 1]);
|
||||
|
||||
//-------------------------- Matches being played -----------------------------
|
||||
void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod);
|
||||
|
||||
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod);
|
||||
unsigned Mch_DB_GetNumPlayers (long MchCod);
|
||||
|
||||
void Mch_DB_RemoveMatchFromBeingPlayed (long MchCod);
|
||||
void Mch_DB_RemoveOldPlaying (void);
|
||||
|
||||
//----------------------------- Elapsed times ---------------------------------
|
||||
void Mch_DB_UpdateElapsedTimeInQuestion (long MchCod,long QstInd);
|
||||
|
||||
|
@ -88,9 +97,6 @@ unsigned Mch_DB_GetElapsedTimeInQuestion (MYSQL_RES **mysql_res,
|
|||
long MchCod,unsigned QstInd);
|
||||
unsigned Mch_DB_GetElapsedTimeInMatch (MYSQL_RES **mysql_res,long MchCod);
|
||||
|
||||
//------------------------------- Players -------------------------------------
|
||||
void Mch_DB_RemoveOldPlayers (void);
|
||||
|
||||
//----------------------------- Match results ---------------------------------
|
||||
unsigned Mch_DB_GetMaxUsrs (long MchCod);
|
||||
unsigned Mch_DB_GetUsrsPerScore (MYSQL_RES **mysql_res,long MchCod);
|
||||
|
|
Loading…
Reference in New Issue