Version 20.96.6: Sep 09, 2021 Queries moved to module swad_exam_database.

This commit is contained in:
acanas 2021-09-09 15:15:55 +02:00
parent f976c4c944
commit 3a4dd6c7ce
4 changed files with 87 additions and 55 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.
*/
#define Log_PLATFORM_VERSION "SWAD 20.96.5 (2021-09-09)"
#define Log_PLATFORM_VERSION "SWAD 20.96.6 (2021-09-09)"
#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.6: Sep 09, 2021 Queries moved to module swad_exam_database. (314471 lines)
Version 20.96.5: Sep 09, 2021 Queries moved to module swad_exam_database. (314448 lines)
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)

View File

@ -280,6 +280,45 @@ void Exa_DB_UpdateSetIndexesInExamGreaterThan (long ExaCod,long SetInd)
SetInd);
}
/*****************************************************************************/
/********************* Change index of a set in an exam **********************/
/*****************************************************************************/
void Exa_DB_UpdateSetIndex (long SetInd,long SetCod,long ExaCod)
{
DB_QueryUPDATE ("can not exchange indexes of sets",
"UPDATE exa_sets"
" SET SetInd=%ld"
" WHERE SetCod=%ld"
" AND ExaCod=%ld", // Extra check
SetInd,
SetCod,
ExaCod);
}
/*****************************************************************************/
/************ Lock tables to make the exchange of sets atomic ****************/
/*****************************************************************************/
void Exa_DB_LockTables (void)
{
DB_Query ("can not lock tables to exchange sets of questions",
"LOCK TABLES exa_sets WRITE");
Gbl.DB.LockedTables = true;
}
/*****************************************************************************/
/********** Unlock tables to make the exchange of sets atomic ****************/
/*****************************************************************************/
void Exa_DB_UnlockTables (void)
{
Gbl.DB.LockedTables = false; // Set to false before the following unlock...
// ...to not retry the unlock if error in unlocking
DB_Query ("can not unlock tables after exchanging sets of questions",
"UNLOCK TABLES");
}
/*****************************************************************************/
/*********************** Get number of sets in an exam ***********************/
/*****************************************************************************/
@ -529,6 +568,37 @@ long Exa_DB_AddQuestionToSet (long SetCod,const struct Tst_Question *Question,lo
MedCod);
}
/*****************************************************************************/
/*********************** Validate/invalidate a question **********************/
/*****************************************************************************/
void Exa_DB_ChangeValidityQst (long QstCod,long SetCod,long ExaCod,long CrsCod,
Tst_Validity_t Validity)
{
static char CharInvalid[Tst_NUM_VALIDITIES] =
{
[Tst_INVALID_QUESTION] = 'Y',
[Tst_VALID_QUESTION ] = 'N'
};
DB_QueryUPDATE ("can not validate question",
"UPDATE exa_set_questions,"
"exa_sets,"
"exa_exams"
" SET exa_set_questions.Invalid='%c'"
" WHERE exa_set_questions.QstCod=%ld"
" AND exa_set_questions.SetCod=%ld" // Extra check
" AND exa_set_questions.SetCod=exa_sets.SetCod"
" AND exa_sets.ExaCod=%ld" // Extra check
" AND exa_sets.ExaCod=exa_exams.ExaCod"
" AND exa_exams.CrsCod=%ld", // Extra check
CharInvalid[Validity],
QstCod,
SetCod,
ExaCod,
CrsCod);
}
/*****************************************************************************/
/********************* Get number of questions in a set **********************/
/*****************************************************************************/

View File

@ -54,6 +54,9 @@ void Exa_DB_UpdateSetTitle (long SetCod,long ExaCod,
const char NewTitle[ExaSet_MAX_BYTES_TITLE + 1]);
void Exa_DB_UpdateNumQstsToExam (long SetCod,long ExaCod,unsigned NumQstsToPrint);
void Exa_DB_UpdateSetIndexesInExamGreaterThan (long ExaCod,long SetInd);
void Exa_DB_UpdateSetIndex (long SetInd,long SetCod,long ExaCod);
void Exa_DB_LockTables (void);
void Exa_DB_UnlockTables (void);
unsigned Exa_DB_GetNumSetsExam (long ExaCod);
unsigned Exa_DB_GetNumQstsExam (long ExaCod);
unsigned Exa_DB_GetExamSets (MYSQL_RES **mysql_res,long ExaCod);
@ -70,6 +73,8 @@ void Exa_DB_RemoveAllSetsFromExam (long ExaCod);
void Exa_DB_RemoveAllSetsFromCrs (long CrsCod);
long Exa_DB_AddQuestionToSet (long SetCod,const struct Tst_Question *Question,long MedCod);
void Exa_DB_ChangeValidityQst (long QstCod,long SetCod,long ExaCod,long CrsCod,
Tst_Validity_t Validity);
unsigned Exa_DB_GetNumQstsInSet (long SetCod);
unsigned Exa_DB_GetQstsFromSet (MYSQL_RES **mysql_res,long SetCod);
unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res,

