mirror of https://github.com/acanas/swad-core.git
Version 21.16.4: Sep 24, 2021 Queries moved to module swad_match_database.
This commit is contained in:
parent
1726ed6442
commit
6161a356cb
|
@ -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.
|
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.3 (2021-09-25)"
|
#define Log_PLATFORM_VERSION "SWAD 21.16.4 (2021-09-25)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 21.16.4: Sep 24, 2021 Queries moved to module swad_match_database. (317091 lines)
|
||||||
Version 21.16.3: Sep 24, 2021 Queries moved to module swad_match_database. (317085 lines)
|
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.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.1: Sep 24, 2021 Queries moved to module swad_match_database. (317054 lines)
|
||||||
|
|
|
@ -2042,7 +2042,7 @@ void Gam_RemoveQstFromGame (void)
|
||||||
|
|
||||||
/***** Remove the question from all the tables *****/
|
/***** Remove the question from all the tables *****/
|
||||||
/* Remove answers from this test question */
|
/* Remove answers from this test question */
|
||||||
Mch_DB_RemAnswersOfAQuestion (Game.GamCod,QstInd);
|
Mch_DB_RemUsrAnswersOfAQuestion (Game.GamCod,QstInd);
|
||||||
|
|
||||||
/* Remove the question itself */
|
/* Remove the question itself */
|
||||||
Gam_DB_RemoveQstFromGame (Game.GamCod,QstInd);
|
Gam_DB_RemoveQstFromGame (Game.GamCod,QstInd);
|
||||||
|
@ -2309,7 +2309,7 @@ void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
|
||||||
|
|
||||||
/* Check number of answers */
|
/* Check number of answers */
|
||||||
if (NumAnswers < 2)
|
if (NumAnswers < 2)
|
||||||
Err_ShowErrorAndExit ("Wrong number of answers.");
|
Err_WrongAnswerExit ();
|
||||||
|
|
||||||
/* Accumulate minimum and maximum score */
|
/* Accumulate minimum and maximum score */
|
||||||
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
||||||
|
|
173
swad_match.c
173
swad_match.c
|
@ -218,12 +218,6 @@ static void Mch_PutBigButtonClose (void);
|
||||||
|
|
||||||
static void Mch_ShowWaitImage (const char *Txt);
|
static void Mch_ShowWaitImage (const char *Txt);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
static unsigned Mch_DB_GetNumUsrsWhoHavePlayedMch (long MchCod);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** Set/Get match code of the match being played ****************/
|
/*************** Set/Get match code of the match being played ****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1672,7 +1666,7 @@ void Mch_GetIndexes (long MchCod,unsigned QstInd,
|
||||||
/***** Get indexes for a question from database *****/
|
/***** Get indexes for a question from database *****/
|
||||||
Mch_DB_GetIndexes (MchCod,QstInd,StrIndexesOneQst);
|
Mch_DB_GetIndexes (MchCod,QstInd,StrIndexesOneQst);
|
||||||
if (!StrIndexesOneQst[0])
|
if (!StrIndexesOneQst[0])
|
||||||
Err_ShowErrorAndExit ("No indexes found for a question.");
|
Err_WrongAnswerIndexExit ();
|
||||||
|
|
||||||
/***** Get indexes from string *****/
|
/***** Get indexes from string *****/
|
||||||
TstPrn_GetIndexesFromStr (StrIndexesOneQst,Indexes);
|
TstPrn_GetIndexesFromStr (StrIndexesOneQst,Indexes);
|
||||||
|
@ -3295,7 +3289,7 @@ static unsigned Mch_GetParamNumOpt (void)
|
||||||
|
|
||||||
NumOpt = Par_GetParToLong ("NumOpt");
|
NumOpt = Par_GetParToLong ("NumOpt");
|
||||||
if (NumOpt < 0)
|
if (NumOpt < 0)
|
||||||
Err_ShowErrorAndExit ("Wrong number of option.");
|
Err_WrongAnswerExit ();
|
||||||
|
|
||||||
return (unsigned) NumOpt;
|
return (unsigned) NumOpt;
|
||||||
}
|
}
|
||||||
|
@ -3388,13 +3382,7 @@ bool Mch_RegisterMeAsPlayerInMatch (struct Mch_Match *Match)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** Insert me as match player *****/
|
/***** Insert me as match player *****/
|
||||||
DB_QueryREPLACE ("can not insert match player",
|
Mch_DB_RegisterMeAsPlayerInMatch (Match->MchCod);
|
||||||
"REPLACE mch_players"
|
|
||||||
" (MchCod,UsrCod)"
|
|
||||||
" VALUES"
|
|
||||||
" (%ld,%ld)",
|
|
||||||
Match->MchCod,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3608,35 +3596,23 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
unsigned NumRows;
|
|
||||||
|
|
||||||
/***** Set default values for number of option and answer index *****/
|
/***** Set default values for number of option and answer index *****/
|
||||||
UsrAnswer->NumOpt = -1; // < 0 ==> no answer selected
|
UsrAnswer->NumOpt = -1; // < 0 ==> no answer selected
|
||||||
UsrAnswer->AnsInd = -1; // < 0 ==> no answer selected
|
UsrAnswer->AnsInd = -1; // < 0 ==> no answer selected
|
||||||
|
|
||||||
/***** Get student's answer *****/
|
/***** Get student's answer *****/
|
||||||
NumRows = (unsigned)
|
if (Mch_DB_GetUsrAnsToQst (&mysql_res,MchCod,UsrCod,QstInd)) // Answer found...
|
||||||
DB_QuerySELECT (&mysql_res,"can not get user's answer to a match question",
|
|
||||||
"SELECT NumOpt," // row[0]
|
|
||||||
"AnsInd" // row[1]
|
|
||||||
" FROM mch_answers"
|
|
||||||
" WHERE MchCod=%ld"
|
|
||||||
" AND UsrCod=%ld"
|
|
||||||
" AND QstInd=%u",
|
|
||||||
MchCod,
|
|
||||||
UsrCod,
|
|
||||||
QstInd);
|
|
||||||
if (NumRows) // Answer found...
|
|
||||||
{
|
{
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
|
||||||
/***** Get number of option index (row[0]) *****/
|
/***** Get number of option index (row[0]) *****/
|
||||||
if (sscanf (row[0],"%d",&(UsrAnswer->NumOpt)) != 1)
|
if (sscanf (row[0],"%d",&(UsrAnswer->NumOpt)) != 1)
|
||||||
Err_ShowErrorAndExit ("Error when getting student's answer to a match question.");
|
Err_WrongAnswerExit ();
|
||||||
|
|
||||||
/***** Get answer index (row[1]) *****/
|
/***** Get answer index (row[1]) *****/
|
||||||
if (sscanf (row[1],"%d",&(UsrAnswer->AnsInd)) != 1)
|
if (sscanf (row[1],"%d",&(UsrAnswer->AnsInd)) != 1)
|
||||||
Err_ShowErrorAndExit ("Error when getting student's answer to a match question.");
|
Err_WrongAnswerIndexExit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
/***** Free structure that stores the query result *****/
|
||||||
|
@ -3731,41 +3707,6 @@ void Mch_StoreQuestionAnswer (const struct Mch_Match *Match,unsigned QstInd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******************** Update my answer to match question *********************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void Mch_DB_UpdateMyAnswerToMatchQuestion (const struct Mch_Match *Match,
|
|
||||||
const struct Mch_UsrAnswer *UsrAnswer)
|
|
||||||
{
|
|
||||||
DB_QueryREPLACE ("can not register your answer to the match question",
|
|
||||||
"REPLACE mch_answers"
|
|
||||||
" (MchCod,UsrCod,QstInd,NumOpt,AnsInd)"
|
|
||||||
" VALUES"
|
|
||||||
" (%ld,%ld,%u,%d,%d)",
|
|
||||||
Match->MchCod,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
||||||
Match->Status.QstInd,
|
|
||||||
UsrAnswer->NumOpt,
|
|
||||||
UsrAnswer->AnsInd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******************* Remove my answer to match question **********************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void Mch_DB_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match)
|
|
||||||
{
|
|
||||||
DB_QueryDELETE ("can not remove your answer to the match question",
|
|
||||||
"DELETE FROM mch_answers"
|
|
||||||
" WHERE MchCod=%ld"
|
|
||||||
" AND UsrCod=%ld"
|
|
||||||
" AND QstInd=%u",
|
|
||||||
Match->MchCod,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
||||||
Match->Status.QstInd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** Get the questions of a match from database ******************/
|
/*************** Get the questions of a match from database ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3779,19 +3720,8 @@ void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print)
|
||||||
struct Mch_UsrAnswer UsrAnswer;
|
struct Mch_UsrAnswer UsrAnswer;
|
||||||
|
|
||||||
/***** Get questions and answers of a match result *****/
|
/***** Get questions and answers of a match result *****/
|
||||||
Print->NumQsts.All = (unsigned)
|
Print->NumQsts.All = Mch_DB_GetMatchQuestions (&mysql_res,Print->MchCod);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get questions and answers"
|
|
||||||
" of a match result",
|
|
||||||
"SELECT gam_questions.QstCod," // row[0]
|
|
||||||
"gam_questions.QstInd," // row[1]
|
|
||||||
"mch_indexes.Indexes" // row[2]
|
|
||||||
" FROM mch_matches,gam_questions,mch_indexes"
|
|
||||||
" WHERE mch_matches.MchCod=%ld"
|
|
||||||
" AND mch_matches.GamCod=gam_questions.GamCod"
|
|
||||||
" AND mch_matches.MchCod=mch_indexes.MchCod"
|
|
||||||
" AND gam_questions.QstInd=mch_indexes.QstInd"
|
|
||||||
" ORDER BY gam_questions.QstInd",
|
|
||||||
Print->MchCod);
|
|
||||||
for (NumQst = 0, Print->NumQsts.NotBlank = 0;
|
for (NumQst = 0, Print->NumQsts.NotBlank = 0;
|
||||||
NumQst < Print->NumQsts.All;
|
NumQst < Print->NumQsts.All;
|
||||||
NumQst++)
|
NumQst++)
|
||||||
|
@ -3855,61 +3785,6 @@ void Mch_ComputeScore (struct MchPrn_Print *Print)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/********** Get number of users who answered a question in a match ***********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
unsigned Mch_DB_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd)
|
|
||||||
{
|
|
||||||
/***** Get number of users who answered
|
|
||||||
a question in a match from database *****/
|
|
||||||
return (unsigned)
|
|
||||||
DB_QueryCOUNT ("can not get number of users who answered a question",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM mch_answers"
|
|
||||||
" WHERE MchCod=%ld"
|
|
||||||
" AND QstInd=%u",
|
|
||||||
MchCod,
|
|
||||||
QstInd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*** Get number of users who have chosen a given answer of a game question ***/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
unsigned Mch_DB_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned AnsInd)
|
|
||||||
{
|
|
||||||
/***** Get number of users who have chosen
|
|
||||||
an answer of a question from database *****/
|
|
||||||
return (unsigned)
|
|
||||||
DB_QueryCOUNT ("can not get number of users who have chosen an answer",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM mch_answers"
|
|
||||||
" WHERE MchCod=%ld"
|
|
||||||
" AND QstInd=%u"
|
|
||||||
" AND AnsInd=%u",
|
|
||||||
MchCod,
|
|
||||||
QstInd,
|
|
||||||
AnsInd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************ Get number of users who have played a given match **************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static unsigned Mch_DB_GetNumUsrsWhoHavePlayedMch (long MchCod)
|
|
||||||
{
|
|
||||||
/***** Get number of users who have played the match
|
|
||||||
(users who have a result for this match, even blank result)
|
|
||||||
from database *****/
|
|
||||||
return (unsigned)
|
|
||||||
DB_QueryCOUNT ("can not get number of users who have played a match",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM mch_results"
|
|
||||||
" WHERE MchCod=%ld",
|
|
||||||
MchCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/***************** Draw a bar with the percentage of answers *****************/
|
/***************** Draw a bar with the percentage of answers *****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3958,35 +3833,3 @@ void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,boo
|
||||||
/***** End container *****/
|
/***** End container *****/
|
||||||
HTM_DIV_End ();
|
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 **********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
unsigned Mch_DB_GetStartEndMatchesInGame (MYSQL_RES **mysql_res,long GamCod)
|
|
||||||
{
|
|
||||||
return (unsigned)
|
|
||||||
DB_QuerySELECT (mysql_res,"can not get game data",
|
|
||||||
"SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0]
|
|
||||||
"UNIX_TIMESTAMP(MAX(EndTime))" // row[1]
|
|
||||||
" FROM mch_matches"
|
|
||||||
" WHERE GamCod=%ld",
|
|
||||||
GamCod);
|
|
||||||
}
|
|
||||||
|
|
|
@ -152,12 +152,6 @@ void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print);
|
||||||
|
|
||||||
void Mch_ComputeScore (struct MchPrn_Print *Print);
|
void Mch_ComputeScore (struct MchPrn_Print *Print);
|
||||||
|
|
||||||
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_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);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,27 +26,13 @@
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define _GNU_SOURCE // For asprintf
|
#define _GNU_SOURCE // For asprintf
|
||||||
// #include <linux/limits.h> // For PATH_MAX
|
|
||||||
// #include <stddef.h> // For NULL
|
|
||||||
#include <stdio.h> // For asprintf
|
#include <stdio.h> // For asprintf
|
||||||
// #include <stdlib.h> // For free
|
|
||||||
#include <string.h> // For string functions
|
#include <string.h> // For string functions
|
||||||
|
|
||||||
#include "swad_database.h"
|
#include "swad_database.h"
|
||||||
// #include "swad_date.h"
|
|
||||||
#include "swad_error.h"
|
#include "swad_error.h"
|
||||||
// #include "swad_form.h"
|
|
||||||
// #include "swad_game.h"
|
|
||||||
// #include "swad_game_database.h"
|
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
// #include "swad_group_database.h"
|
|
||||||
// #include "swad_HTML.h"
|
|
||||||
// #include "swad_match.h"
|
|
||||||
#include "swad_match_database.h"
|
#include "swad_match_database.h"
|
||||||
// #include "swad_match_result.h"
|
|
||||||
// #include "swad_role.h"
|
|
||||||
// #include "swad_setting.h"
|
|
||||||
// #include "swad_test.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
@ -222,6 +208,21 @@ unsigned Mch_DB_GetDataOfMatchByCod (MYSQL_RES **mysql_res,long MchCod)
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Get start of first match and end of last match in a game **********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetStartEndMatchesInGame (MYSQL_RES **mysql_res,long GamCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get game data",
|
||||||
|
"SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0]
|
||||||
|
"UNIX_TIMESTAMP(MAX(EndTime))" // row[1]
|
||||||
|
" FROM mch_matches"
|
||||||
|
" WHERE GamCod=%ld",
|
||||||
|
GamCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************************* Get the matches of a game *************************/
|
/************************* Get the matches of a game *************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -539,10 +540,139 @@ void Mch_DB_RemoveGroupsOfType (long GrpTypCod)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******** Remove answers of a question from all matches of this game *********/
|
/*************** Get the questions of a match from database ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void Mch_DB_RemAnswersOfAQuestion (long GamCod,unsigned QstInd)
|
unsigned Mch_DB_GetMatchQuestions (MYSQL_RES **mysql_res,long MchCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get questions and indexes of options"
|
||||||
|
" of a match result",
|
||||||
|
"SELECT gam_questions.QstCod," // row[0]
|
||||||
|
"gam_questions.QstInd," // row[1]
|
||||||
|
"mch_indexes.Indexes" // row[2]
|
||||||
|
" FROM mch_matches,"
|
||||||
|
"gam_questions,"
|
||||||
|
"mch_indexes"
|
||||||
|
" WHERE mch_matches.MchCod=%ld"
|
||||||
|
" AND mch_matches.GamCod=gam_questions.GamCod"
|
||||||
|
" AND mch_matches.MchCod=mch_indexes.MchCod"
|
||||||
|
" AND gam_questions.QstInd=mch_indexes.QstInd"
|
||||||
|
" ORDER BY gam_questions.QstInd",
|
||||||
|
MchCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************** Update my answer to match question *********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Mch_DB_UpdateMyAnswerToMatchQuestion (const struct Mch_Match *Match,
|
||||||
|
const struct Mch_UsrAnswer *UsrAnswer)
|
||||||
|
{
|
||||||
|
DB_QueryREPLACE ("can not register your answer to the match question",
|
||||||
|
"REPLACE mch_answers"
|
||||||
|
" (MchCod,UsrCod,QstInd,NumOpt,AnsInd)"
|
||||||
|
" VALUES"
|
||||||
|
" (%ld,%ld,%u,%d,%d)",
|
||||||
|
Match->MchCod,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
|
Match->Status.QstInd,
|
||||||
|
UsrAnswer->NumOpt,
|
||||||
|
UsrAnswer->AnsInd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*** Update indexes of user answers to 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 user's answer to a match question ******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetUsrAnsToQst (MYSQL_RES **mysql_res,
|
||||||
|
long MchCod,long UsrCod,unsigned QstInd)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get user's answer to a match question",
|
||||||
|
"SELECT NumOpt," // row[0]
|
||||||
|
"AnsInd" // row[1]
|
||||||
|
" FROM mch_answers"
|
||||||
|
" WHERE MchCod=%ld"
|
||||||
|
" AND UsrCod=%ld"
|
||||||
|
" AND QstInd=%u",
|
||||||
|
MchCod,
|
||||||
|
UsrCod,
|
||||||
|
QstInd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********** Get number of users who answered a question in a match ***********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get number of users who answered a question",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM mch_answers"
|
||||||
|
" WHERE MchCod=%ld"
|
||||||
|
" AND QstInd=%u",
|
||||||
|
MchCod,
|
||||||
|
QstInd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*** Get number of users who have chosen a given answer of a game question ***/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned AnsInd)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get number of users who have chosen an answer",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM mch_answers"
|
||||||
|
" WHERE MchCod=%ld"
|
||||||
|
" AND QstInd=%u"
|
||||||
|
" AND AnsInd=%u",
|
||||||
|
MchCod,
|
||||||
|
QstInd,
|
||||||
|
AnsInd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************* Remove my answer to match question **********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Mch_DB_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove your answer to the match question",
|
||||||
|
"DELETE FROM mch_answers"
|
||||||
|
" WHERE MchCod=%ld"
|
||||||
|
" AND UsrCod=%ld"
|
||||||
|
" AND QstInd=%u",
|
||||||
|
Match->MchCod,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
|
Match->Status.QstInd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***** Remove users' answers of a question from all matches of this game *****/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Mch_DB_RemUsrAnswersOfAQuestion (long GamCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
DB_QueryDELETE ("can not remove the answers of a question",
|
DB_QueryDELETE ("can not remove the answers of a question",
|
||||||
"DELETE FROM mch_answers"
|
"DELETE FROM mch_answers"
|
||||||
|
@ -603,6 +733,21 @@ void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod)
|
||||||
MchCod);
|
MchCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************* Register me as a player in a match **********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Mch_DB_RegisterMeAsPlayerInMatch (long MchCod)
|
||||||
|
{
|
||||||
|
DB_QueryREPLACE ("can not insert match player",
|
||||||
|
"REPLACE mch_players"
|
||||||
|
" (MchCod,UsrCod)"
|
||||||
|
" VALUES"
|
||||||
|
" (%ld,%ld)",
|
||||||
|
MchCod,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*********************** Get if match is being played ************************/
|
/*********************** Get if match is being played ************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -718,6 +863,23 @@ unsigned Mch_DB_GetElapsedTimeInMatch (MYSQL_RES **mysql_res,long MchCod)
|
||||||
MchCod);
|
MchCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************ Get number of users who have played a given match **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoHavePlayedMch (long MchCod)
|
||||||
|
{
|
||||||
|
/***** Get number of users who have played the match
|
||||||
|
(users who have a result for this match, even blank result)
|
||||||
|
from database *****/
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get number of users who have played a match",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM mch_results"
|
||||||
|
" WHERE MchCod=%ld",
|
||||||
|
MchCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/********* Get maximum number of users per score in match results ************/
|
/********* Get maximum number of users per score in match results ************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -27,11 +27,7 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include "swad_game.h"
|
|
||||||
#include "swad_match.h"
|
#include "swad_match.h"
|
||||||
// #include "swad_match_print.h"
|
|
||||||
// #include "swad_scope.h"
|
|
||||||
// #include "swad_test.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************************** Public types and constants ***********************/
|
/************************** Public types and constants ***********************/
|
||||||
|
@ -49,6 +45,7 @@ void Mch_DB_UpdateMatchTitle (long MchCod,
|
||||||
void Mch_DB_UpdateVisResultsMchUsr (long MchCod,bool ShowUsrResults);
|
void Mch_DB_UpdateVisResultsMchUsr (long MchCod,bool ShowUsrResults);
|
||||||
|
|
||||||
unsigned Mch_DB_GetDataOfMatchByCod (MYSQL_RES **mysql_res,long MchCod);
|
unsigned Mch_DB_GetDataOfMatchByCod (MYSQL_RES **mysql_res,long MchCod);
|
||||||
|
unsigned Mch_DB_GetStartEndMatchesInGame (MYSQL_RES **mysql_res,long GamCod);
|
||||||
unsigned Mch_DB_GetMatches (MYSQL_RES **mysql_res,long GamCod);
|
unsigned Mch_DB_GetMatches (MYSQL_RES **mysql_res,long GamCod);
|
||||||
Mch_Showing_t Mch_DB_GetShowingFromStr (const char *Str);
|
Mch_Showing_t Mch_DB_GetShowingFromStr (const char *Str);
|
||||||
unsigned Mch_DB_GetNumMchsInGame (long GamCod);
|
unsigned Mch_DB_GetNumMchsInGame (long GamCod);
|
||||||
|
@ -72,8 +69,21 @@ bool Mch_DB_CheckIfICanPlayThisMatchBasedOnGrps (long MchCod);
|
||||||
void Mch_DB_RemoveGroup (long GrpCod);
|
void Mch_DB_RemoveGroup (long GrpCod);
|
||||||
void Mch_DB_RemoveGroupsOfType (long GrpTypCod);
|
void Mch_DB_RemoveGroupsOfType (long GrpTypCod);
|
||||||
|
|
||||||
//-------------------------------- Answers ------------------------------------
|
//---------------------------- Match questions --------------------------------
|
||||||
void Mch_DB_RemAnswersOfAQuestion (long GamCod,unsigned QstInd);
|
unsigned Mch_DB_GetMatchQuestions (MYSQL_RES **mysql_res,long MchCod);
|
||||||
|
|
||||||
|
//------------------------------ User answers ---------------------------------
|
||||||
|
void Mch_DB_UpdateMyAnswerToMatchQuestion (const struct Mch_Match *Match,
|
||||||
|
const struct Mch_UsrAnswer *UsrAnswer);
|
||||||
|
void Mch_DB_UpdateIndexesOfQstsGreaterThan (long GamCod,unsigned QstInd);
|
||||||
|
|
||||||
|
unsigned Mch_DB_GetUsrAnsToQst (MYSQL_RES **mysql_res,
|
||||||
|
long MchCod,long UsrCod,unsigned QstInd);
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd);
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned AnsInd);
|
||||||
|
|
||||||
|
void Mch_DB_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match);
|
||||||
|
void Mch_DB_RemUsrAnswersOfAQuestion (long GamCod,unsigned QstInd);
|
||||||
|
|
||||||
//----------------------------- Answers indexes -------------------------------
|
//----------------------------- Answers indexes -------------------------------
|
||||||
void Mch_DB_CreateQstIndexes (long MchCod,unsigned QstInd,
|
void Mch_DB_CreateQstIndexes (long MchCod,unsigned QstInd,
|
||||||
|
@ -83,6 +93,7 @@ void Mch_DB_GetIndexes (long MchCod,unsigned QstInd,
|
||||||
|
|
||||||
//-------------------------- Matches being played -----------------------------
|
//-------------------------- Matches being played -----------------------------
|
||||||
void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod);
|
void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod);
|
||||||
|
void Mch_DB_RegisterMeAsPlayerInMatch (long MchCod);
|
||||||
|
|
||||||
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod);
|
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod);
|
||||||
unsigned Mch_DB_GetNumPlayers (long MchCod);
|
unsigned Mch_DB_GetNumPlayers (long MchCod);
|
||||||
|
@ -98,7 +109,9 @@ unsigned Mch_DB_GetElapsedTimeInQuestion (MYSQL_RES **mysql_res,
|
||||||
unsigned Mch_DB_GetElapsedTimeInMatch (MYSQL_RES **mysql_res,long MchCod);
|
unsigned Mch_DB_GetElapsedTimeInMatch (MYSQL_RES **mysql_res,long MchCod);
|
||||||
|
|
||||||
//----------------------------- Match results ---------------------------------
|
//----------------------------- Match results ---------------------------------
|
||||||
|
unsigned Mch_DB_GetNumUsrsWhoHavePlayedMch (long MchCod);
|
||||||
unsigned Mch_DB_GetMaxUsrs (long MchCod);
|
unsigned Mch_DB_GetMaxUsrs (long MchCod);
|
||||||
unsigned Mch_DB_GetUsrsPerScore (MYSQL_RES **mysql_res,long MchCod);
|
unsigned Mch_DB_GetUsrsPerScore (MYSQL_RES **mysql_res,long MchCod);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3522,7 +3522,7 @@ static void Svy_WriteAnswersOfAQst (struct Svy_Survey *Svy,
|
||||||
{
|
{
|
||||||
/* Check number of answers */
|
/* Check number of answers */
|
||||||
if (NumAnswers > Svy_MAX_ANSWERS_PER_QUESTION)
|
if (NumAnswers > Svy_MAX_ANSWERS_PER_QUESTION)
|
||||||
Err_ShowErrorAndExit ("Wrong number of answers.");
|
Err_WrongAnswerExit ();
|
||||||
|
|
||||||
/* Write one row for each answer */
|
/* Write one row for each answer */
|
||||||
HTM_TABLE_BeginPadding (5);
|
HTM_TABLE_BeginPadding (5);
|
||||||
|
|
|
@ -2088,7 +2088,7 @@ void Tst_GenerateChoiceIndexes (struct TstPrn_PrintedQuestion *PrintedQuestion,
|
||||||
else
|
else
|
||||||
ErrorInIndex = true;
|
ErrorInIndex = true;
|
||||||
if (ErrorInIndex)
|
if (ErrorInIndex)
|
||||||
Err_ShowErrorAndExit ("Wrong index of answer.");
|
Err_WrongAnswerIndexExit ();
|
||||||
|
|
||||||
snprintf (StrInd,sizeof (StrInd),NumOpt ? ",%u" :
|
snprintf (StrInd,sizeof (StrInd),NumOpt ? ",%u" :
|
||||||
"%u",Index);
|
"%u",Index);
|
||||||
|
@ -4069,9 +4069,9 @@ static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *Unsigned
|
||||||
unsigned AnsType;
|
unsigned AnsType;
|
||||||
|
|
||||||
if (sscanf (UnsignedStr,"%u",&AnsType) != 1)
|
if (sscanf (UnsignedStr,"%u",&AnsType) != 1)
|
||||||
Err_ShowErrorAndExit ("Wrong type of answer. 2");
|
Err_WrongAnswerExit ();
|
||||||
if (AnsType >= Tst_NUM_ANS_TYPES)
|
if (AnsType >= Tst_NUM_ANS_TYPES)
|
||||||
Err_ShowErrorAndExit ("Wrong type of answer. 3");
|
Err_WrongAnswerExit ();
|
||||||
return (Tst_AnswerType_t) AnsType;
|
return (Tst_AnswerType_t) AnsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue