Version 20.96.4: Sep 08, 2021 Queries moved to module swad_exam_database.

This commit is contained in:
acanas 2021-09-08 22:18:54 +02:00
parent c8f9d9baad
commit 40c16c865f
6 changed files with 105 additions and 69 deletions

View File

@ -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 20.96.3 (2021-09-08)" #define Log_PLATFORM_VERSION "SWAD 20.96.4 (2021-09-08)"
#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 20.96.4: Sep 08, 2021 Queries moved to module swad_exam_database. (314414 lines)
Version 20.96.3: Sep 08, 2021 Queries moved to module swad_exam_database. (314384 lines) 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.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.1: Jul 30, 2021 Fix bugs removing exams. (314373 lines)

View File

@ -470,6 +470,37 @@ void Exa_DB_RemoveSetsFromCrs (long CrsCod)
CrsCod); CrsCod);
} }
/*****************************************************************************/
/******************* Insert question in table of questions *******************/
/*****************************************************************************/
long Exa_DB_AddQuestionToSet (long SetCod,const struct Tst_Question *Question,long MedCod)
{
extern const char *Tst_StrAnswerTypesDB[Tst_NUM_ANS_TYPES];
static char CharInvalid[Tst_NUM_VALIDITIES] =
{
[Tst_INVALID_QUESTION] = 'Y',
[Tst_VALID_QUESTION ] = 'N'
};
return
DB_QueryINSERTandReturnCode ("can not add question to set",
"INSERT INTO exa_set_questions"
" (SetCod,Invalid,AnsType,Shuffle,"
"Stem,Feedback,MedCod)"
" VALUES"
" (%ld,'%c','%s','%c',"
"'%s','%s',%ld)",
SetCod,
CharInvalid[Question->Validity],
Tst_StrAnswerTypesDB[Question->Answer.Type],
Question->Answer.Shuffle ? 'Y' :
'N',
Question->Stem,
Question->Feedback,
MedCod);
}
/*****************************************************************************/ /*****************************************************************************/
/********************* Get number of questions in a set **********************/ /********************* Get number of questions in a set **********************/
/*****************************************************************************/ /*****************************************************************************/
@ -600,6 +631,57 @@ void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod)
CrsCod); CrsCod);
} }
/*****************************************************************************/
/********************* Add one answer to question in set *********************/
/*****************************************************************************/
void Exa_DB_AddAnsToQstInSet (long QstCod,unsigned AnsInd,
const char *Answer,const char *Feedback,
long MedCod,bool Correct)
{
DB_QueryINSERT ("can not add answer to set",
"INSERT INTO exa_set_answers"
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)"
" VALUES"
" (%ld,%u,'%s','%s',%ld,'%c')",
QstCod, // Question code in set
AnsInd, // Answer index (number of option)
Answer, // Copy of text
Feedback, // Copy of feedback
MedCod, // Media code of the new cloned media
Correct ? 'Y' :
'N'); // Copy of correct
}
/*****************************************************************************/
/*************** Get answers of a test question from database ****************/
/*****************************************************************************/
unsigned Exa_DB_GetQstAnswersFromSet (MYSQL_RES **mysql_res,long QstCod,bool Shuffle)
{
unsigned NumOptions;
/***** Get answers of a question from database *****/
NumOptions = (unsigned)
DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd," // row[0]
"Answer," // row[1]
"Feedback," // row[2]
"MedCod," // row[3]
"Correct" // row[4]
" FROM exa_set_answers"
" WHERE QstCod=%ld"
" ORDER BY %s",
QstCod,
Shuffle ? "RAND()" :
"AnsInd");
if (!NumOptions)
Ale_ShowAlert (Ale_ERROR,"Error when getting answers of a question.");
return NumOptions;
}
/*****************************************************************************/ /*****************************************************************************/
/************** Get answers text for a question in an exam set ***************/ /************** Get answers text for a question in an exam set ***************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -68,6 +68,7 @@ unsigned Exa_DB_GetNextSetIndexInExam (long ExaCod,unsigned SetInd);
void Exa_DB_RemoveSetsFromExam (long ExaCod); void Exa_DB_RemoveSetsFromExam (long ExaCod);
void Exa_DB_RemoveSetsFromCrs (long CrsCod); void Exa_DB_RemoveSetsFromCrs (long CrsCod);
long Exa_DB_AddQuestionToSet (long SetCod,const struct Tst_Question *Question,long MedCod);
unsigned Exa_DB_GetNumQstsInSet (long SetCod); unsigned Exa_DB_GetNumQstsInSet (long SetCod);
unsigned Exa_DB_GetQstsFromSet (MYSQL_RES **mysql_res,long SetCod); unsigned Exa_DB_GetQstsFromSet (MYSQL_RES **mysql_res,long SetCod);
unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res, unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res,
@ -78,6 +79,10 @@ unsigned Exa_DB_GetAnswerType (MYSQL_RES **mysql_res,long QstCod);
void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod); void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod);
void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod); void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod);
void Exa_DB_AddAnsToQstInSet (long QstCod,unsigned AnsInd,
const char *Answer,const char *Feedback,
long MedCod,bool Correct);
unsigned Exa_DB_GetQstAnswersFromSet (MYSQL_RES **mysql_res,long QstCod,bool Shuffle);
unsigned Exa_DB_GetQstAnswersTextFromSet (MYSQL_RES **mysql_res,long QstCod); unsigned Exa_DB_GetQstAnswersTextFromSet (MYSQL_RES **mysql_res,long QstCod);
unsigned Exa_DB_GetQstAnswersCorrFromSet (MYSQL_RES **mysql_res,long QstCod); unsigned Exa_DB_GetQstAnswersCorrFromSet (MYSQL_RES **mysql_res,long QstCod);
void Exa_DB_RemoveSetAnswersFromExam (long ExaCod); void Exa_DB_RemoveSetAnswersFromExam (long ExaCod);

View File

@ -479,7 +479,9 @@ static void ExaPrn_GenerateChoiceIndexes (struct TstPrn_PrintedQuestion *Printed
Question.QstCod = PrintedQuestion->QstCod; Question.QstCod = PrintedQuestion->QstCod;
/***** Get answers of question from database *****/ /***** Get answers of question from database *****/
ExaSet_GetAnswersQst (&Question,&mysql_res,Shuffle); Question.Answer.NumOptions = Exa_DB_GetQstAnswersFromSet (&mysql_res,
Question.QstCod,
Shuffle);
/* /*
row[0] AnsInd row[0] AnsInd
row[1] Answer row[1] Answer
@ -487,7 +489,6 @@ static void ExaPrn_GenerateChoiceIndexes (struct TstPrn_PrintedQuestion *Printed
row[3] MedCod row[3] MedCod
row[4] Correct row[4] Correct
*/ */
for (NumOpt = 0; for (NumOpt = 0;
NumOpt < Question.Answer.NumOptions; NumOpt < Question.Answer.NumOptions;
NumOpt++) NumOpt++)

