mirror of https://github.com/acanas/swad-core.git
Version 21.41.1: Oct 24, 2021 Queries moved to module swad_tag_database.
This commit is contained in:
parent
00302bea7d
commit
4d46a06d38
|
@ -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.41 (2021-10-24)"
|
#define Log_PLATFORM_VERSION "SWAD 21.41.1 (2021-10-24)"
|
||||||
#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.41.1: Oct 24, 2021 Queries moved to module swad_tag_database. (320767 lines)
|
||||||
Version 21.41: Oct 24, 2021 New module swad_tag_database for database queries related to question tags. (320721 lines)
|
Version 21.41: Oct 24, 2021 New module swad_tag_database for database queries related to question tags. (320721 lines)
|
||||||
Version 21.40.1: Oct 24, 2021 Queries moved to module swad_center_database. (320621 lines)
|
Version 21.40.1: Oct 24, 2021 Queries moved to module swad_center_database. (320621 lines)
|
||||||
Version 21.40: Oct 24, 2021 Queries moved to module swad_survey_database. (320673 lines)
|
Version 21.40: Oct 24, 2021 Queries moved to module swad_survey_database. (320673 lines)
|
||||||
|
|
62
swad_tag.c
62
swad_tag.c
|
@ -172,8 +172,8 @@ void Tag_RenameTag (void)
|
||||||
extern const char *Txt_The_tag_X_has_not_changed;
|
extern const char *Txt_The_tag_X_has_not_changed;
|
||||||
char OldTagTxt[Tag_MAX_BYTES_TAG + 1];
|
char OldTagTxt[Tag_MAX_BYTES_TAG + 1];
|
||||||
char NewTagTxt[Tag_MAX_BYTES_TAG + 1];
|
char NewTagTxt[Tag_MAX_BYTES_TAG + 1];
|
||||||
long ExistingTagCod;
|
long ExistingTagCodNewTxt;
|
||||||
long OldTagCod;
|
long TagCodOldTxt;
|
||||||
bool ComplexRenaming;
|
bool ComplexRenaming;
|
||||||
|
|
||||||
/***** Get old and new tags from the form *****/
|
/***** Get old and new tags from the form *****/
|
||||||
|
@ -199,81 +199,43 @@ void Tag_RenameTag (void)
|
||||||
// are not the same (case insensitively)
|
// are not the same (case insensitively)
|
||||||
/* Check if the new tag text is equal to any of the tags
|
/* Check if the new tag text is equal to any of the tags
|
||||||
already present in the database */
|
already present in the database */
|
||||||
if ((ExistingTagCod = Tag_DB_GetTagCodFromTagTxt (NewTagTxt)) > 0)
|
if ((ExistingTagCodNewTxt = Tag_DB_GetTagCodFromTagTxt (NewTagTxt)) > 0)
|
||||||
// The new tag was already in database
|
// The new tag was already in database
|
||||||
ComplexRenaming = true;
|
ComplexRenaming = true;
|
||||||
|
|
||||||
if (ComplexRenaming) // Renaming is not easy
|
if (ComplexRenaming) // Renaming is not easy
|
||||||
{
|
{
|
||||||
/***** Complex update made to not repeat tags:
|
/***** Complex renaming made to not repeat tags:
|
||||||
- If the new tag existed for a question ==>
|
- If the new tag existed for a question ==>
|
||||||
delete old tag from tst_question_tags;
|
delete old tag from tst_question_tags;
|
||||||
the new tag will remain
|
the new tag will remain
|
||||||
- If the new tag did not exist for a question ==>
|
- If the new tag did not exist for a question ==>
|
||||||
change old tag to new tag in tst_question_tags *****/
|
change old tag to new tag in tst_question_tags *****/
|
||||||
/* Get tag code of the old tag */
|
/* Get tag code of the old tag */
|
||||||
if ((OldTagCod = Tag_DB_GetTagCodFromTagTxt (OldTagTxt)) <= 0)
|
if ((TagCodOldTxt = Tag_DB_GetTagCodFromTagTxt (OldTagTxt)) <= 0)
|
||||||
Err_WrongTagExit ();
|
Err_WrongTagExit ();
|
||||||
|
|
||||||
/* Create a temporary table with all the question codes
|
/* Create a temporary table with all the question codes
|
||||||
that had the new tag as one of their tags */
|
that had the new tag as one of their tags */
|
||||||
DB_Query ("can not remove temporary table",
|
Tag_DB_DropTmpTableQuestionsWithTag ();
|
||||||
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
|
Tag_DB_CreateTmpTableQuestionsWithTag (ExistingTagCodNewTxt);
|
||||||
|
|
||||||
DB_Query ("can not create temporary table",
|
|
||||||
"CREATE TEMPORARY TABLE tst_question_tags_tmp"
|
|
||||||
" ENGINE=MEMORY"
|
|
||||||
" SELECT QstCod"
|
|
||||||
" FROM tst_question_tags"
|
|
||||||
" WHERE TagCod=%ld",
|
|
||||||
ExistingTagCod);
|
|
||||||
|
|
||||||
/* Remove old tag in questions where it would be repeated */
|
/* Remove old tag in questions where it would be repeated */
|
||||||
// New tag existed for a question ==> delete old tag
|
|
||||||
DB_QueryDELETE ("can not remove a tag from some questions",
|
|
||||||
"DELETE FROM tst_question_tags"
|
|
||||||
" WHERE TagCod=%ld"
|
|
||||||
" AND QstCod IN"
|
|
||||||
" (SELECT QstCod"
|
|
||||||
" FROM tst_question_tags_tmp)",
|
|
||||||
OldTagCod);
|
|
||||||
|
|
||||||
/* Change old tag to new tag in questions where it would not be repeated */
|
/* Change old tag to new tag in questions where it would not be repeated */
|
||||||
|
// New tag existed for a question ==> delete old tag
|
||||||
// New tag did not exist for a question ==> change old tag to new tag
|
// New tag did not exist for a question ==> change old tag to new tag
|
||||||
DB_QueryUPDATE ("can not update a tag in some questions",
|
Tag_DB_ComplexRenameTag (TagCodOldTxt,ExistingTagCodNewTxt);
|
||||||
"UPDATE tst_question_tags"
|
|
||||||
" SET TagCod=%ld"
|
|
||||||
" WHERE TagCod=%ld"
|
|
||||||
" AND QstCod NOT IN"
|
|
||||||
" (SELECT QstCod"
|
|
||||||
" FROM tst_question_tags_tmp)",
|
|
||||||
ExistingTagCod,
|
|
||||||
OldTagCod);
|
|
||||||
|
|
||||||
/* Drop temporary table, no longer necessary */
|
/* Drop temporary table, no longer necessary */
|
||||||
DB_Query ("can not remove temporary table",
|
Tag_DB_DropTmpTableQuestionsWithTag ();
|
||||||
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
|
|
||||||
|
|
||||||
/***** Delete old tag from tst_tags
|
/***** Delete old tag from tst_tags
|
||||||
because it is not longer used *****/
|
because it is not longer used *****/
|
||||||
DB_QueryDELETE ("can not remove old tag",
|
Tag_DB_RemoveTag (TagCodOldTxt);
|
||||||
"DELETE FROM tst_tags"
|
|
||||||
" WHERE TagCod=%ld",
|
|
||||||
OldTagCod);
|
|
||||||
}
|
}
|
||||||
else // Renaming is easy
|
else // Renaming is easy
|
||||||
{
|
|
||||||
/***** Simple update replacing each instance of the old tag by the new tag *****/
|
/***** Simple update replacing each instance of the old tag by the new tag *****/
|
||||||
DB_QueryUPDATE ("can not update tag",
|
Tag_DB_SimplexRenameTag (OldTagTxt,NewTagTxt);
|
||||||
"UPDATE tst_tags"
|
|
||||||
" SET TagTxt='%s',"
|
|
||||||
"ChangeTime=NOW()"
|
|
||||||
" WHERE tst_tags.CrsCod=%ld"
|
|
||||||
" AND tst_tags.TagTxt='%s'",
|
|
||||||
NewTagTxt,
|
|
||||||
Gbl.Hierarchy.Crs.CrsCod,
|
|
||||||
OldTagTxt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Write message to show the change made *****/
|
/***** Write message to show the change made *****/
|
||||||
Ale_ShowAlert (Ale_SUCCESS,Txt_The_tag_X_has_been_renamed_as_Y,
|
Ale_ShowAlert (Ale_SUCCESS,Txt_The_tag_X_has_been_renamed_as_Y,
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
// #include "swad_error.h"
|
// #include "swad_error.h"
|
||||||
// #include "swad_form.h"
|
// #include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
// #include "swad_tag.h"
|
#include "swad_tag.h"
|
||||||
#include "swad_tag_database.h"
|
#include "swad_tag_database.h"
|
||||||
// #include "swad_theme.h"
|
// #include "swad_theme.h"
|
||||||
|
|
||||||
|
@ -98,6 +98,81 @@ void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd)
|
||||||
TagInd);
|
TagInd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********** Create a temporary table with all the question codes *************/
|
||||||
|
/********** that had the new tag as one of their tags *************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Tag_DB_CreateTmpTableQuestionsWithTag (long TagCod)
|
||||||
|
{
|
||||||
|
DB_Query ("can not create temporary table",
|
||||||
|
"CREATE TEMPORARY TABLE tst_question_tags_tmp"
|
||||||
|
" ENGINE=MEMORY"
|
||||||
|
" SELECT QstCod"
|
||||||
|
" FROM tst_question_tags"
|
||||||
|
" WHERE TagCod=%ld",
|
||||||
|
TagCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* Drop temporary table with all the question codes **************/
|
||||||
|
/************* that had the new tag as one of their tags **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Tag_DB_DropTmpTableQuestionsWithTag (void)
|
||||||
|
{
|
||||||
|
DB_Query ("can not remove temporary table",
|
||||||
|
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************* Complex renaming of tag ***************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Tag_DB_ComplexRenameTag (long TagCodOldTxt,long ExistingTagCodNewTxt)
|
||||||
|
{
|
||||||
|
/***** Remove old tag in questions where it would be repeated *****/
|
||||||
|
// New tag existed for a question ==> delete old tag
|
||||||
|
DB_QueryDELETE ("can not remove a tag from some questions",
|
||||||
|
"DELETE FROM tst_question_tags"
|
||||||
|
" WHERE TagCod=%ld"
|
||||||
|
" AND QstCod IN"
|
||||||
|
// Questions that already have a tag with the new name
|
||||||
|
" (SELECT QstCod"
|
||||||
|
" FROM tst_question_tags_tmp)",
|
||||||
|
TagCodOldTxt);
|
||||||
|
|
||||||
|
/***** Change old tag to new tag in questions where it would not be repeated *****/
|
||||||
|
// New tag did not exist for a question ==> change old tag to new tag
|
||||||
|
DB_QueryUPDATE ("can not update a tag in some questions",
|
||||||
|
"UPDATE tst_question_tags"
|
||||||
|
" SET TagCod=%ld"
|
||||||
|
" WHERE TagCod=%ld"
|
||||||
|
" AND QstCod NOT IN"
|
||||||
|
" (SELECT QstCod"
|
||||||
|
" FROM tst_question_tags_tmp)",
|
||||||
|
ExistingTagCodNewTxt,
|
||||||
|
TagCodOldTxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**** Simple update replacing each instance of the old tag by the new tag ****/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Tag_DB_SimplexRenameTag (const char OldTagTxt[Tag_MAX_BYTES_TAG + 1],
|
||||||
|
const char NewTagTxt[Tag_MAX_BYTES_TAG + 1])
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update tag",
|
||||||
|
"UPDATE tst_tags"
|
||||||
|
" SET TagTxt='%s',"
|
||||||
|
"ChangeTime=NOW()"
|
||||||
|
" WHERE tst_tags.CrsCod=%ld"
|
||||||
|
" AND tst_tags.TagTxt='%s'",
|
||||||
|
NewTagTxt,
|
||||||
|
Gbl.Hierarchy.Crs.CrsCod,
|
||||||
|
OldTagTxt);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/********** Change visibility of an existing tag into tst_tags table *********/
|
/********** Change visibility of an existing tag into tst_tags table *********/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -190,13 +265,24 @@ long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt)
|
||||||
|
|
||||||
void Tag_DB_RemTagsFromQst (long QstCod)
|
void Tag_DB_RemTagsFromQst (long QstCod)
|
||||||
{
|
{
|
||||||
/***** Remove tags *****/
|
|
||||||
DB_QueryDELETE ("can not remove the tags of a question",
|
DB_QueryDELETE ("can not remove the tags of a question",
|
||||||
"DELETE FROM tst_question_tags"
|
"DELETE FROM tst_question_tags"
|
||||||
" WHERE QstCod=%ld",
|
" WHERE QstCod=%ld",
|
||||||
QstCod);
|
QstCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************************** Remove a tag *******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Tag_DB_RemoveTag (long TagCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove tag",
|
||||||
|
"DELETE FROM tst_tags"
|
||||||
|
" WHERE TagCod=%ld",
|
||||||
|
TagCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/********************** Remove unused tags in a course ***********************/
|
/********************** Remove unused tags in a course ***********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -45,7 +45,11 @@
|
||||||
|
|
||||||
long Tag_DB_CreateNewTag (long CrsCod,const char *TagTxt);
|
long Tag_DB_CreateNewTag (long CrsCod,const char *TagTxt);
|
||||||
void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd);
|
void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd);
|
||||||
|
void Tag_DB_CreateTmpTableQuestionsWithTag (long TagCod);
|
||||||
|
void Tag_DB_DropTmpTableQuestionsWithTag (void);
|
||||||
|
void Tag_DB_ComplexRenameTag (long TagCodOldTxt,long ExistingTagCodNewTxt);
|
||||||
|
void Tag_DB_SimplexRenameTag (const char OldTagTxt[Tag_MAX_BYTES_TAG + 1],
|
||||||
|
const char NewTagTxt[Tag_MAX_BYTES_TAG + 1]);
|
||||||
void Tag_DB_EnableOrDisableTag (long TagCod,bool TagHidden);
|
void Tag_DB_EnableOrDisableTag (long TagCod,bool TagHidden);
|
||||||
|
|
||||||
unsigned Tag_DB_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res);
|
unsigned Tag_DB_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res);
|
||||||
|
@ -54,6 +58,7 @@ bool Tag_DB_CheckIfCurrentCrsHasTestTags (void);
|
||||||
long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt);
|
long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt);
|
||||||
|
|
||||||
void Tag_DB_RemTagsFromQst (long QstCod);
|
void Tag_DB_RemTagsFromQst (long QstCod);
|
||||||
|
void Tag_DB_RemoveTag (long TagCod);
|
||||||
void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod);
|
void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue