Version19.83

This commit is contained in:
Antonio Cañas Vargas 2019-12-04 22:22:42 +01:00
parent af7a7a3749
commit 4aa68192af
6 changed files with 100 additions and 118 deletions

View File

@ -293,28 +293,13 @@ struct swad__getMatchesOutput
struct swad__matchesArray matchesArray;
};
/* playMatch */
struct swad__playMatchOutput
{
int matchCode;
};
/* getMatchStatus */
struct swad__matchAnswer
{
int answerIndex;
int selected;
};
struct swad__matchAnswersArray
{
struct swad__matchAnswer *__ptr; // pointer to array
int __size; // number of elements pointed to
};
struct swad__getMatchStatusOutput
{
int matchCode;
int questionIndex;
struct swad__matchAnswersArray answersArray;
int numAnswers;
int selected;
};
/* answerMatchQuestion */
@ -502,11 +487,9 @@ int swad__getGames (char *wsKey,int courseCode,
struct swad__getGamesOutput *getGamesOut);
int swad__getMatches (char *wsKey,int gameCode,
struct swad__getMatchesOutput *getMatchesOut);
int swad__playMatch (char *wsKey,int matchCode,
struct swad__playMatchOutput *playMatchOut);
int swad__getMatchStatus (char *wsKey,int matchCode,
struct swad__getMatchStatusOutput *getMatchStatusOut);
int swad__answerMatchQuestion (char *wsKey,int matchCode,int questionIndex,int numOption,
int swad__answerMatchQuestion (char *wsKey,int matchCode,int questionIndex,int answerIndex,
struct swad__answerMatchQuestionOutput *answerMatchQuestionOut);
/* List of users */

View File

@ -4663,21 +4663,23 @@ int swad__getMatches (struct soap *soap,
}
/*****************************************************************************/
/********************** Try to join to a match as student ********************/
/*********** Get match status to be refreshed in student's screen ************/
/*****************************************************************************/
int swad__playMatch (struct soap *soap,
char *wsKey,int matchCode, // input
struct swad__playMatchOutput *playMatchOut) // output
int swad__getMatchStatus (struct soap *soap,
char *wsKey,int matchCode, // input
struct swad__getMatchStatusOutput *getMatchStatusOut) // output
{
int ReturnCode;
struct Match Match;
struct Game Game;
bool ICanPlayThisMatchBasedOnGrps;
unsigned NumOptions;
struct Mch_UsrAnswer UsrAnswer;
/***** Initializations *****/
Gbl.soap = soap;
Gbl.WebService.Function = API_playMatch;
Gbl.WebService.Function = API_getMatchStatus;
/***** Check web service key *****/
if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK)
@ -4737,46 +4739,40 @@ int swad__playMatch (struct soap *soap,
"Request forbidden",
"Requester can not join this match");
/***** Join match *****/
if (Match.Status.Playing)
{
if (Match.Status.QstInd < Mch_AFTER_LAST_QUESTION) // Unfinished
/* Update players */
playMatchOut->matchCode = Mch_RegisterMeAsPlayerInMatch (&Match) ? matchCode : // > 0 ==> OK
-1; // < 0 ==> can not join this match
else
playMatchOut->matchCode = 0; // == 0 ==> wait
}
else // Not being played
playMatchOut->matchCode = 0; // == 0 ==> wait
return SOAP_OK;
}
/*****************************************************************************/
/*********** Get match status to be refreshed in student's screen ************/
/*****************************************************************************/
int swad__getMatchStatus (struct soap *soap,
char *wsKey,int matchCode, // input
struct swad__getMatchStatusOutput *getMatchStatusOut) // output
{
int ReturnCode;
/***** Initializations *****/
Gbl.soap = soap;
Gbl.WebService.Function = API_getMatchStatus;
/***** Check web service key *****/
if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK)
return ReturnCode;
if (Gbl.Usrs.Me.UsrDat.UsrCod < 0) // Web service key does not exist in database
/***** Check question *****/
if (!Tst_CheckIfQuestionIsValidForGame (Match.Status.QstCod))
return soap_receiver_fault (Gbl.soap,
"Bad web service key",
"Web service key does not exist in database");
"Wrong question",
"Type of answer not valid in a game.");
// TODO: Write the code
getMatchStatusOut->matchCode = matchCode;
/***** Join match *****/
getMatchStatusOut->matchCode = 0; // == 0 ==> wait
if (Match.Status.Playing && // Match is being played
Match.Status.QstInd < Mch_AFTER_LAST_QUESTION) // Unfinished
/* Update players */
getMatchStatusOut->matchCode = Mch_RegisterMeAsPlayerInMatch (&Match) ? matchCode : // > 0 ==> OK
-1; // < 0 ==> can not join this match
/***** Set index of question inside the game *****/
getMatchStatusOut->questionIndex = (int) Match.Status.QstInd;
/***** Set number of answers (options) in question *****/
NumOptions = Tst_GetNumAnswersQst (Match.Status.QstCod);
getMatchStatusOut->numAnswers = (int) NumOptions;
/***** Set number of selected answer *****/
if (NumOptions == 0)
getMatchStatusOut->selected = -1;
else // Answers found
{
/***** Get student's answer to this question
(<0 ==> no answer) *****/
Mch_GetQstAnsFromDB (Match.MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Match.Status.QstInd,
&UsrAnswer);
getMatchStatusOut->selected = UsrAnswer.NumOpt;
}
return SOAP_OK;
}