View File

@ -1686,7 +1686,7 @@ static void ExaSet_RemoveMediaFromAllAnsOfQst (long QstCod,long SetCod)
}
/*****************************************************************************/
/***************************** Validate a question ***************************/
/*********************** Validate/invalidate a question **********************/
/*****************************************************************************/
void ExaSet_ValidateQst (void)
@ -1705,11 +1705,6 @@ static void ExaSet_ChangeValidityQst (Tst_Validity_t Validity)
struct Exa_Exam Exam;
struct ExaSet_Set Set;
long QstCod;
static char CharInvalid[Tst_NUM_VALIDITIES] =
{
[Tst_INVALID_QUESTION] = 'Y',
[Tst_VALID_QUESTION ] = 'N'
};
/***** Reset exams context *****/
Exa_ResetExams (&Exams);
@ -1722,22 +1717,9 @@ static void ExaSet_ChangeValidityQst (Tst_Validity_t Validity)
/***** Get question index *****/
QstCod = ExaSet_GetParamQstCod ();
/***** Validate question *****/
DB_QueryUPDATE ("can not validate question",
"UPDATE exa_set_questions,"
"exa_sets,exa_exams"
" SET exa_set_questions.Invalid='%c'"
" WHERE exa_set_questions.QstCod=%ld"
" AND exa_set_questions.SetCod=%ld" // Extra check
" AND exa_set_questions.SetCod=exa_sets.SetCod"
" AND exa_sets.ExaCod=%ld" // Extra check
" AND exa_sets.ExaCod=exa_exams.ExaCod"
" AND exa_exams.CrsCod=%ld", // Extra check
CharInvalid[Validity],
QstCod,
Set.SetCod,
Exam.ExaCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Validate/unvalidate question *****/
Exa_DB_ChangeValidityQst (QstCod,Set.SetCod,Exam.ExaCod,Gbl.Hierarchy.Crs.CrsCod,
Validity);
/***** Show current exam and its sets *****/
Exa_PutFormsOneExam (&Exams,&Exam,&Set,
@ -1806,12 +1788,10 @@ static void ExaSet_ExchangeSets (long ExaCod,
long SetCodBottom;
/***** Lock table to make the move atomic *****/
DB_Query ("can not lock tables to exchange sets of questions",
"LOCK TABLES exa_sets WRITE");
Gbl.DB.LockedTables = true;
Exa_DB_LockTables ();
/***** Get set codes of the sets to be moved *****/
SetCodTop = Exa_DB_GetSetCodFromSetInd (ExaCod,SetIndTop);
SetCodTop = Exa_DB_GetSetCodFromSetInd (ExaCod,SetIndTop );
SetCodBottom = Exa_DB_GetSetCodFromSetInd (ExaCod,SetIndBottom);
/***** Exchange indexes of sets *****/
@ -1830,40 +1810,16 @@ static void ExaSet_ExchangeSets (long ExaCod,
*/
/* Step 1: change temporarily top index to minus bottom index
in order to not repeat unique index (ExaCod,SetInd) */
DB_QueryUPDATE ("can not exchange indexes of sets",
"UPDATE exa_sets"
" SET SetInd=-%u"
" WHERE ExaCod=%ld"
" AND SetCod=%ld",
SetIndBottom,
ExaCod,
SetCodTop);
Exa_DB_UpdateSetIndex (-((long) SetIndBottom),SetCodTop ,ExaCod);
/* Step 2: change bottom index to old top index */
DB_QueryUPDATE ("can not exchange indexes of sets",
"UPDATE exa_sets"
" SET SetInd=%u"
" WHERE ExaCod=%ld"
" AND SetCod=%ld",
SetIndTop,
ExaCod,
SetCodBottom);
Exa_DB_UpdateSetIndex ( (long) SetIndTop ,SetCodBottom,ExaCod);
/* Step 3: change top index to old bottom index */
DB_QueryUPDATE ("can not exchange indexes of sets",
"UPDATE exa_sets"
" SET SetInd=%u"
" WHERE ExaCod=%ld"
" AND SetCod=%ld",
SetIndBottom,
ExaCod,
SetCodTop);
Exa_DB_UpdateSetIndex ( (long) SetIndBottom ,SetCodTop ,ExaCod);
/***** Unlock table *****/
Gbl.DB.LockedTables = false; // Set to false before the following unlock...
// ...to not retry the unlock if error in unlocking
DB_Query ("can not unlock tables after exchanging sets of questions",
"UNLOCK TABLES");
Exa_DB_LockTables ();
}
/*****************************************************************************/