Version 22.107.6: May 06, 2023 Code refactoring in edition of exam.

This commit is contained in:
acanas 2023-05-06 14:44:50 +02:00
parent deecbe7e63
commit 63705c66a2
5 changed files with 83 additions and 87 deletions

View File

@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr
TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen.
*/ */
#define Log_PLATFORM_VERSION "SWAD 22.107.5 (2023-05-06)" #define Log_PLATFORM_VERSION "SWAD 22.107.6 (2023-05-06)"
#define CSS_FILE "swad22.107.css" #define CSS_FILE "swad22.107.css"
#define JS_FILE "swad22.49.js" #define JS_FILE "swad22.49.js"
/* /*
Version 22.107.6: May 06, 2023 Code refactoring in edition of exam. (338023 lines)
Version 22.107.5: May 06, 2023 Changes in edition of rubric. (338027 lines) Version 22.107.5: May 06, 2023 Changes in edition of rubric. (338027 lines)
Version 22.107.4: May 06, 2023 Changes in edition of exam. (338040 lines) Version 22.107.4: May 06, 2023 Changes in edition of exam. (338040 lines)
Version 22.107.3: May 06, 2023 Changes in edition of exam. (338045 lines) Version 22.107.3: May 06, 2023 Changes in edition of exam. (338045 lines)

View File

@ -1227,7 +1227,7 @@ void Exa_ReqCreatOrEditExam (void)
{ {
struct Exa_Exams Exams; struct Exa_Exams Exams;
struct ExaSet_Set Set; struct ExaSet_Set Set;
bool ItsANewExam; Exa_ExistingNewExam_t ExistingNewExam;
/***** Check if I can edit exams *****/ /***** Check if I can edit exams *****/
if (!Exa_CheckIfICanEditExams ()) if (!Exa_CheckIfICanEditExams ())
@ -1240,18 +1240,22 @@ void Exa_ReqCreatOrEditExam (void)
/***** Get parameters *****/ /***** Get parameters *****/
Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD); Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD);
ItsANewExam = (Exams.Exam.ExaCod <= 0); ExistingNewExam = (Exams.Exam.ExaCod > 0) ? Exa_EXISTING_EXAM :
Exa_NEW_EXAM;
/***** Get exam data *****/ /***** Get exam data *****/
if (ItsANewExam) switch (ExistingNewExam)
/* Initialize to empty exam */ {
Exa_ResetExam (&Exams.Exam); case Exa_EXISTING_EXAM:
else /* Get exam data from database */
/* Get exam data from database */ Exa_GetExamDataByCod (&Exams.Exam);
Exa_GetExamDataByCod (&Exams.Exam); break;
case Exa_NEW_EXAM:
break;
}
/***** Put form to create/edit an exam and show sets *****/ /***** Put form to create/edit an exam and show sets *****/
Exa_PutFormsOneExam (&Exams,&Set,ItsANewExam); Exa_PutFormsOneExam (&Exams,&Set,ExistingNewExam);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1430,7 +1434,7 @@ void Exa_ReceiveFormExam (void)
{ {
struct Exa_Exams Exams; struct Exa_Exams Exams;
struct ExaSet_Set Set; struct ExaSet_Set Set;
bool ItsANewExam; Exa_ExistingNewExam_t ExistingNewExam;
char Txt[Cns_MAX_BYTES_TEXT + 1]; char Txt[Cns_MAX_BYTES_TEXT + 1];
/***** Check if I can edit exams *****/ /***** Check if I can edit exams *****/
@ -1444,31 +1448,41 @@ void Exa_ReceiveFormExam (void)
/***** Get parameters *****/ /***** Get parameters *****/
Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD); Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD);
ItsANewExam = (Exams.Exam.ExaCod <= 0); ExistingNewExam = (Exams.Exam.ExaCod > 0) ? Exa_EXISTING_EXAM :
Exa_NEW_EXAM;
/***** Get all current exam data from database *****/ /***** Get all current exam data from database *****/
// Some data, not received from form, // Some data, not received from form,
// are necessary to show exam and sets of questions again // are necessary to show exam and sets of questions again
if (!ItsANewExam) switch (ExistingNewExam)
Exa_GetExamDataByCod (&Exams.Exam); {
case Exa_EXISTING_EXAM:
Exa_GetExamDataByCod (&Exams.Exam);
break;
case Exa_NEW_EXAM:
break;
}
/***** Overwrite some exam data with the data received from form *****/ /***** Overwrite some exam data with the data received from form *****/
Exa_ReceiveExamFieldsFromForm (&Exams.Exam,Txt); Exa_ReceiveExamFieldsFromForm (&Exams.Exam,Txt);
if (Exa_CheckExamFieldsReceivedFromForm (&Exams.Exam)) if (Exa_CheckExamFieldsReceivedFromForm (&Exams.Exam))
{
/***** Create a new exam or update an existing one *****/ /***** Create a new exam or update an existing one *****/
if (ItsANewExam) switch (ExistingNewExam)
{ {
Exa_CreateExam (&Exams.Exam,Txt); // Add new exam to database case Exa_EXISTING_EXAM:
ItsANewExam = false; Exa_UpdateExam (&Exams.Exam,Txt); // Update exam data in database
break;
case Exa_NEW_EXAM:
Exa_CreateExam (&Exams.Exam,Txt); // Add new exam to database
ExistingNewExam = Exa_EXISTING_EXAM;
break;
} }
else
Exa_UpdateExam (&Exams.Exam,Txt); // Update exam data in database /***** Show pending alerts */
} Ale_ShowAlerts (NULL);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,ExistingNewExam);
ItsANewExam);
} }
static void Exa_ReceiveExamFieldsFromForm (struct Exa_Exam *Exam, static void Exa_ReceiveExamFieldsFromForm (struct Exa_Exam *Exam,
@ -1506,8 +1520,9 @@ static bool Exa_CheckExamFieldsReceivedFromForm (const struct Exa_Exam *Exam)
Exam->ExaCod,Exam->Title)) Exam->ExaCod,Exam->Title))
{ {
NewExamIsCorrect = false; NewExamIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_an_exam_with_the_title_X, Ale_CreateAlert (Ale_WARNING,NULL,
Exam->Title); Txt_Already_existed_an_exam_with_the_title_X,
Exam->Title);
} }
} }
else // If there is not an exam title else // If there is not an exam title