View File

@ -114,7 +114,7 @@ static void ExaSet_ListQuestionForEdition (struct Tst_Question *Question,
static void ExaSet_AllocateListSelectedQuestions (struct Exa_Exams *Exams); static void ExaSet_AllocateListSelectedQuestions (struct Exa_Exams *Exams);
static void ExaSet_FreeListsSelectedQuestions (struct Exa_Exams *Exams); static void ExaSet_FreeListsSelectedQuestions (struct Exa_Exams *Exams);
static void ExaSet_CopyQstFromBankToExamSet (struct ExaSet_Set *Set,long QstCod); static void ExaSet_CopyQstFromBankToExamSet (const struct ExaSet_Set *Set,long QstCod);
static void ExaSet_RemoveMediaFromStemOfQst (long SetCod,long QstCod); static void ExaSet_RemoveMediaFromStemOfQst (long SetCod,long QstCod);
static void ExaSet_RemoveMediaFromAllAnsOfQst (long SetCod,long QstCod); static void ExaSet_RemoveMediaFromAllAnsOfQst (long SetCod,long QstCod);
@ -1104,8 +1104,9 @@ void ExaSet_GetQstDataFromDB (struct Tst_Question *Question)
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
/***** Get the answers from the database *****/ /***** Get the answers from the database *****/
ExaSet_GetAnswersQst (Question,&mysql_res, Question->Answer.NumOptions = Exa_DB_GetQstAnswersFromSet (&mysql_res,
false); // Don't shuffle Question->QstCod,
false); // Don't shuffle
/* /*
row[0] AnsInd row[0] AnsInd
row[1] Answer row[1] Answer
@ -1179,32 +1180,6 @@ void ExaSet_GetQstDataFromDB (struct Tst_Question *Question)
Err_WrongQuestionExit (); Err_WrongQuestionExit ();
} }
/*****************************************************************************/
/*************** Get answers of a test question from database ****************/
/*****************************************************************************/
void ExaSet_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res,
bool Shuffle)
{
/***** Get answers of a question from database *****/
Question->Answer.NumOptions = (unsigned)
DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd," // row[0]
"Answer," // row[1]
"Feedback," // row[2]
"MedCod," // row[3]
"Correct" // row[4]
" FROM exa_set_answers"
" WHERE QstCod=%ld"
" ORDER BY %s",
Question->QstCod,
Shuffle ? "RAND()" :
"AnsInd");
if (!Question->Answer.NumOptions)
Ale_ShowAlert (Ale_ERROR,"Error when getting answers of a question.");
}
/*****************************************************************************/ /*****************************************************************************/
/********************* List question in set for edition **********************/ /********************* List question in set for edition **********************/
/*****************************************************************************/ /*****************************************************************************/
@ -1355,9 +1330,8 @@ static void ExaSet_FreeListsSelectedQuestions (struct Exa_Exams *Exams)
/******* Copy question and answers from back of questions to exam set ********/ /******* Copy question and answers from back of questions to exam set ********/
/*****************************************************************************/ /*****************************************************************************/
static void ExaSet_CopyQstFromBankToExamSet (struct ExaSet_Set *Set,long QstCod) static void ExaSet_CopyQstFromBankToExamSet (const struct ExaSet_Set *Set,long QstCod)
{ {
extern const char *Tst_StrAnswerTypesDB[Tst_NUM_ANS_TYPES];
extern const char *Txt_Question_removed; extern const char *Txt_Question_removed;
struct Tst_Question Question; struct Tst_Question Question;
long CloneMedCod; long CloneMedCod;
@ -1365,11 +1339,6 @@ static void ExaSet_CopyQstFromBankToExamSet (struct ExaSet_Set *Set,long QstCod)
unsigned NumOpt; unsigned NumOpt;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
static char CharInvalid[Tst_NUM_VALIDITIES] =
{
[Tst_INVALID_QUESTION] = 'Y',
[Tst_VALID_QUESTION ] = 'N'
};
/***** Create test question *****/ /***** Create test question *****/
Tst_QstConstructor (&Question); Tst_QstConstructor (&Question);
@ -1381,23 +1350,8 @@ static void ExaSet_CopyQstFromBankToExamSet (struct ExaSet_Set *Set,long QstCod)
/***** Clone media *****/ /***** Clone media *****/
CloneMedCod = Med_CloneMedia (&Question.Media); CloneMedCod = Med_CloneMedia (&Question.Media);
/***** Insert question in table of questions *****/ /***** Add question to set *****/
QstCodInSet = QstCodInSet = Exa_DB_AddQuestionToSet (Set->SetCod,&Question,CloneMedCod);
DB_QueryINSERTandReturnCode ("can not add question to set",
"INSERT INTO exa_set_questions"
" (SetCod,Invalid,AnsType,Shuffle,"
"Stem,Feedback,MedCod)"
" VALUES"
" (%ld,'%c','%s','%c',"
"'%s','%s',%ld)",
Set->SetCod,
CharInvalid[Question.Validity],
Tst_StrAnswerTypesDB[Question.Answer.Type],
Question.Answer.Shuffle ? 'Y' :
'N',
Question.Stem,
Question.Feedback,
CloneMedCod);
/***** Get the answers from the database *****/ /***** Get the answers from the database *****/
Tst_GetAnswersQst (&Question,&mysql_res, Tst_GetAnswersQst (&Question,&mysql_res,
@ -1423,17 +1377,12 @@ static void ExaSet_CopyQstFromBankToExamSet (struct ExaSet_Set *Set,long QstCod)
CloneMedCod = Med_CloneMedia (&Question.Answer.Options[NumOpt].Media); CloneMedCod = Med_CloneMedia (&Question.Answer.Options[NumOpt].Media);
/* Copy answer option to exam set */ /* Copy answer option to exam set */
DB_QueryINSERT ("can not add answer to set", Exa_DB_AddAnsToQstInSet (QstCodInSet, // Question code in set
"INSERT INTO exa_set_answers" NumOpt, // Answer index (number of option)
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)" row[1], // Copy of text
" VALUES" row[2], // Copy of feedback
" (%ld,%u,'%s','%s',%ld,'%s')", CloneMedCod, // Media code of the new cloned media
QstCodInSet, // Question code in set row[4][0] == 'Y'); // Copy of correct
NumOpt, // Answer index (number of option)
row[1], // Copy of text
row[2], // Copy of feedback
CloneMedCod, // Media code of the new cloned media
row[4]); // Copy of correct
} }
/* Free structure that stores the query result */ /* Free structure that stores the query result */

View File

@ -60,8 +60,6 @@ void ExaSet_ResetSet (struct ExaSet_Set *Set);
Tst_AnswerType_t ExaSet_GetAnswerType (long QstCod); Tst_AnswerType_t ExaSet_GetAnswerType (long QstCod);
void ExaSet_GetQstDataFromDB (struct Tst_Question *Question); void ExaSet_GetQstDataFromDB (struct Tst_Question *Question);
void ExaSet_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res,
bool Shuffle);
void ExaSet_AddQstsToSet (void); void ExaSet_AddQstsToSet (void);