mirror of https://github.com/acanas/swad-core.git
Version 21.6.2: Sep 18, 2021 Queries moved to module swad_game_database.
This commit is contained in:
parent
1514c65817
commit
74d611fc4d
|
@ -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.6.1 (2021-09-18)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.6.2 (2021-09-18)"
|
||||
#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.6.2: Sep 18, 2021 Queries moved to module swad_game_database. (315679 lines)
|
||||
Version 21.6.1: Sep 18, 2021 Queries moved to module swad_game_database. (315571 lines)
|
||||
Version 21.6: Sep 18, 2021 New module swad_game_database for database queries related to games. (315565 lines)
|
||||
Version 21.5.3: Sep 16, 2021 Queries moved to module swad_forum_database. (315431 lines)
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "swad_form.h"
|
||||
#include "swad_forum.h"
|
||||
#include "swad_forum_database.h"
|
||||
#include "swad_game_database.h"
|
||||
#include "swad_global.h"
|
||||
#include "swad_hierarchy.h"
|
||||
#include "swad_hierarchy_level.h"
|
||||
|
|
144
swad_game.c
144
swad_game.c
|
@ -1138,17 +1138,11 @@ static void Gam_RemoveGameFromAllTables (long GamCod)
|
|||
/***** Remove all matches in this game *****/
|
||||
Mch_RemoveMatchesInGameFromAllTables (GamCod);
|
||||
|
||||
/***** Remove game question *****/
|
||||
DB_QueryDELETE ("can not remove game questions",
|
||||
"DELETE FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
/***** Remove game questions *****/
|
||||
Gam_DB_RemoveGameQsts (GamCod);
|
||||
|
||||
/***** Remove game *****/
|
||||
DB_QueryDELETE ("can not remove game",
|
||||
"DELETE FROM gam_games"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
Gam_DB_RemoveGame (GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1161,19 +1155,10 @@ void Gam_RemoveCrsGames (long CrsCod)
|
|||
Mch_RemoveMatchesInCourseFromAllTables (CrsCod);
|
||||
|
||||
/***** Remove the questions in games *****/
|
||||
DB_QueryDELETE ("can not remove questions in course games",
|
||||
"DELETE FROM gam_questions"
|
||||
" USING gam_games,"
|
||||
"gam_questions"
|
||||
" WHERE gam_games.CrsCod=%ld"
|
||||
" AND gam_games.GamCod=gam_questions.GamCod",
|
||||
CrsCod);
|
||||
Gam_DB_RemoveCrsGameQsts (CrsCod);
|
||||
|
||||
/***** Remove the games *****/
|
||||
DB_QueryDELETE ("can not remove course games",
|
||||
"DELETE FROM gam_games"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
Gam_DB_RemoveCrsGames (CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1201,11 +1186,7 @@ void Gam_HideGame (void)
|
|||
Err_NoPermissionExit ();
|
||||
|
||||
/***** Hide game *****/
|
||||
DB_QueryUPDATE ("can not hide game",
|
||||
"UPDATE gam_games"
|
||||
" SET Hidden='Y'"
|
||||
" WHERE GamCod=%ld",
|
||||
Game.GamCod);
|
||||
Gam_DB_HideGame (Game.GamCod);
|
||||
|
||||
/***** Show games again *****/
|
||||
Gam_ListAllGames (&Games);
|
||||
|
@ -1235,12 +1216,8 @@ void Gam_UnhideGame (void)
|
|||
if (!Gam_CheckIfICanEditGames ())
|
||||
Err_NoPermissionExit ();
|
||||
|
||||
/***** Show game *****/
|
||||
DB_QueryUPDATE ("can not show game",
|
||||
"UPDATE gam_games"
|
||||
" SET Hidden='N'"
|
||||
" WHERE GamCod=%ld",
|
||||
Game.GamCod);
|
||||
/***** Unhide game *****/
|
||||
Gam_DB_UnhideGame (Game.GamCod);
|
||||
|
||||
/***** Show games again *****/
|
||||
Gam_ListAllGames (&Games);
|
||||
|
@ -1556,22 +1533,7 @@ static void Gam_CreateGame (struct Gam_Game *Game,const char *Txt)
|
|||
extern const char *Txt_Created_new_game_X;
|
||||
|
||||
/***** Create a new game *****/
|
||||
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
|
||||
Game->GamCod =
|
||||
DB_QueryINSERTandReturnCode ("can not create new game",
|
||||
"INSERT INTO gam_games"
|
||||
" (CrsCod,Hidden,UsrCod,MaxGrade,Visibility,"
|
||||
"Title,Txt)"
|
||||
" VALUES"
|
||||
" (%ld,'N',%ld,%.15lg,%u,"
|
||||
"'%s','%s')",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Game->MaxGrade,
|
||||
Game->Visibility,
|
||||
Game->Title,
|
||||
Txt);
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
Game->GamCod = Gam_DB_CreateGame (Game,Txt);
|
||||
|
||||
/***** Write success message *****/
|
||||
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_game_X,
|
||||
|
@ -1587,22 +1549,7 @@ static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt)
|
|||
extern const char *Txt_The_game_has_been_modified;
|
||||
|
||||
/***** Update the data of the game *****/
|
||||
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
|
||||
DB_QueryUPDATE ("can not update game",
|
||||
"UPDATE gam_games"
|
||||
" SET CrsCod=%ld,"
|
||||
"MaxGrade=%.15lg,"
|
||||
"Visibility=%u,"
|
||||
"Title='%s',"
|
||||
"Txt='%s'"
|
||||
" WHERE GamCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Game->MaxGrade,
|
||||
Game->Visibility,
|
||||
Game->Title,
|
||||
Txt,
|
||||
Game->GamCod);
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
Gam_DB_UpdateGame (Game,Txt);
|
||||
|
||||
/***** Write success message *****/
|
||||
Ale_ShowAlert (Ale_SUCCESS,Txt_The_game_has_been_modified);
|
||||
|
@ -1694,28 +1641,6 @@ unsigned Gam_GetParamQstInd (void)
|
|||
return (unsigned) QstInd;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get question code given game and index of question *************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
||||
{
|
||||
long QstCod;
|
||||
|
||||
/***** Get question code of the question to be moved up *****/
|
||||
QstCod = DB_QuerySELECTCode ("can not get question code",
|
||||
"SELECT QstCod"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
if (QstCod <= 0)
|
||||
Err_WrongQuestionExit ();
|
||||
|
||||
return QstCod;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ List the questions of a game ***********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -1729,14 +1654,7 @@ static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game
|
|||
bool ICanEditQuestions = Gam_CheckIfEditable (Game);
|
||||
|
||||
/***** Get data of questions from database *****/
|
||||
NumQsts = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get game questions",
|
||||
"SELECT QstInd," // row[0]
|
||||
"QstCod" // row[1]
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" ORDER BY QstInd",
|
||||
Game->GamCod);
|
||||
NumQsts = Gam_DB_GetGameQuestions (&mysql_res,Game->GamCod);
|
||||
|
||||
/***** Begin box *****/
|
||||
Games->GamCod = Game->GamCod;
|
||||
|
@ -1997,14 +1915,7 @@ void Gam_AddQstsToGame (void)
|
|||
MaxQstInd = Gam_DB_GetMaxQuestionIndexInGame (Game.GamCod); // 0 is no questions in game
|
||||
|
||||
/* Insert question in the table of questions */
|
||||
DB_QueryINSERT ("can not add question to game",
|
||||
"INSERT INTO gam_questions"
|
||||
" (GamCod,QstInd,QstCod)"
|
||||
" VALUES"
|
||||
" (%ld,%u,%ld)",
|
||||
Game.GamCod,
|
||||
MaxQstInd + 1,
|
||||
QstCod);
|
||||
Gam_DB_InsertQstInGame (Game.GamCod,MaxQstInd + 1,QstCod);
|
||||
|
||||
NumQstsAdded++;
|
||||
}
|
||||
|
@ -2134,30 +2045,11 @@ void Gam_RemoveQstFromGame (void)
|
|||
Mch_DB_RemAnswersOfAQuestion (Game.GamCod,QstInd);
|
||||
|
||||
/* Remove the question itself */
|
||||
DB_QueryDELETE ("can not remove a question",
|
||||
"DELETE FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
Game.GamCod,
|
||||
QstInd);
|
||||
Gam_DB_RemoveQstFromGame (Game.GamCod,QstInd);
|
||||
|
||||
/* Change index of questions greater than this */
|
||||
DB_QueryUPDATE ("can not update indexes of questions in table of answers",
|
||||
"UPDATE mch_answers,"
|
||||
"mch_matches"
|
||||
" SET mch_answers.QstInd=mch_answers.QstInd-1"
|
||||
" WHERE mch_matches.GamCod=%ld"
|
||||
" AND mch_matches.MchCod=mch_answers.MchCod"
|
||||
" AND mch_answers.QstInd>%u",
|
||||
Game.GamCod,
|
||||
QstInd);
|
||||
DB_QueryUPDATE ("can not update indexes of questions",
|
||||
"UPDATE gam_questions"
|
||||
" SET QstInd=QstInd-1"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
Game.GamCod,
|
||||
QstInd);
|
||||
/* Change indexes of questions greater than this */
|
||||
Mch_DB_UpdateIndexesOfQstsGreaterThan (Game.GamCod,QstInd);
|
||||
Gam_DB_UpdateIndexesOfQstsGreaterThan (Game.GamCod,QstInd);
|
||||
|
||||
/***** Write message *****/
|
||||
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
|
||||
|
@ -2288,8 +2180,8 @@ static void Gam_ExchangeQuestions (long GamCod,
|
|||
Gbl.DB.LockedTables = true;
|
||||
|
||||
/***** Get question code of the questions to be moved *****/
|
||||
QstCodTop = Gam_GetQstCodFromQstInd (GamCod,QstIndTop);
|
||||
QstCodBottom = Gam_GetQstCodFromQstInd (GamCod,QstIndBottom);
|
||||
QstCodTop = Gam_DB_GetQstCodFromQstInd (GamCod,QstIndTop);
|
||||
QstCodBottom = Gam_DB_GetQstCodFromQstInd (GamCod,QstIndBottom);
|
||||
|
||||
/***** Exchange indexes of questions *****/
|
||||
/*
|
||||
|
|
|
@ -148,7 +148,6 @@ void Gam_ListQstsToAddToGame (void);
|
|||
|
||||
void Gam_PutParamQstInd (unsigned QstInd);
|
||||
unsigned Gam_GetParamQstInd (void);
|
||||
long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd);
|
||||
|
||||
void Gam_AddQstsToGame (void);
|
||||
|
||||
|
|
|
@ -71,6 +71,83 @@ extern struct Globals Gbl;
|
|||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Create a new game ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Gam_DB_CreateGame (const struct Gam_Game *Game,const char *Txt)
|
||||
{
|
||||
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
|
||||
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create new game",
|
||||
"INSERT INTO gam_games"
|
||||
" (CrsCod,Hidden,UsrCod,MaxGrade,Visibility,"
|
||||
"Title,Txt)"
|
||||
" VALUES"
|
||||
" (%ld,'N',%ld,%.15lg,%u,"
|
||||
"'%s','%s')",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Game->MaxGrade,
|
||||
Game->Visibility,
|
||||
Game->Title,
|
||||
Txt);
|
||||
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
}
|
||||
/*****************************************************************************/
|
||||
/*************************** Update an existing game *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_UpdateGame (const struct Gam_Game *Game,const char *Txt)
|
||||
{
|
||||
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
|
||||
|
||||
DB_QueryUPDATE ("can not update game",
|
||||
"UPDATE gam_games"
|
||||
" SET CrsCod=%ld,"
|
||||
"MaxGrade=%.15lg,"
|
||||
"Visibility=%u,"
|
||||
"Title='%s',"
|
||||
"Txt='%s'"
|
||||
" WHERE GamCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Game->MaxGrade,
|
||||
Game->Visibility,
|
||||
Game->Title,
|
||||
Txt,
|
||||
Game->GamCod);
|
||||
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************************** Hide a game ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_HideGame (long GamCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not hide game",
|
||||
"UPDATE gam_games"
|
||||
" SET Hidden='Y'"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************** Unhide a game ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_UnhideGame (long GamCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not show game",
|
||||
"UPDATE gam_games"
|
||||
" SET Hidden='N'"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************* Get list of all the games in the current course ***************/
|
||||
/*****************************************************************************/
|
||||
|
@ -190,95 +267,6 @@ bool Gam_DB_CheckIfSimilarGameExists (const struct Gam_Game *Game)
|
|||
Game->GamCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get number of questions of a game *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Gam_DB_GetNumQstsGame (long GamCod)
|
||||
{
|
||||
/***** Get nuumber of questions in a game from database *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of questions of a game",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get question index given game and code of question *************/
|
||||
/*****************************************************************************/
|
||||
// Return 0 is question is not present in game
|
||||
|
||||
unsigned Gam_DB_GetQstIndFromQstCod (long GamCod,long QstCod)
|
||||
{
|
||||
/***** Get question index in a game given the question code *****/
|
||||
return DB_QuerySELECTUnsigned ("can not get question index",
|
||||
"SELECT QstInd"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstCod=%ld",
|
||||
GamCod,
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Get maximum question index in a game *********************/
|
||||
/*****************************************************************************/
|
||||
// Question index can be 1, 2, 3...
|
||||
// Return 0 if no questions
|
||||
|
||||
unsigned Gam_DB_GetMaxQuestionIndexInGame (long GamCod)
|
||||
{
|
||||
/***** Get maximum question index in a game from database *****/
|
||||
return DB_QuerySELECTUnsigned ("can not get last question index",
|
||||
"SELECT MAX(QstInd)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get previous question index to a given index in a game **********/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if previous question exists, or 0 if no previous question
|
||||
|
||||
unsigned Gam_DB_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
/***** Get previous question index in a game from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||
"SELECT COALESCE(MAX(QstInd),0)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************* Get next question index to a given index in a game ************/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 0, 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if next question exists, or big number if no next question
|
||||
|
||||
unsigned Gam_DB_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
/***** Get next question index in a game from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get next question index",
|
||||
"SELECT COALESCE(MIN(QstInd),%u)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
Gam_AFTER_LAST_QUESTION, // End of questions has been reached
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Get number of courses with games **********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -429,6 +417,187 @@ unsigned Gam_DB_GetNumGames (HieLvl_Level_t Scope)
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************************* Remove game *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_RemoveGame (long GamCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove game",
|
||||
"DELETE FROM gam_games"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Remove the games of a course ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_RemoveCrsGames (long CrsCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove course games",
|
||||
"DELETE FROM gam_games"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Insert question in the table of questions ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_InsertQstInGame (long GamCod,unsigned QstInd,long QstCod)
|
||||
{
|
||||
DB_QueryINSERT ("can not add question to game",
|
||||
"INSERT INTO gam_questions"
|
||||
" (GamCod,QstInd,QstCod)"
|
||||
" VALUES"
|
||||
" (%ld,%u,%ld)",
|
||||
GamCod,
|
||||
QstInd,
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Update indexes of questions greater than a given one ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_UpdateIndexesOfQstsGreaterThan (long GamCod,unsigned QstInd)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update indexes of questions",
|
||||
"UPDATE gam_questions"
|
||||
" SET QstInd=QstInd-1"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get number of questions of a game *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Gam_DB_GetNumQstsGame (long GamCod)
|
||||
{
|
||||
/***** Get nuumber of questions in a game from database *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of questions of a game",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
/************************ Get the questions of a game ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Gam_DB_GetGameQuestions (MYSQL_RES **mysql_res,long GamCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get game questions",
|
||||
"SELECT QstInd," // row[0]
|
||||
"QstCod" // row[1]
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" ORDER BY QstInd",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get question code given game and index of question *************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Gam_DB_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
||||
{
|
||||
long QstCod;
|
||||
|
||||
/***** Get question code of the question to be moved up *****/
|
||||
QstCod = DB_QuerySELECTCode ("can not get question code",
|
||||
"SELECT QstCod"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
if (QstCod <= 0)
|
||||
Err_WrongQuestionExit ();
|
||||
|
||||
return QstCod;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get question index given game and code of question *************/
|
||||
/*****************************************************************************/
|
||||
// Return 0 is question is not present in game
|
||||
|
||||
unsigned Gam_DB_GetQstIndFromQstCod (long GamCod,long QstCod)
|
||||
{
|
||||
/***** Get question index in a game given the question code *****/
|
||||
return DB_QuerySELECTUnsigned ("can not get question index",
|
||||
"SELECT QstInd"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstCod=%ld",
|
||||
GamCod,
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Get maximum question index in a game *********************/
|
||||
/*****************************************************************************/
|
||||
// Question index can be 1, 2, 3...
|
||||
// Return 0 if no questions
|
||||
|
||||
unsigned Gam_DB_GetMaxQuestionIndexInGame (long GamCod)
|
||||
{
|
||||
/***** Get maximum question index in a game from database *****/
|
||||
return DB_QuerySELECTUnsigned ("can not get last question index",
|
||||
"SELECT MAX(QstInd)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get previous question index to a given index in a game **********/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if previous question exists, or 0 if no previous question
|
||||
|
||||
unsigned Gam_DB_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
/***** Get previous question index in a game from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||
"SELECT COALESCE(MAX(QstInd),0)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************* Get next question index to a given index in a game ************/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 0, 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if next question exists, or big number if no next question
|
||||
|
||||
unsigned Gam_DB_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
/***** Get next question index in a game from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get next question index",
|
||||
"SELECT COALESCE(MIN(QstInd),%u)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
Gam_AFTER_LAST_QUESTION, // End of questions has been reached
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Get average number of questions per game ******************/
|
||||
/*****************************************************************************/
|
||||
|
@ -527,3 +696,44 @@ double Gam_DB_GetNumQstsPerGame (HieLvl_Level_t Scope)
|
|||
return 0.0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Remove question from game *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_RemoveQstFromGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove a question",
|
||||
"DELETE FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Remove game questions **************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_RemoveGameQsts (long GamCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove game questions",
|
||||
"DELETE FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Remove the questions in games of a course *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_DB_RemoveCrsGameQsts (long CrsCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove questions in course games",
|
||||
"DELETE FROM gam_questions"
|
||||
" USING gam_games,"
|
||||
"gam_questions"
|
||||
" WHERE gam_games.CrsCod=%ld"
|
||||
" AND gam_games.GamCod=gam_questions.GamCod",
|
||||
CrsCod);
|
||||
}
|
||||
|
|
|
@ -39,20 +39,37 @@
|
|||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
//--------------------------------- Games -------------------------------------
|
||||
long Gam_DB_CreateGame (const struct Gam_Game *Game,const char *Txt);
|
||||
void Gam_DB_UpdateGame (const struct Gam_Game *Game,const char *Txt);
|
||||
void Gam_DB_HideGame (long GamCod);
|
||||
void Gam_DB_UnhideGame (long GamCod);
|
||||
|
||||
unsigned Gam_DB_GetListGames (MYSQL_RES **mysql_res,Gam_Order_t SelectedOrder);
|
||||
unsigned Gam_DB_GetDataOfGameByCod (MYSQL_RES **mysql_res,long GamCod);
|
||||
void Gam_DB_GetGameTxt (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
|
||||
bool Gam_DB_CheckIfSimilarGameExists (const struct Gam_Game *Game);
|
||||
|
||||
unsigned Gam_DB_GetNumQstsGame (long GamCod);
|
||||
unsigned Gam_DB_GetQstIndFromQstCod (long GamCod,long QstCod);
|
||||
unsigned Gam_DB_GetMaxQuestionIndexInGame (long GamCod);
|
||||
|
||||
unsigned Gam_DB_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd);
|
||||
unsigned Gam_DB_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd);
|
||||
|
||||
unsigned Gam_DB_GetNumCoursesWithGames (HieLvl_Level_t Scope);
|
||||
unsigned Gam_DB_GetNumGames (HieLvl_Level_t Scope);
|
||||
|
||||
void Gam_DB_RemoveGame (long GamCod);
|
||||
void Gam_DB_RemoveCrsGames (long CrsCod);
|
||||
|
||||
//---------------------------- Game questions ---------------------------------
|
||||
void Gam_DB_InsertQstInGame (long GamCod,unsigned QstInd,long QstCod);
|
||||
void Gam_DB_UpdateIndexesOfQstsGreaterThan (long GamCod,unsigned QstInd);
|
||||
|
||||
unsigned Gam_DB_GetNumQstsGame (long GamCod);
|
||||
unsigned Gam_DB_GetGameQuestions (MYSQL_RES **mysql_res,long GamCod);
|
||||
long Gam_DB_GetQstCodFromQstInd (long GamCod,unsigned QstInd);
|
||||
unsigned Gam_DB_GetQstIndFromQstCod (long GamCod,long QstCod);
|
||||
unsigned Gam_DB_GetMaxQuestionIndexInGame (long GamCod);
|
||||
unsigned Gam_DB_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd);
|
||||
unsigned Gam_DB_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd);
|
||||
double Gam_DB_GetNumQstsPerGame (HieLvl_Level_t Scope);
|
||||
|
||||
void Gam_DB_RemoveQstFromGame (long GamCod,unsigned QstInd);
|
||||
void Gam_DB_RemoveGameQsts (long GamCod);
|
||||
void Gam_DB_RemoveCrsGameQsts (long CrsCod);
|
||||
|
||||
#endif
|
||||
|
|
21
swad_match.c
21
swad_match.c
|
@ -2378,7 +2378,7 @@ static void Mch_SetMatchStatusToPrevQst (struct Mch_Match *Match)
|
|||
Match->Status.QstInd);
|
||||
if (Match->Status.QstInd) // Start of questions not reached
|
||||
{
|
||||
Match->Status.QstCod = Gam_GetQstCodFromQstInd (Match->GamCod,
|
||||
Match->Status.QstCod = Gam_DB_GetQstCodFromQstInd (Match->GamCod,
|
||||
Match->Status.QstInd);
|
||||
Match->Status.Showing = Match->Status.ShowQstResults ? Mch_RESULTS :
|
||||
Mch_ANSWERS;
|
||||
|
@ -2443,7 +2443,7 @@ static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
|
|||
/***** Get question code *****/
|
||||
if (Match->Status.QstInd < Gam_AFTER_LAST_QUESTION) // End of questions not reached
|
||||
{
|
||||
Match->Status.QstCod = Gam_GetQstCodFromQstInd (Match->GamCod,
|
||||
Match->Status.QstCod = Gam_DB_GetQstCodFromQstInd (Match->GamCod,
|
||||
Match->Status.QstInd);
|
||||
Match->Status.Showing = Mch_STEM;
|
||||
}
|
||||
|
@ -4485,6 +4485,23 @@ void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,boo
|
|||
HTM_DIV_End ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Update indexes of questions greater than a given one ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Mch_DB_UpdateIndexesOfQstsGreaterThan (long GamCod,unsigned QstInd)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update indexes of questions",
|
||||
"UPDATE mch_answers,"
|
||||
"mch_matches"
|
||||
" SET mch_answers.QstInd=mch_answers.QstInd-1"
|
||||
" WHERE mch_matches.GamCod=%ld"
|
||||
" AND mch_matches.MchCod=mch_answers.MchCod"
|
||||
" AND mch_answers.QstInd>%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get start of first match and end of last match in a game **********/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -158,6 +158,8 @@ unsigned Mch_DB_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd);
|
|||
unsigned Mch_DB_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned AnsInd);
|
||||
void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,bool Correct);
|
||||
|
||||
void Mch_DB_UpdateIndexesOfQstsGreaterThan (long GamCod,unsigned QstInd);
|
||||
|
||||
unsigned Mch_DB_GetStartEndMatchesInGame (MYSQL_RES **mysql_res,long GamCod);
|
||||
void Mch_DB_RemAnswersOfAQuestion (long GamCod,unsigned QstInd);
|
||||
|
||||
|
|
Loading…
Reference in New Issue