View File

@ -70,9 +70,8 @@ typedef enum
API_removeAttendanceEvent = 27,
API_getGames = 28,
API_getMatches = 29,
API_playMatch = 30,
API_getMatchStatus = 31,
API_answerMatchQuestion = 32,
API_getMatchStatus = 30,
API_answerMatchQuestion = 31,
} API_Function_t;
/*****************************************************************************/

View File

@ -490,7 +490,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 19.82.3 (2019-12-04)"
#define Log_PLATFORM_VERSION "SWAD 19.83 (2019-12-04)"
#define CSS_FILE "swad19.82.3.css"
#define JS_FILE "swad19.70.js"
/*
@ -498,6 +498,8 @@ ps2pdf source.ps destination.pdf
// TODO: Impedir la creación y edición de proyectos si no son editables.
// TODO: En cada juego, poder listar los resultados en una tabla como la de resultados globales
Version 19.83: Dec 04, 2019 Removed API function playMatch.
API function getMatchStatus finished. (247823 lines)
Version 19.82.3: Dec 04, 2019 Code refactoring in matches.
Some messages translated. (247840 lines)
Version 19.82.2: Dec 03, 2019 Some messages translated. (247781 lines)

View File

@ -28,9 +28,9 @@
/** Uncomment one of the following installations of SWAD or create your own **/
/*****************************************************************************/
#define LOCALHOST_UBUNTU // Comment this line if not applicable
//#define LOCALHOST_UBUNTU // Comment this line if not applicable
//#define OPENSWAD_ORG // Comment this line if not applicable
//#define SWAD_UGR_ES // Comment this line if not applicable
#define SWAD_UGR_ES // Comment this line if not applicable
//#define SWADBERRY_UGR_ES // Comment this line if not applicable
/*****************************************************************************/

View File

