Version 21.47.3: Oct 29, 2021 Queries moved to module swad_questions_database.

This commit is contained in:
acanas 2021-10-29 19:48:36 +02:00
parent 0179af96e0
commit 4177e5cb18
7 changed files with 143 additions and 90 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 21.47.2 (2021-10-29)" #define Log_PLATFORM_VERSION "SWAD 21.47.3 (2021-10-29)"
#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 21.47.3: Oct 29, 2021 Queries moved to module swad_questions_database. (321299 lines)
Version 21.47.2: Oct 29, 2021 Queries moved to module swad_questions_database. (321259 lines) Version 21.47.2: Oct 29, 2021 Queries moved to module swad_questions_database. (321259 lines)
Version 21.47.1: Oct 28, 2021 Queries moved to module swad_questions_database. (321231 lines) Version 21.47.1: Oct 28, 2021 Queries moved to module swad_questions_database. (321231 lines)
Version 21.47: Oct 27, 2021 New module swad_questions_database for database queries related to test/exam/game questions. (321236 lines) Version 21.47: Oct 27, 2021 New module swad_questions_database for database queries related to test/exam/game questions. (321236 lines)

View File

@ -2610,7 +2610,7 @@ long Qst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt)
return Qst_DB_GetQstMedCod (CrsCod,QstCod); return Qst_DB_GetQstMedCod (CrsCod,QstCod);
else else
// Get media associated to answer // Get media associated to answer
return Qst_DB_GetAnswerMedCod (QstCod,(unsigned) NumOpt); return Qst_DB_GetMedCodFromAnsOfQst (QstCod,(unsigned) NumOpt);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3698,41 +3698,21 @@ unsigned Qst_CountNumQuestionsInList (const char *ListQuestions)
void Qst_RemoveCrsQsts (long CrsCod) void Qst_RemoveCrsQsts (long CrsCod)
{ {
/***** Remove associations between test questions /***** Remove associations between questions and tags in the course *****/
and test tags in the course *****/ Tag_DB_RemTagsInQstsInCrs (CrsCod);
DB_QueryDELETE ("can not remove tags associated"
" to questions of tests of a course",
"DELETE FROM tst_question_tags"
" USING tst_questions,"
"tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_question_tags.QstCod",
CrsCod);
/***** Remove test tags in the course *****/ /***** Remove test tags in the course *****/
DB_QueryDELETE ("can not remove tags of test of a course", Tag_DB_RemTagsInCrs (CrsCod);
"DELETE FROM tst_tags"
" WHERE CrsCod=%ld",
CrsCod);
/***** Remove media associated to test questions in the course *****/ /***** Remove media associated to test questions in the course *****/
Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (CrsCod); Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (CrsCod);
Qst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (CrsCod); Qst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (CrsCod);
/***** Remove test answers in the course *****/ /***** Remove test answers in the course *****/
DB_QueryDELETE ("can not remove answers of tests of a course", Qst_DB_RemAnssFromQstsInCrs (CrsCod);
"DELETE FROM tst_answers"
" USING tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
/***** Remove test questions in the course *****/ /***** Remove test questions in the course *****/
DB_QueryDELETE ("can not remove test questions of a course", Qst_DB_RemoveQstsInCrs (CrsCod);
"DELETE FROM tst_questions"
" WHERE CrsCod=%ld",
CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3745,14 +3725,7 @@ void Qst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod)
unsigned NumMedia; unsigned NumMedia;
/***** Get media code associated to stem of test question from database *****/ /***** Get media code associated to stem of test question from database *****/
NumMedia = (unsigned) NumMedia = Qst_DB_GetMedCodFromStemOfQst (&mysql_res,CrsCod,QstCod);
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod"
" FROM tst_questions"
" WHERE QstCod=%ld"
" AND CrsCod=%ld", // Extra check
QstCod,
CrsCod);
/***** Go over result removing media *****/ /***** Go over result removing media *****/
Med_RemoveMediaFromAllRows (NumMedia,mysql_res); Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
@ -3771,18 +3744,7 @@ void Qst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod)
unsigned NumMedia; unsigned NumMedia;
/***** Get media codes associated to answers of test questions from database *****/ /***** Get media codes associated to answers of test questions from database *****/
NumMedia = (unsigned) NumMedia = Qst_DB_GetMedCodsFromAnssOfQst (&mysql_res,CrsCod,QstCod);
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_answers,"
"tst_questions"
" WHERE tst_answers.QstCod=%ld"
" AND tst_answers.QstCod=tst_questions.QstCod"
" AND tst_questions.CrsCod=%ld" // Extra check
" AND tst_questions.QstCod=%ld", // Extra check
QstCod,
CrsCod,
QstCod);
/***** Go over result removing media *****/ /***** Go over result removing media *****/
Med_RemoveMediaFromAllRows (NumMedia,mysql_res); Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
@ -3801,12 +3763,7 @@ void Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod)
unsigned NumMedia; unsigned NumMedia;
/***** Get media codes associated to stems of test questions from database *****/ /***** Get media codes associated to stems of test questions from database *****/
NumMedia = NumMedia = Qst_DB_GetMedCodsFromStemsOfQstsInCrs (&mysql_res,CrsCod);
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_questions"
" WHERE CrsCod=%ld",
CrsCod);
/***** Go over result removing media files *****/ /***** Go over result removing media files *****/
Med_RemoveMediaFromAllRows (NumMedia,mysql_res); Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
@ -3825,14 +3782,7 @@ void Qst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod)
unsigned NumMedia; unsigned NumMedia;
/***** Get names of media files associated to answers of test questions from database *****/ /***** Get names of media files associated to answers of test questions from database *****/
NumMedia = (unsigned) NumMedia = Qst_DB_GetMedCodsFromAnssOfQstsInCrs (&mysql_res,CrsCod);
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
/***** Go over result removing media files *****/ /***** Go over result removing media files *****/
Med_RemoveMediaFromAllRows (NumMedia,mysql_res); Med_RemoveMediaFromAllRows (NumMedia,mysql_res);

