From b1854d0dea54b171dd161aff00256fa739d29815 Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 25 Oct 2021 10:24:43 +0200 Subject: [PATCH] Version 21.43: Oct 25, 2021 New module swad_question for test/exam/game questions. --- Makefile | 2 +- swad_changelog.h | 3 +- swad_database.c | 8 +-- swad_exam_print.c | 2 +- swad_exam_set.c | 4 +- swad_exam_set.h | 1 + swad_question.c | 125 +++++++++++++++++++++++++++++++++++++++++ swad_question.h | 120 +++++++++++++++++++++++++++++++++++++++ swad_question_import.c | 14 ++--- swad_question_type.h | 59 ------------------- swad_test.c | 48 +++------------- swad_test.h | 9 +-- swad_test_print.c | 3 +- swad_test_print.h | 1 + 14 files changed, 274 insertions(+), 125 deletions(-) create mode 100644 swad_question.c create mode 100644 swad_question.h diff --git a/Makefile b/Makefile index 75e83c45..b2dbd6aa 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_place.o swad_place_database.o swad_plugin.o swad_plugin_database.o \ swad_privacy.o swad_profile.o swad_profile_database.o swad_program.o \ swad_program_database.o swad_project.o swad_project_database.o \ - swad_question_import.o swad_QR.o \ + swad_question.o swad_question_import.o swad_QR.o \ swad_record.o swad_record_database.o swad_report.o \ swad_report_database.o swad_role.o swad_role_database.o swad_room.o \ swad_room_database.o swad_RSS.o \ diff --git a/swad_changelog.h b/swad_changelog.h index ce945ed1..d29b713b 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 21.42.2 (2021-10-25)" +#define Log_PLATFORM_VERSION "SWAD 21.43 (2021-10-25)" #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 21.43: Oct 25, 2021 New module swad_question for test/exam/game questions. (320919 lines) Version 21.42.2: Oct 25, 2021 Code refactoring in test questions. (320795 lines) Version 21.42.1: Oct 25, 2021 Code refactoring in test questions. (320784 lines) Version 21.42: Oct 24, 2021 Code refactoring in test questions. (320782 lines) diff --git a/swad_database.c b/swad_database.c index 5cac5ee7..16a0f22a 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1307,8 +1307,8 @@ mysql> DESCRIBE exa_set_answers; DB_CreateTable ("CREATE TABLE IF NOT EXISTS exa_set_answers (" "QstCod INT NOT NULL," "AnsInd TINYINT NOT NULL," - "Answer TEXT NOT NULL," // Tst_MAX_BYTES_ANSWER_OR_FEEDBACK - "Feedback TEXT NOT NULL," // Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + "Answer TEXT NOT NULL," // Qst_MAX_BYTES_ANSWER_OR_FEEDBACK + "Feedback TEXT NOT NULL," // Qst_MAX_BYTES_ANSWER_OR_FEEDBACK "MedCod INT NOT NULL DEFAULT -1," "Correct ENUM('N','Y') NOT NULL," "UNIQUE INDEX(QstCod,AnsInd)," @@ -3101,8 +3101,8 @@ mysql> DESCRIBE tst_answers; DB_CreateTable ("CREATE TABLE IF NOT EXISTS tst_answers (" "QstCod INT NOT NULL," "AnsInd TINYINT NOT NULL," - "Answer TEXT NOT NULL," // Tst_MAX_BYTES_ANSWER_OR_FEEDBACK - "Feedback TEXT NOT NULL," // Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + "Answer TEXT NOT NULL," // Qst_MAX_BYTES_ANSWER_OR_FEEDBACK + "Feedback TEXT NOT NULL," // Qst_MAX_BYTES_ANSWER_OR_FEEDBACK "MedCod INT NOT NULL DEFAULT -1," "Correct ENUM('N','Y') NOT NULL," "INDEX(QstCod)," diff --git a/swad_exam_print.c b/swad_exam_print.c index faf075ce..5df6f823 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -1312,7 +1312,7 @@ static void ExaPrn_GetCorrectTxtAnswerFromDB (struct Qst_Question *Question) /***** Copy answer text (row[0]) ******/ Str_Copy (Question->Answer.Options[NumOpt].Text,row[0], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); } /***** Change format of answers text *****/ diff --git a/swad_exam_set.c b/swad_exam_set.c index 9e344586..3095ce89 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -1151,14 +1151,14 @@ void ExaSet_GetQstDataFromDB (struct Qst_Question *Question) if (row[1]) if (row[1][0]) Str_Copy (Question->Answer.Options[NumOpt].Text ,row[1], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Get feedback (row[2]) */ Question->Answer.Options[NumOpt].Feedback[0] = '\0'; if (row[2]) if (row[2][0]) Str_Copy (Question->Answer.Options[NumOpt].Feedback,row[2], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Get media (row[3]) */ Question->Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]); diff --git a/swad_exam_set.h b/swad_exam_set.h index 0897a03f..c2dd3680 100644 --- a/swad_exam_set.h +++ b/swad_exam_set.h @@ -29,6 +29,7 @@ /*****************************************************************************/ #include "swad_exam_type.h" +#include "swad_question.h" #include "swad_question_type.h" /*****************************************************************************/ diff --git a/swad_question.c b/swad_question.c new file mode 100644 index 00000000..9ea02d5f --- /dev/null +++ b/swad_question.c @@ -0,0 +1,125 @@ +// swad_question.c: test/exam/game questions + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +// #define _GNU_SOURCE // For asprintf +// #include // For UINT_MAX +// #include // For PATH_MAX +// #include // To access MySQL databases +// #include // For boolean type +// #include // For NULL +// #include // For asprintf +// #include // For exit, system, malloc, free, etc +// #include // For string functions +// #include // For mkdir +// #include // For mkdir + +// #include "swad_action.h" +// #include "swad_box.h" +// #include "swad_database.h" +// #include "swad_error.h" +// #include "swad_exam_set.h" +// #include "swad_figure.h" +// #include "swad_form.h" +// #include "swad_global.h" +// #include "swad_hierarchy_level.h" +// #include "swad_HTML.h" +// #include "swad_ID.h" +// #include "swad_language.h" +// #include "swad_match.h" +// #include "swad_media.h" +// #include "swad_parameter.h" +#include "swad_question.h" +// #include "swad_question_import.h" +// #include "swad_tag_database.h" +// #include "swad_test.h" +// #include "swad_test_config.h" +// #include "swad_test_print.h" +// #include "swad_test_visibility.h" +// #include "swad_theme.h" +// #include "swad_user.h" +// #include "swad_xml.h" + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/**************************** Private constants ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************** Change format of answers text / feedback ******************/ +/*****************************************************************************/ + +void Qst_ChangeFormatAnswersText (struct Qst_Question *Question) + { + unsigned NumOpt; + + /***** Change format of answers text *****/ + for (NumOpt = 0; + NumOpt < Question->Answer.NumOptions; + NumOpt++) + /* Convert answer text, that is in HTML, to rigorous HTML */ + if (Question->Answer.Options[NumOpt].Text[0]) + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + Question->Answer.Options[NumOpt].Text, + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + } + +void Qst_ChangeFormatAnswersFeedback (struct Qst_Question *Question) + { + unsigned NumOpt; + + /***** Change format of answers text and feedback *****/ + for (NumOpt = 0; + NumOpt < Question->Answer.NumOptions; + NumOpt++) + /* Convert answer feedback, that is in HTML, to rigorous HTML */ + if (Question->Answer.Options[NumOpt].Feedback) + if (Question->Answer.Options[NumOpt].Feedback[0]) + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + Question->Answer.Options[NumOpt].Feedback, + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + } diff --git a/swad_question.h b/swad_question.h new file mode 100644 index 00000000..96f73757 --- /dev/null +++ b/swad_question.h @@ -0,0 +1,120 @@ +// swad_question.h: test/exam/game questions + +#ifndef _SWAD_QST +#define _SWAD_QST +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include // For boolean type +#include // For time_t + +// #include "swad_question_type.h" +#include "swad_media.h" +#include "swad_string.h" +#include "swad_tag.h" +// #include "swad_test_config.h" +// #include "swad_test_visibility.h" +// #include "swad_user.h" + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +#define Qst_MAX_BYTES_ANSWER_TYPE 32 + +#define Qst_MAX_BYTES_FLOAT_ANSWER 30 // Maximum length of the strings that store an floating point answer + +#define Qst_MAX_OPTIONS_PER_QUESTION 10 + +#define Qst_MAX_BYTES_INDEXES_ONE_QST (Qst_MAX_OPTIONS_PER_QUESTION * (3 + 1)) + +#define Qst_MAX_CHARS_ANSWER_OR_FEEDBACK (1024 - 1) // 1023 +#define Qst_MAX_BYTES_ANSWER_OR_FEEDBACK ((Qst_MAX_CHARS_ANSWER_OR_FEEDBACK + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 16383 + +#define Qst_MAX_CHARS_ANSWERS_ONE_QST (128 - 1) // 127 +#define Qst_MAX_BYTES_ANSWERS_ONE_QST ((Qst_MAX_CHARS_ANSWERS_ONE_QST + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 + +/*****************************************************************************/ +/******************************* Public types ********************************/ +/*****************************************************************************/ + +#define Qst_NUM_VALIDITIES 2 +typedef enum + { + Qst_INVALID_QUESTION, + Qst_VALID_QUESTION, + } Qst_Validity_t; + +#define Qst_NUM_ANS_TYPES 6 +#define Qst_MAX_BYTES_LIST_ANSWER_TYPES (Qst_NUM_ANS_TYPES * (Cns_MAX_DECIMAL_DIGITS_UINT + 1)) +typedef enum + { + Qst_ANS_INT = 0, + Qst_ANS_FLOAT = 1, + Qst_ANS_TRUE_FALSE = 2, + Qst_ANS_UNIQUE_CHOICE = 3, + Qst_ANS_MULTIPLE_CHOICE = 4, + Qst_ANS_TEXT = 5, + Qst_ANS_UNKNOWN = 6, // Unknown/all/any type of answer + } Qst_AnswerType_t; + +struct Qst_Question + { + long QstCod; + struct Tag_Tags Tags; + time_t EditTime; + char *Stem; + char *Feedback; + struct Med_Media Media; + struct + { + Qst_AnswerType_t Type; + unsigned NumOptions; + bool Shuffle; + char TF; + struct + { + bool Correct; + char *Text; + char *Feedback; + struct Med_Media Media; + } Options[Qst_MAX_OPTIONS_PER_QUESTION]; + long Integer; + double FloatingPoint[2]; + } Answer; + unsigned long NumHits; + unsigned long NumHitsNotBlank; + double Score; + Qst_Validity_t Validity; // If a question in an exam has been marked as invalid + }; + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +void Qst_ChangeFormatAnswersText (struct Qst_Question *Question); +void Qst_ChangeFormatAnswersFeedback (struct Qst_Question *Question); + +#endif diff --git a/swad_question_import.c b/swad_question_import.c index 154a32ee..1dd3723a 100644 --- a/swad_question_import.c +++ b/swad_question_import.c @@ -719,7 +719,7 @@ static void QstImp_GetAnswerFromXML (struct XMLElement *AnswerElem, if (AnswerElem->Content) Str_Copy (Question->Answer.Options[0].Text,AnswerElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; case Qst_ANS_FLOAT: if (!Qst_AllocateTextChoiceAnswer (Question,0)) @@ -737,7 +737,7 @@ static void QstImp_GetAnswerFromXML (struct XMLElement *AnswerElem, if (LowerUpperElem->Content) Str_Copy (Question->Answer.Options[0].Text, LowerUpperElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; // Only first element "lower" } for (LowerUpperElem = AnswerElem->FirstChild; @@ -748,7 +748,7 @@ static void QstImp_GetAnswerFromXML (struct XMLElement *AnswerElem, if (LowerUpperElem->Content) Str_Copy (Question->Answer.Options[1].Text, LowerUpperElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; // Only first element "upper" } break; @@ -791,12 +791,12 @@ static void QstImp_GetAnswerFromXML (struct XMLElement *AnswerElem, { Str_Copy (Question->Answer.Options[NumOpt].Text, TextElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Convert answer from text to HTML (in database answer text is stored in HTML) */ Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Question->Answer.Options[NumOpt].Text, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,true); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK,true); } break; // Only first element "text" } @@ -810,12 +810,12 @@ static void QstImp_GetAnswerFromXML (struct XMLElement *AnswerElem, { Str_Copy (Question->Answer.Options[NumOpt].Feedback, FeedbackElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Convert feedback from text to HTML (in database answer feedback is stored in HTML) */ Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Question->Answer.Options[NumOpt].Feedback, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,true); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK,true); } break; // Only first element "feedback" } diff --git a/swad_question_type.h b/swad_question_type.h index e1b7d0c8..94cd29c3 100644 --- a/swad_question_type.h +++ b/swad_question_type.h @@ -34,69 +34,10 @@ /***************************** Public constants ******************************/ /*****************************************************************************/ -#define Qst_MAX_BYTES_FLOAT_ANSWER 30 // Maximum length of the strings that store an floating point answer - -#define Qst_MAX_OPTIONS_PER_QUESTION 10 - -#define Qst_MAX_BYTES_INDEXES_ONE_QST (Qst_MAX_OPTIONS_PER_QUESTION * (3 + 1)) - -#define Qst_MAX_CHARS_ANSWERS_ONE_QST (128 - 1) // 127 -#define Qst_MAX_BYTES_ANSWERS_ONE_QST ((Qst_MAX_CHARS_ANSWERS_ONE_QST + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 - /*****************************************************************************/ /******************************* Public types ********************************/ /*****************************************************************************/ -#define Qst_NUM_VALIDITIES 2 -typedef enum - { - Qst_INVALID_QUESTION, - Qst_VALID_QUESTION, - } Qst_Validity_t; - -#define Qst_NUM_ANS_TYPES 6 -#define Qst_MAX_BYTES_LIST_ANSWER_TYPES (Qst_NUM_ANS_TYPES * (Cns_MAX_DECIMAL_DIGITS_UINT + 1)) -typedef enum - { - Qst_ANS_INT = 0, - Qst_ANS_FLOAT = 1, - Qst_ANS_TRUE_FALSE = 2, - Qst_ANS_UNIQUE_CHOICE = 3, - Qst_ANS_MULTIPLE_CHOICE = 4, - Qst_ANS_TEXT = 5, - Qst_ANS_UNKNOWN = 6, // Unknown/all/any type of answer - } Qst_AnswerType_t; - -struct Qst_Question - { - long QstCod; - struct Tag_Tags Tags; - time_t EditTime; - char *Stem; - char *Feedback; - struct Med_Media Media; - struct - { - Qst_AnswerType_t Type; - unsigned NumOptions; - bool Shuffle; - char TF; - struct - { - bool Correct; - char *Text; - char *Feedback; - struct Med_Media Media; - } Options[Qst_MAX_OPTIONS_PER_QUESTION]; - long Integer; - double FloatingPoint[2]; - } Answer; - unsigned long NumHits; - unsigned long NumHitsNotBlank; - double Score; - Qst_Validity_t Validity; // If a question in an exam has been marked as invalid - }; - /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ diff --git a/swad_test.c b/swad_test.c index e417de19..c5be4817 100644 --- a/swad_test.c +++ b/swad_test.c @@ -52,6 +52,7 @@ #include "swad_match.h" #include "swad_media.h" #include "swad_parameter.h" +#include "swad_question.h" #include "swad_question_import.h" #include "swad_tag_database.h" #include "swad_test.h" @@ -2685,41 +2686,6 @@ void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res, Err_WrongAnswerExit (); } -/*****************************************************************************/ -/***************** Change format of answers text / feedback ******************/ -/*****************************************************************************/ - -void Qst_ChangeFormatAnswersText (struct Qst_Question *Question) - { - unsigned NumOpt; - - /***** Change format of answers text *****/ - for (NumOpt = 0; - NumOpt < Question->Answer.NumOptions; - NumOpt++) - /* Convert answer text, that is in HTML, to rigorous HTML */ - if (Question->Answer.Options[NumOpt].Text[0]) - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Question->Answer.Options[NumOpt].Text, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); - } - -void Qst_ChangeFormatAnswersFeedback (struct Qst_Question *Question) - { - unsigned NumOpt; - - /***** Change format of answers text and feedback *****/ - for (NumOpt = 0; - NumOpt < Question->Answer.NumOptions; - NumOpt++) - /* Convert answer feedback, that is in HTML, to rigorous HTML */ - if (Question->Answer.Options[NumOpt].Feedback) - if (Question->Answer.Options[NumOpt].Feedback[0]) - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Question->Answer.Options[NumOpt].Feedback, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); - } - /*****************************************************************************/ /**************** Get and write the answers of a test question ***************/ /*****************************************************************************/ @@ -3654,14 +3620,14 @@ void Qst_QstDestructor (struct Qst_Question *Question) bool Qst_AllocateTextChoiceAnswer (struct Qst_Question *Question,unsigned NumOpt) { if ((Question->Answer.Options[NumOpt].Text = - malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL) + malloc (Qst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL) { Ale_CreateAlert (Ale_ERROR,NULL, "Not enough memory to store answer."); return false; } if ((Question->Answer.Options[NumOpt].Feedback = - malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL) + malloc (Qst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL) { Ale_CreateAlert (Ale_ERROR,NULL, "Not enough memory to store feedback."); @@ -3895,12 +3861,12 @@ bool Qst_GetQstDataFromDB (struct Qst_Question *Question) if (row[1]) if (row[1][0]) Str_Copy (Question->Answer.Options[NumOpt].Text ,row[1], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); Question->Answer.Options[NumOpt].Feedback[0] = '\0'; if (row[2]) if (row[2][0]) Str_Copy (Question->Answer.Options[NumOpt].Feedback,row[2], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Get media (row[3]) */ Question->Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]); @@ -4162,7 +4128,7 @@ static void Qst_GetQstFromForm (struct Qst_Question *Question) /* Get answer */ snprintf (AnsStr,sizeof (AnsStr),"AnsStr%u",NumOpt); Par_GetParToHTML (AnsStr,Question->Answer.Options[NumOpt].Text, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); if (Question->Answer.Type == Qst_ANS_TEXT) /* In order to compare student answer to stored answer, the text answers are stored avoiding two or more consecurive spaces */ @@ -4171,7 +4137,7 @@ static void Qst_GetQstFromForm (struct Qst_Question *Question) /* Get feedback */ snprintf (FbStr,sizeof (FbStr),"FbStr%u",NumOpt); Par_GetParToHTML (FbStr,Question->Answer.Options[NumOpt].Feedback, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Get media associated to the answer (action, file and title) */ if (Question->Answer.Type == Qst_ANS_UNIQUE_CHOICE || diff --git a/swad_test.h b/swad_test.h index cf49d713..ac2e8980 100644 --- a/swad_test.h +++ b/swad_test.h @@ -30,6 +30,7 @@ #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" @@ -38,11 +39,6 @@ /***************************** Public constants ******************************/ /*****************************************************************************/ -#define Tst_MAX_CHARS_ANSWER_OR_FEEDBACK (1024 - 1) // 1023 -#define Tst_MAX_BYTES_ANSWER_OR_FEEDBACK ((Tst_MAX_CHARS_ANSWER_OR_FEEDBACK + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 16383 - -#define Qst_MAX_BYTES_ANSWER_TYPE 32 - #define Tst_SCORE_MAX 10 // Maximum score of a test (10 in Spain). Must be unsigned! // TODO: Make this configurable by teachers /*****************************************************************************/ @@ -128,9 +124,6 @@ unsigned Qst_GetNumAnswersQst (long QstCod); void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res, bool Shuffle); -void Qst_ChangeFormatAnswersText (struct Qst_Question *Question); -void Qst_ChangeFormatAnswersFeedback (struct Qst_Question *Question); - void Qst_WriteAnswersBank (struct Qst_Question *Question, const char *ClassTxt, const char *ClassFeedback); diff --git a/swad_test_print.c b/swad_test_print.c index 3fe3329d..2de06e9d 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -40,6 +40,7 @@ #include "swad_HTML.h" #include "swad_ID.h" #include "swad_photo.h" +#include "swad_question.h" #include "swad_test.h" #include "swad_test_print.h" #include "swad_test_visibility.h" @@ -1021,7 +1022,7 @@ static void TstPrn_GetCorrectTxtAnswerFromDB (struct Qst_Question *Question) /***** Copy answer text (row[0]) ******/ Str_Copy (Question->Answer.Options[NumOpt].Text,row[0], - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Qst_MAX_BYTES_ANSWER_OR_FEEDBACK); } /***** Change format of answers text *****/ diff --git a/swad_test_print.h b/swad_test_print.h index c466c859..060e0435 100644 --- a/swad_test_print.h +++ b/swad_test_print.h @@ -27,6 +27,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ +#include "swad_question.h" #include "swad_question_type.h" #include "swad_test_config.h" #include "swad_test_visibility.h"