diff --git a/swad_changelog.h b/swad_changelog.h index fd7d018d..c505a6ff 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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 20.96.2 (2021-09-08)" +#define Log_PLATFORM_VERSION "SWAD 20.96.3 (2021-09-08)" #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 20.96.3: Sep 08, 2021 Queries moved to module swad_exam_database. (314384 lines) Version 20.96.2: Sep 08, 2021 Queries moved to module swad_exam_database. (314362 lines) Version 20.96.1: Jul 30, 2021 Fix bugs removing exams. (314373 lines) Version 20.96: Jul 27, 2021 Queries moved to module swad_exam_database. (314247 lines) diff --git a/swad_exam_database.c b/swad_exam_database.c index b4ed09a7..56af4bc3 100644 --- a/swad_exam_database.c +++ b/swad_exam_database.c @@ -485,6 +485,21 @@ unsigned Exa_DB_GetNumQstsInSet (long SetCod) SetCod); } +/*****************************************************************************/ +/*********************** Get all questions from a set ************************/ +/*****************************************************************************/ + +unsigned Exa_DB_GetQstsFromSet (MYSQL_RES **mysql_res,long SetCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get questions from set", + "SELECT QstCod" // row[0] + " FROM exa_set_questions" + " WHERE SetCod=%ld" + " ORDER BY Stem", + SetCod); + } + /*****************************************************************************/ /******************* Get some random questions from a set ********************/ /*****************************************************************************/ @@ -505,11 +520,30 @@ unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res, NumQstsToPrint); } +/*****************************************************************************/ +/********************* Get data from a question in a set *********************/ +/*****************************************************************************/ + +unsigned Exa_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get a question", + "SELECT Invalid," // row[0] + "AnsType," // row[1] + "Shuffle," // row[2] + "Stem," // row[3] + "Feedback," // row[4] + "MedCod" // row[5] + " FROM exa_set_questions" + " WHERE QstCod=%ld", + QstCod); + } + /*****************************************************************************/ /********** Get validity and answer type from a question in a set ************/ /*****************************************************************************/ -unsigned Exa_DB_GetValidityAndTypeOfQuestion (MYSQL_RES **mysql_res,long QstCod) +unsigned Exa_DB_GetValidityAndAnswerType (MYSQL_RES **mysql_res,long QstCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get a question", @@ -520,6 +554,20 @@ unsigned Exa_DB_GetValidityAndTypeOfQuestion (MYSQL_RES **mysql_res,long QstCod) QstCod); } +/*****************************************************************************/ +/***************** Get answer type from a question in a set ******************/ +/*****************************************************************************/ + +unsigned Exa_DB_GetAnswerType (MYSQL_RES **mysql_res,long QstCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get a question", + "SELECT AnsType" // row[0] + " FROM exa_set_questions" + " WHERE QstCod=%ld", + QstCod); + } + /*****************************************************************************/ /********* Remove the questions in sets of questions from an exam ************/ /*****************************************************************************/ diff --git a/swad_exam_database.h b/swad_exam_database.h index 7889d0b4..8fdc1bc7 100644 --- a/swad_exam_database.h +++ b/swad_exam_database.h @@ -69,9 +69,12 @@ void Exa_DB_RemoveSetsFromExam (long ExaCod); void Exa_DB_RemoveSetsFromCrs (long CrsCod); unsigned Exa_DB_GetNumQstsInSet (long SetCod); +unsigned Exa_DB_GetQstsFromSet (MYSQL_RES **mysql_res,long SetCod); unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res, long SetCod,unsigned NumQstsToPrint); -unsigned Exa_DB_GetValidityAndTypeOfQuestion (MYSQL_RES **mysql_res,long QstCod); +unsigned Exa_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod); +unsigned Exa_DB_GetValidityAndAnswerType (MYSQL_RES **mysql_res,long QstCod); +unsigned Exa_DB_GetAnswerType (MYSQL_RES **mysql_res,long QstCod); void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod); void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod); diff --git a/swad_exam_print.c b/swad_exam_print.c index a0a880d5..96ed5fbc 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -1091,7 +1091,7 @@ static void ExaPrn_ComputeScoreAndStoreQuestionOfPrint (struct ExaPrn_Print *Pri /***** Compute question score *****/ Tst_QstConstructor (&Question); Question.QstCod = Print->PrintedQuestions[QstInd].QstCod; - Question.Answer.Type = ExaSet_GetQstAnswerTypeFromDB (Question.QstCod); + Question.Answer.Type = ExaSet_GetAnswerType (Question.QstCod); ExaPrn_ComputeAnswerScore (&Print->PrintedQuestions[QstInd],&Question); Tst_QstDestructor (&Question); diff --git a/swad_exam_result.c b/swad_exam_result.c index 8473b2b1..1cdcb140 100644 --- a/swad_exam_result.c +++ b/swad_exam_result.c @@ -1448,7 +1448,7 @@ static void ExaRes_ComputeValidPrintScore (struct ExaPrn_Print *Print) Question.QstCod = Print->PrintedQuestions[QstInd].QstCod; /***** Get validity and answer type from database *****/ - if ((QuestionExists = (Exa_DB_GetValidityAndTypeOfQuestion (&mysql_res,Question.QstCod) != 0))) + if ((QuestionExists = (Exa_DB_GetValidityAndAnswerType (&mysql_res,Question.QstCod) != 0))) { row = mysql_fetch_row (mysql_res); diff --git a/swad_exam_set.c b/swad_exam_set.c index 9d5be3cf..7e65973b 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -682,36 +682,25 @@ static void ExaSet_ListSetQuestions (struct Exa_Exams *Exams, unsigned NumQsts; bool ICanEditQuestions = Exa_CheckIfEditable (Exam); - /***** Get data of questions from database *****/ - NumQsts = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get exam questions", - "SELECT QstCod" // row[0] - " FROM exa_set_questions" - " WHERE SetCod=%ld" - " ORDER BY Stem", - Set->SetCod); - /***** Begin box *****/ - if (ICanEditQuestions) - Box_BoxBegin (NULL,Txt_Questions, - ExaSet_PutIconToAddNewQuestions,Exams, - Hlp_ASSESSMENT_Exams_questions,Box_NOT_CLOSABLE); - else - Box_BoxBegin (NULL,Txt_Questions, - NULL,NULL, - Hlp_ASSESSMENT_Exams_questions,Box_NOT_CLOSABLE); + Box_BoxBegin (NULL,Txt_Questions, + ICanEditQuestions ? ExaSet_PutIconToAddNewQuestions : + NULL, + ICanEditQuestions ? Exams : + NULL, + Hlp_ASSESSMENT_Exams_questions,Box_NOT_CLOSABLE); - /***** Show table with questions *****/ - if (NumQsts) - ExaSet_ListOneOrMoreQuestionsForEdition (Exams,NumQsts,mysql_res, - ICanEditQuestions); + /***** Show table with questions *****/ + if ((NumQsts = Exa_DB_GetQstsFromSet (&mysql_res,Set->SetCod))) + ExaSet_ListOneOrMoreQuestionsForEdition (Exams,NumQsts,mysql_res, + ICanEditQuestions); - /***** Put button to add a new question in this set *****/ - if (ICanEditQuestions) // I can edit questions - ExaSet_PutButtonToAddNewQuestions (Exams); + /***** Put button to add a new question in this set *****/ + if (ICanEditQuestions) // I can edit questions + ExaSet_PutButtonToAddNewQuestions (Exams); - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); /***** End box *****/ Box_BoxEnd (); @@ -1049,18 +1038,14 @@ static void ExaSet_ListOneOrMoreQuestionsForEdition (struct Exa_Exams *Exams, /*************** Get answer type of a question from database *****************/ /*****************************************************************************/ -Tst_AnswerType_t ExaSet_GetQstAnswerTypeFromDB (long QstCod) +Tst_AnswerType_t ExaSet_GetAnswerType (long QstCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; Tst_AnswerType_t AnswerType; /***** Get type of answer from database *****/ - if (!DB_QuerySELECT (&mysql_res,"can not get the type of a question", - "SELECT AnsType" // row[0] - " FROM exa_set_questions" - " WHERE QstCod=%ld", - QstCod)) + if (!Exa_DB_GetAnswerType (&mysql_res,QstCod)) Err_WrongQuestionExit (); /* Get type of answer */ @@ -1085,18 +1070,7 @@ void ExaSet_GetQstDataFromDB (struct Tst_Question *Question) unsigned NumOpt; /***** Get question data from database *****/ - QuestionExists = (DB_QuerySELECT (&mysql_res,"can not get a question", - "SELECT Invalid," // row[0] - "AnsType," // row[1] - "Shuffle," // row[2] - "Stem," // row[3] - "Feedback," // row[4] - "MedCod" // row[5] - " FROM exa_set_questions" - " WHERE QstCod=%ld", - Question->QstCod) != 0); - - if (QuestionExists) + if ((QuestionExists = (Exa_DB_GetQstDataByCod (&mysql_res,Question->QstCod) != 0))) { row = mysql_fetch_row (mysql_res); diff --git a/swad_exam_set.h b/swad_exam_set.h index 8d7cf09a..e26b3b6a 100644 --- a/swad_exam_set.h +++ b/swad_exam_set.h @@ -58,7 +58,7 @@ void ExaSet_ListExamSets (struct Exa_Exams *Exams, void ExaSet_ResetSet (struct ExaSet_Set *Set); -Tst_AnswerType_t ExaSet_GetQstAnswerTypeFromDB (long QstCod); +Tst_AnswerType_t ExaSet_GetAnswerType (long QstCod); void ExaSet_GetQstDataFromDB (struct Tst_Question *Question); void ExaSet_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res, bool Shuffle);