@ -178,7 +178,7 @@ static void Mch_PutIconToRemoveMyAnswer (struct Match *Match);
static void Mch_ShowQuestionAndAnswersTch (struct Match *Match);
static void Mch_WriteAnswersMatchResult (struct Match *Match,
const char *Class,bool ShowResult);
static void Mch_ShowQuestionAndAnswersStd (struct Match *Match,
static bool Mch_ShowQuestionAndAnswersStd (struct Match *Match,
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update);
@ -2281,7 +2281,8 @@ static void Mch_ShowRightColumnStd (struct Match *Match,
{
if (Match->Status.Showing == Mch_ANSWERS) // Teacher's screen is showing question answers
/* Show current question and possible answers */
Mch_ShowQuestionAndAnswersStd (Match,UsrAnswer,Update);
if (!Mch_ShowQuestionAndAnswersStd (Match,UsrAnswer,Update))
Ale_ShowAlert (Ale_ERROR,"Wrong question.");
}
else
Ale_ShowAlert (Ale_ERROR,"You can not join this match.");
@ -2651,8 +2652,9 @@ static void Mch_WriteAnswersMatchResult (struct Match *Match,
/*****************************************************************************/
/***** Show question and its answers when playing a match (as a student) *****/
/*****************************************************************************/
// Return true on valid question, false on invalid question
static void Mch_ShowQuestionAndAnswersStd (struct Match *Match,
static bool Mch_ShowQuestionAndAnswersStd (struct Match *Match,
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update)
{
@ -2660,60 +2662,60 @@ static void Mch_ShowQuestionAndAnswersStd (struct Match *Match,
unsigned NumOpt;
char *Class;
/***** Show question *****/
if (Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod))
/***** Trivial check: this question must be valid for games *****/
if (!Tst_CheckIfQuestionIsValidForGame (Match->Status.QstCod))
return false;
/***** Get number of options in this question *****/
NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod);
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (8);
for (NumOpt = 0;
NumOpt < NumOptions;
NumOpt++)
{
/***** Get number of options in this question *****/
NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod);
/***** Start row *****/
HTM_TR_Begin (NULL);
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (8);
/***** Write letter for this option *****/
/* Begin table cell */
HTM_TD_Begin ("class=\"MCH_STD_CELL\"");
for (NumOpt = 0;
NumOpt < NumOptions;
NumOpt++)
{
/***** Start row *****/
HTM_TR_Begin (NULL);
/* Form with button.
Sumitting onmousedown instead of default onclick
is necessary in order to be fast
and not lose clicks due to refresh */
Frm_StartForm (ActAnsMchQstStd);
Mch_PutParamMchCod (Match->MchCod); // Current match being played
Gam_PutParamQstInd (Match->Status.QstInd); // Current question index shown
Mch_PutParamNumOpt (NumOpt); // Number of button
/***** Write letter for this option *****/
/* Begin table cell */
HTM_TD_Begin ("class=\"MCH_STD_CELL\"");
if (asprintf (&Class,"MCH_STD_BUTTON%s BT_%c",
UsrAnswer->NumOpt == (int) NumOpt && // Student's answer
Update == Mch_CHANGE_STATUS_BY_STUDENT ? " MCH_STD_ANSWER_SELECTED" :
"",
'A' + (char) NumOpt) < 0)
Lay_NotEnoughMemoryExit ();
HTM_BUTTON_OnMouseDown_Begin (NULL,Class);
HTM_TxtF ("%c",'a' + (char) NumOpt);
HTM_BUTTON_End ();
free (Class);
/* Form with button.
Sumitting onmousedown instead of default onclick
is necessary in order to be fast
and not lose clicks due to refresh */
Frm_StartForm (ActAnsMchQstStd);
Mch_PutParamMchCod (Match->MchCod); // Current match being played
Gam_PutParamQstInd (Match->Status.QstInd); // Current question index shown
Mch_PutParamNumOpt (NumOpt); // Number of button
Frm_EndForm ();
if (asprintf (&Class,"MCH_STD_BUTTON%s BT_%c",
UsrAnswer->NumOpt == (int) NumOpt && // Student's answer
Update == Mch_CHANGE_STATUS_BY_STUDENT ? " MCH_STD_ANSWER_SELECTED" :
"",
'A' + (char) NumOpt) < 0)
Lay_NotEnoughMemoryExit ();
HTM_BUTTON_OnMouseDown_Begin (NULL,Class);
HTM_TxtF ("%c",'a' + (char) NumOpt);
HTM_BUTTON_End ();
free (Class);
/* End table cell */
HTM_TD_End ();
Frm_EndForm ();
/* End table cell */
HTM_TD_End ();
/***** End row *****/
HTM_TR_End ();
}
/***** End table *****/
HTM_TABLE_End ();
/***** End row *****/
HTM_TR_End ();
}
else
Ale_ShowAlert (Ale_ERROR,"Type of answer not valid in a game.");
/***** End table *****/
HTM_TABLE_End ();
return true;
}
/*****************************************************************************/