View File

@ -269,8 +269,7 @@ void ExaSet_ReceiveFormSet (void)
ExaSet_CreateSet (&Set); // Add new set to database ExaSet_CreateSet (&Set); // Add new set to database
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
static void ExaSet_ReceiveSetFieldsFromForm (struct ExaSet_Set *Set) static void ExaSet_ReceiveSetFieldsFromForm (struct ExaSet_Set *Set)
@ -357,8 +356,7 @@ void ExaSet_ChangeSetTitle (void)
} }
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -404,8 +402,7 @@ void ExaSet_ChangeNumQstsToExam (void)
} }
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -450,8 +447,7 @@ void ExaSet_ReqSelectQstsToAddToSet (void)
Qst_RequestSelectQstsForExamSet (&Exams); Qst_RequestSelectQstsForExamSet (&Exams);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -479,8 +475,7 @@ void ExaSet_ListQstsToAddToSet (void)
Qst_ListQuestionsToSelectForExamSet (&Exams); Qst_ListQuestionsToSelectForExamSet (&Exams);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1144,8 +1139,7 @@ void ExaSet_AddQstsToSet (void)
ExaSet_FreeListsSelectedQuestions (&Exams); ExaSet_FreeListsSelectedQuestions (&Exams);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1275,8 +1269,7 @@ void ExaSet_ReqRemSet (void)
Set.Title); Set.Title);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1315,8 +1308,7 @@ void ExaSet_RemoveSet (void)
Ale_ShowAlert (Ale_SUCCESS,Txt_Set_of_questions_removed); Ale_ShowAlert (Ale_SUCCESS,Txt_Set_of_questions_removed);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1361,8 +1353,7 @@ void ExaSet_MoveUpSet (void)
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed); Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1411,8 +1402,7 @@ void ExaSet_MoveDownSet (void)
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed); Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1452,8 +1442,7 @@ void ExaSet_ReqRemQstFromSet (void)
Frm_FreeAnchorStr (&Anchor); Frm_FreeAnchorStr (&Anchor);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1489,8 +1478,7 @@ void ExaSet_RemoveQstFromSet (void)
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed); Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1564,8 +1552,7 @@ static void ExaSet_ChangeValidityQst (Qst_Validity_t Validity)
Validity); Validity);
/***** Show current exam and its sets *****/ /***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Set, Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM);
false); // It's not a new exam
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -144,9 +144,9 @@ static Gam_Order_t Gam_GetParOrder (void);
static void Gam_RemoveGameFromAllTables (long GamCod); static void Gam_RemoveGameFromAllTables (long GamCod);
static void Gam_PutFormsEditionGame (struct Gam_Games *Games, static void Gam_PutFormEditionGame (struct Gam_Games *Games,
char Txt[Cns_MAX_BYTES_TEXT + 1], char Txt[Cns_MAX_BYTES_TEXT + 1],
Gam_ExistingNewGame_t ExistingNewGame); Gam_ExistingNewGame_t ExistingNewGame);
static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game,
char Txt[Cns_MAX_BYTES_TEXT + 1]); char Txt[Cns_MAX_BYTES_TEXT + 1]);
static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game); static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game);
@ -1268,7 +1268,7 @@ void Gam_ReqCreatOrEditGame (void)
} }
/***** Put forms to create/edit a game *****/ /***** Put forms to create/edit a game *****/
Gam_PutFormsEditionGame (&Games,Txt,ExistingNewGame); Gam_PutFormEditionGame (&Games,Txt,ExistingNewGame);
/***** Show games or questions *****/ /***** Show games or questions *****/
switch (ExistingNewGame) switch (ExistingNewGame)
@ -1288,9 +1288,9 @@ void Gam_ReqCreatOrEditGame (void)
/********************* Put a form to create/edit a game **********************/ /********************* Put a form to create/edit a game **********************/
/*****************************************************************************/ /*****************************************************************************/
static void Gam_PutFormsEditionGame (struct Gam_Games *Games, static void Gam_PutFormEditionGame (struct Gam_Games *Games,
char Txt[Cns_MAX_BYTES_TEXT + 1], char Txt[Cns_MAX_BYTES_TEXT + 1],
Gam_ExistingNewGame_t ExistingNewGame) Gam_ExistingNewGame_t ExistingNewGame)
{ {
extern const char *Hlp_ASSESSMENT_Games_edit_game; extern const char *Hlp_ASSESSMENT_Games_edit_game;
extern const char *Hlp_ASSESSMENT_Games_new_game; extern const char *Hlp_ASSESSMENT_Games_new_game;
@ -1447,7 +1447,6 @@ void Gam_ReceiveFormGame (void)
/***** Receive game from form *****/ /***** Receive game from form *****/
Gam_ReceiveGameFieldsFromForm (&Games.Game,Txt); Gam_ReceiveGameFieldsFromForm (&Games.Game,Txt);
if (Gam_CheckGameFieldsReceivedFromForm (&Games.Game)) if (Gam_CheckGameFieldsReceivedFromForm (&Games.Game))
{
/***** Create a new game or update an existing one *****/ /***** Create a new game or update an existing one *****/
switch (ExistingNewGame) switch (ExistingNewGame)
{ {
@ -1456,34 +1455,28 @@ void Gam_ReceiveFormGame (void)
break; break;
case Gam_NEW_GAME: case Gam_NEW_GAME:
Gam_CreateGame (&Games.Game,Txt); // Add new game to database Gam_CreateGame (&Games.Game,Txt); // Add new game to database
ExistingNewGame = Gam_EXISTING_GAME;
break; break;
} }
/***** Put forms to edit the game created or updated *****/ /***** Show pending alerts */
Gam_PutFormsEditionGame (&Games,Txt,Gam_EXISTING_GAME); Ale_ShowAlerts (NULL);
/***** Show questions of the game ready to be edited ******/ /***** Put forms to create/edit the game *****/
Gam_ListGameQuestions (&Games); Gam_PutFormEditionGame (&Games,Txt,ExistingNewGame);
}
else /***** Show games or questions *****/
switch (ExistingNewGame)
{ {
/***** Put forms to create/edit the game *****/ case Gam_EXISTING_GAME:
Gam_PutFormsEditionGame (&Games,Txt,ExistingNewGame); /* Show questions of the game ready to be edited */
Gam_ListGameQuestions (&Games);
/***** Show games or questions *****/ break;
switch (ExistingNewGame) case Gam_NEW_GAME:
{ /* Show games again */
case Gam_EXISTING_GAME: Gam_ListAllGames (&Games);
/* Show questions of the game ready to be edited */ break;
Gam_ListGameQuestions (&Games);
break;
case Gam_NEW_GAME:
/* Show games again */
Gam_ListAllGames (&Games);
break;
}
} }
} }
static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game,
@ -1520,8 +1513,9 @@ static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game)
if (Gam_DB_CheckIfSimilarGameExists (Game)) if (Gam_DB_CheckIfSimilarGameExists (Game))
{ {
NewGameIsCorrect = false; NewGameIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_game_with_the_title_X, Ale_CreateAlert (Ale_WARNING,NULL,
Game->Title); Txt_Already_existed_a_game_with_the_title_X,
Game->Title);
} }
} }
else // If there is not a game title else // If there is not a game title