View File

@ -25,20 +25,12 @@
/*********************************** Headers *********************************/ /*********************************** Headers *********************************/
/*****************************************************************************/ /*****************************************************************************/
// #define _GNU_SOURCE // For asprintf
// #include <stdio.h> // For asprintf
#include <string.h> // For string functions #include <string.h> // For string functions
#include "swad_database.h" #include "swad_database.h"
#include "swad_error.h" #include "swad_error.h"
// #include "swad_exam_set.h"
// #include "swad_figure.h"
// #include "swad_form.h"
#include "swad_global.h" #include "swad_global.h"
#include "swad_question.h" #include "swad_question.h"
// #include "swad_question_import.h"
// #include "swad_tag_database.h"
// #include "swad_test.h"
#include "swad_test_print.h" #include "swad_test_print.h"
/*****************************************************************************/ /*****************************************************************************/
@ -1037,11 +1029,77 @@ unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
"AnsInd"); "AnsInd");
} }
/*****************************************************************************/
/****** Get media codes associated to stems of test questions in course ******/
/*****************************************************************************/
unsigned Qst_DB_GetMedCodsFromStemsOfQstsInCrs (MYSQL_RES **mysql_res,long CrsCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_questions"
" WHERE CrsCod=%ld",
CrsCod);
}
/*****************************************************************************/
/***** Get media codes associated to answers of test questions in course *****/
/*****************************************************************************/
unsigned Qst_DB_GetMedCodsFromAnssOfQstsInCrs (MYSQL_RES **mysql_res,long CrsCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
}
/*****************************************************************************/
/************** Get media code associated to stem of a question **************/
/*****************************************************************************/
unsigned Qst_DB_GetMedCodFromStemOfQst (MYSQL_RES **mysql_res,long CrsCod,long QstCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get media",
"SELECT MedCod"
" FROM tst_questions"
" WHERE QstCod=%ld"
" AND CrsCod=%ld", // Extra check
QstCod,
CrsCod);
}
/*****************************************************************************/
/************** Get media code associated to stem of a question **************/
/*****************************************************************************/
unsigned Qst_DB_GetMedCodsFromAnssOfQst (MYSQL_RES **mysql_res,long CrsCod,long QstCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_answers,"
"tst_questions"
" WHERE tst_answers.QstCod=%ld"
" AND tst_answers.QstCod=tst_questions.QstCod"
" AND tst_questions.CrsCod=%ld" // Extra check
" AND tst_questions.QstCod=%ld", // Extra check
QstCod,
CrsCod,
QstCod);
}
/*****************************************************************************/ /*****************************************************************************/
/********* Get media code associated to an answer of a test question *********/ /********* Get media code associated to an answer of a test question *********/
/*****************************************************************************/ /*****************************************************************************/
long Qst_DB_GetAnswerMedCod (long QstCod,unsigned AnsInd) long Qst_DB_GetMedCodFromAnsOfQst (long QstCod,unsigned AnsInd)
{ {
return DB_QuerySELECTCode ("can not get media", return DB_QuerySELECTCode ("can not get media",
"SELECT MedCod" "SELECT MedCod"
@ -1052,6 +1110,18 @@ long Qst_DB_GetAnswerMedCod (long QstCod,unsigned AnsInd)
AnsInd); AnsInd);
} }
/*****************************************************************************/
/********************* Remove all questions in a course **********************/
/*****************************************************************************/
void Qst_DB_RemoveQstsInCrs (long CrsCod)
{
DB_QueryDELETE ("can not remove questions in a course",
"DELETE FROM tst_questions"
" WHERE CrsCod=%ld",
CrsCod);
}
/*****************************************************************************/ /*****************************************************************************/
/********************** Remove a question from database **********************/ /********************** Remove a question from database **********************/
/*****************************************************************************/ /*****************************************************************************/
@ -1066,13 +1136,27 @@ void Qst_DB_RemoveQst (long CrsCod,long QstCod)
CrsCod); CrsCod);
} }
/*****************************************************************************/
/*************** Remove answers from all questions in a course ****************/
/*****************************************************************************/
void Qst_DB_RemAnssFromQstsInCrs (long CrsCod)
{
DB_QueryDELETE ("can not remove answers of tests of a course",
"DELETE FROM tst_answers"
" USING tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
}
/*****************************************************************************/ /*****************************************************************************/
/******************** Remove answers from a test question ********************/ /******************** Remove answers from a test question ********************/
/*****************************************************************************/ /*****************************************************************************/
void Qst_DB_RemAnsFromQst (long QstCod) void Qst_DB_RemAnsFromQst (long QstCod)
{ {
/***** Remove answers *****/
DB_QueryDELETE ("can not remove the answers of a question", DB_QueryDELETE ("can not remove the answers of a question",
"DELETE FROM tst_answers" "DELETE FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",

View File

@ -27,16 +27,6 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
// #include <stdbool.h> // For boolean type
// #include <time.h> // For time_t
// #include "swad_exam.h"
// #include "swad_game.h"
// #include "swad_question_type.h"
// #include "swad_media.h"
// #include "swad_string.h"
// #include "swad_tag.h"
/*****************************************************************************/ /*****************************************************************************/
/***************************** Public constants ******************************/ /***************************** Public constants ******************************/
/*****************************************************************************/ /*****************************************************************************/
@ -71,9 +61,15 @@ unsigned Qst_DB_GetDataOfAnswers (MYSQL_RES **mysql_res,long QstCod,bool Shuffle
unsigned Qst_DB_GetTextOfAnswers (MYSQL_RES **mysql_res,long QstCod); unsigned Qst_DB_GetTextOfAnswers (MYSQL_RES **mysql_res,long QstCod);
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res, unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
const struct Qst_Question *Question); const struct Qst_Question *Question);
long Qst_DB_GetAnswerMedCod (long QstCod,unsigned AnsInd); unsigned Qst_DB_GetMedCodsFromStemsOfQstsInCrs (MYSQL_RES **mysql_res,long CrsCod);
unsigned Qst_DB_GetMedCodsFromAnssOfQstsInCrs (MYSQL_RES **mysql_res,long CrsCod);
unsigned Qst_DB_GetMedCodFromStemOfQst (MYSQL_RES **mysql_res,long CrsCod,long QstCod);
unsigned Qst_DB_GetMedCodsFromAnssOfQst (MYSQL_RES **mysql_res,long CrsCod,long QstCod);
long Qst_DB_GetMedCodFromAnsOfQst (long QstCod,unsigned AnsInd);
void Qst_DB_RemoveQstsInCrs (long CrsCod);
void Qst_DB_RemoveQst (long CrsCod,long QstCod); void Qst_DB_RemoveQst (long CrsCod,long QstCod);
void Qst_DB_RemAnssFromQstsInCrs (long CrsCod);
void Qst_DB_RemAnsFromQst (long QstCod); void Qst_DB_RemAnsFromQst (long QstCod);
#endif #endif

View File

@ -269,6 +269,34 @@ long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt)
TagTxt); TagTxt);
} }
/*****************************************************************************/
/******** Remove associations between questions and tags in a course *********/
/*****************************************************************************/
void Tag_DB_RemTagsInQstsInCrs (long CrsCod)
{
DB_QueryDELETE ("can not remove tags associated"
" to questions in a course",
"DELETE FROM tst_question_tags"
" USING tst_questions,"
"tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_question_tags.QstCod",
CrsCod);
}
/*****************************************************************************/
/**************************** Remove tags in a course ************************/
/*****************************************************************************/
void Tag_DB_RemTagsInCrs (long CrsCod)
{
DB_QueryDELETE ("can not remove tags of questions in a course",
"DELETE FROM tst_tags"
" WHERE CrsCod=%ld",
CrsCod);
}
/*****************************************************************************/ /*****************************************************************************/
/************************** Remove tags from a question **********************/ /************************** Remove tags from a question **********************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -59,6 +59,8 @@ unsigned Tag_DB_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res);
bool Tag_DB_CheckIfCurrentCrsHasTestTags (void); bool Tag_DB_CheckIfCurrentCrsHasTestTags (void);
long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt); long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt);
void Tag_DB_RemTagsInQstsInCrs (long CrsCod);
void Tag_DB_RemTagsInCrs (long CrsCod);
void Tag_DB_RemTagsFromQst (long QstCod); void Tag_DB_RemTagsFromQst (long QstCod);
void Tag_DB_RemoveTag (long TagCod); void Tag_DB_RemoveTag (long TagCod);
void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod); void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod);

View File

@ -29,14 +29,6 @@
#include <mysql/mysql.h> // To access MySQL databases #include <mysql/mysql.h> // To access MySQL databases
// #include "swad_exam.h"
// #include "swad_game.h"
// #include "swad_media.h"
// #include "swad_question.h"
// #include "swad_question_type.h"
// #include "swad_test_config.h"
// #include "swad_test_print.h"
/*****************************************************************************/ /*****************************************************************************/
/***************************** Public constants ******************************/ /***************************** Public constants ******************************/
/*****************************************************************************/ /*****************************************************************************/