View File

@ -976,7 +976,6 @@ void Rub_ReceiveFormRubric (void)
/***** Overwrite some rubric data with the data received from form *****/ /***** Overwrite some rubric data with the data received from form *****/
Rub_ReceiveRubricFieldsFromForm (&Rubrics.Rubric); Rub_ReceiveRubricFieldsFromForm (&Rubrics.Rubric);
if (Rub_CheckRubricFieldsReceivedFromForm (&Rubrics.Rubric)) if (Rub_CheckRubricFieldsReceivedFromForm (&Rubrics.Rubric))
{
/***** Create a new rubric or update an existing one *****/ /***** Create a new rubric or update an existing one *****/
switch (ExistingNewRubric) switch (ExistingNewRubric)
{ {
@ -988,7 +987,6 @@ void Rub_ReceiveFormRubric (void)
ExistingNewRubric = Rub_EXISTING_RUBRIC; ExistingNewRubric = Rub_EXISTING_RUBRIC;
break; break;
} }
}
/***** Show pending alerts */ /***** Show pending alerts */
Ale_ShowAlerts (NULL); Ale_ShowAlerts (NULL);
@ -1022,8 +1020,9 @@ static bool Rub_CheckRubricFieldsReceivedFromForm (const struct Rub_Rubric *Rubr
if (Rub_DB_CheckIfSimilarRubricExists (Rubric)) if (Rub_DB_CheckIfSimilarRubricExists (Rubric))
{ {
NewRubricIsCorrect = false; NewRubricIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_game_with_the_title_X, Ale_CreateAlert (Ale_WARNING,NULL,
Rubric->Title); Txt_Already_existed_a_game_with_the_title_X,
Rubric->Title);
} }
} }
else // If there is not a rubric title else // If there is not a rubric title