From 64a4aa6ce973356afc2a6b83312c1e339b505e15 Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 20 Mar 2021 15:06:07 +0100 Subject: [PATCH] Version 20.51.30: Mar 20, 2021 Survey groups database table renamed. --- sql/swad.sql | 4 +-- swad_changelog.h | 6 +++- swad_database.c | 6 ++-- swad_group.c | 2 +- swad_notification.c | 40 ++++++++++++++----------- swad_survey.c | 72 +++++++++++++++++++++++++++------------------ 6 files changed, 78 insertions(+), 52 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index 8483cd78a..0373c0a11 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -1332,9 +1332,9 @@ CREATE TABLE IF NOT EXISTS svy_answers ( Answer TEXT NOT NULL, UNIQUE INDEX(QstCod,AnsInd)); -- --- Table svy_grp: stores the groups associated to each survey +-- Table svy_groups: stores the groups associated to each survey -- -CREATE TABLE IF NOT EXISTS svy_grp ( +CREATE TABLE IF NOT EXISTS svy_groups ( SvyCod INT NOT NULL, GrpCod INT NOT NULL, UNIQUE INDEX(SvyCod,GrpCod)); diff --git a/swad_changelog.h b/swad_changelog.h index d6c1799c3..2643c2b2b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -600,13 +600,17 @@ TODO: Salvador Romero Cort TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. */ -#define Log_PLATFORM_VERSION "SWAD 20.51.29 (2021-03-20)" +#define Log_PLATFORM_VERSION "SWAD 20.51.30 (2021-03-20)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.6.2.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.51.30: Mar 20, 2021 Survey groups database table renamed. (308287 lines) + 1 change necessary in database: +RENAME TABLE svy_grp TO svy_groups; + Version 20.51.29: Mar 20, 2021 Attendance groups database table renamed. (308259 lines) 1 change necessary in database: RENAME TABLE att_grp TO att_groups; diff --git a/swad_database.c b/swad_database.c index 080e82a13..96f6f7d78 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2779,9 +2779,9 @@ mysql> DESCRIBE svy_answers; "Answer TEXT NOT NULL," // Cns_MAX_BYTES_TEXT "UNIQUE INDEX(QstCod,AnsInd))"); - /***** Table svy_grp *****/ + /***** Table svy_groups *****/ /* -mysql> DESCRIBE svy_grp; +mysql> DESCRIBE svy_groups; +--------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+-------+ @@ -2790,7 +2790,7 @@ mysql> DESCRIBE svy_grp; +--------+---------+------+-----+---------+-------+ 2 rows in set (0.01 sec) */ - DB_CreateTable ("CREATE TABLE IF NOT EXISTS svy_grp (" + DB_CreateTable ("CREATE TABLE IF NOT EXISTS svy_groups (" "SvyCod INT NOT NULL," "GrpCod INT NOT NULL," "UNIQUE INDEX(SvyCod,GrpCod))"); diff --git a/swad_group.c b/swad_group.c index e1d49d71b..b51a62a87 100644 --- a/swad_group.c +++ b/swad_group.c @@ -1694,7 +1694,7 @@ void Grp_ListGrpsToEditAsgAttSvyEvtMch (struct GroupType *GrpTyp, { [Grp_ASSIGNMENT] = {"asg_groups","AsgCod"}, [Grp_ATT_EVENT ] = {"att_groups","AttCod"}, - [Grp_SURVEY ] = {"svy_grp" ,"SvyCod"}, + [Grp_SURVEY ] = {"svy_groups","SvyCod"}, [Grp_EXA_EVENT ] = {"exa_groups","SesCod"}, [Grp_MATCH ] = {"mch_groups","MchCod"}, }; diff --git a/swad_notification.c b/swad_notification.c index fe1744556..b71b9e15b 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -1402,25 +1402,31 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) NumRows = DB_QuerySELECT (&mysql_res,"can not get users" " to be notified", "(SELECT crs_usr.UsrCod" - " FROM svy_surveys,crs_usr" - " WHERE svy_surveys.SvyCod=%ld" - " AND svy_surveys.SvyCod NOT IN" - " (SELECT SvyCod FROM svy_grp WHERE SvyCod=%ld)" - " AND svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=crs_usr.CrsCod" - " AND crs_usr.UsrCod<>%ld" - " AND (svy_surveys.Roles&(1<0)" + " FROM svy_surveys," + "crs_usr" + " WHERE svy_surveys.SvyCod=%ld" + " AND svy_surveys.SvyCod NOT IN" + " (SELECT SvyCod" + " FROM svy_groups" + " WHERE SvyCod=%ld)" + " AND svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=crs_usr.CrsCod" + " AND crs_usr.UsrCod<>%ld" + " AND (svy_surveys.Roles&(1<0)" " UNION " "(SELECT DISTINCT crs_grp_usr.UsrCod" - " FROM svy_grp,crs_grp_usr,svy_surveys,crs_usr" - " WHERE svy_grp.SvyCod=%ld" - " AND svy_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_grp_usr.UsrCod<>%ld" - " AND svy_grp.SvyCod=svy_surveys.SvyCod" - " AND svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=crs_usr.CrsCod" - " AND (svy_surveys.Roles&(1<0)", + " FROM svy_groups," + "crs_grp_usr," + "svy_surveys," + "crs_usr" + " WHERE svy_groups.SvyCod=%ld" + " AND svy_groups.GrpCod=crs_grp_usr.GrpCod" + " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" + " AND crs_grp_usr.UsrCod<>%ld" + " AND svy_groups.SvyCod=svy_surveys.SvyCod" + " AND svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=crs_usr.CrsCod" + " AND (svy_surveys.Roles&(1<0)", Cod, Cod, Sco_GetDBStrFromScope (Hie_Lvl_CRS), diff --git a/swad_survey.c b/swad_survey.c index c3fb382bc..a09c31a89 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -988,16 +988,18 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys) if (Gbl.Crs.Grps.WhichGrps == Grp_MY_GROUPS) { if (asprintf (&SubQuery[Hie_Lvl_CRS],"%s(" - "Scope='%s' AND Cod=%ld%s" + "Scope='%s'" + " AND Cod=%ld%s" " AND " "(SvyCod NOT IN" - " (SELECT SvyCod FROM svy_grp)" + " (SELECT SvyCod" + " FROM svy_groups)" " OR" " SvyCod IN" - " (SELECT svy_grp.SvyCod" - " FROM svy_grp,crs_grp_usr" - " WHERE crs_grp_usr.UsrCod=%ld" - " AND svy_grp.GrpCod=crs_grp_usr.GrpCod))" + " (SELECT svy_groups.SvyCod" + " FROM svy_groups,crs_grp_usr" + " WHERE crs_grp_usr.UsrCod=%ld" + " AND svy_groups.GrpCod=crs_grp_usr.GrpCod))" ")", SubQueryFilled ? " OR " : "", @@ -2151,8 +2153,8 @@ static void Svy_ShowLstGrpsToEditSurvey (long SvyCod) HTM_LABEL_Begin (NULL); HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"WholeCrs\" value=\"Y\"%s onclick=\"uncheckChildren(this,'GrpCods')\"", - Grp_CheckIfAssociatedToGrps ("svy_grp","SvyCod",SvyCod) ? "" : - " checked=\"checked\""); + Grp_CheckIfAssociatedToGrps ("svy_groups","SvyCod",SvyCod) ? "" : + " checked=\"checked\""); HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -2420,7 +2422,8 @@ static void Svy_RemoveAllTheGrpsAssociatedToAndSurvey (long SvyCod) { /***** Remove groups of the survey *****/ DB_QueryDELETE ("can not remove the groups associated to a survey", - "DELETE FROM svy_grp WHERE SvyCod=%ld", + "DELETE FROM svy_groups" + " WHERE SvyCod=%ld", SvyCod); } @@ -2433,7 +2436,8 @@ void Svy_RemoveGroup (long GrpCod) /***** Remove group from all the surveys *****/ DB_QueryDELETE ("can not remove group from the associations" " between surveys and groups", - "DELETE FROM svy_grp WHERE GrpCod=%ld", + "DELETE FROM svy_groups" + " WHERE GrpCod=%ld", GrpCod); } @@ -2446,9 +2450,11 @@ void Svy_RemoveGroupsOfType (long GrpTypCod) /***** Remove group from all the surveys *****/ DB_QueryDELETE ("can not remove groups of a type" " from the associations between surveys and groups", - "DELETE FROM svy_grp USING crs_grp,svy_grp" + "DELETE FROM svy_groups" + " USING crs_grp," + "svy_groups" " WHERE crs_grp.GrpTypCod=%ld" - " AND crs_grp.GrpCod=svy_grp.GrpCod", + " AND crs_grp.GrpCod=svy_groups.GrpCod", GrpTypCod); } @@ -2466,7 +2472,7 @@ static void Svy_CreateGrps (long SvyCod) NumGrpSel++) /* Create group */ DB_QueryINSERT ("can not associate a group to a survey", - "INSERT INTO svy_grp" + "INSERT INTO svy_groups" " (SvyCod,GrpCod)" " VALUES" " (%ld,%ld)", @@ -2490,13 +2496,14 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy) /***** Get groups associated to a survey from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey", - "SELECT crs_grp_types.GrpTypName,crs_grp.GrpName" - " FROM svy_grp,crs_grp,crs_grp_types" - " WHERE svy_grp.SvyCod=%ld" - " AND svy_grp.GrpCod=crs_grp.GrpCod" - " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" + "SELECT crs_grp_types.GrpTypName," + "crs_grp.GrpName" + " FROM svy_groups,crs_grp,crs_grp_types" + " WHERE svy_groups.SvyCod=%ld" + " AND svy_groups.GrpCod=crs_grp.GrpCod" + " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " ORDER BY crs_grp_types.GrpTypName," - "crs_grp.GrpName", + "crs_grp.GrpName", Svy->SvyCod); /***** Write heading *****/ @@ -2576,10 +2583,12 @@ void Svy_RemoveSurveys (Hie_Lvl_Level_t Scope,long Cod) /***** Remove groups *****/ DB_QueryDELETE ("can not remove all the groups" " associated to surveys of a course", - "DELETE FROM svy_grp" - " USING svy_surveys,svy_grp" - " WHERE svy_surveys.Scope='%s' AND svy_surveys.Cod=%ld" - " AND svy_surveys.SvyCod=svy_grp.SvyCod", + "DELETE FROM svy_groups" + " USING svy_surveys," + "svy_groups" + " WHERE svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=%ld" + " AND svy_surveys.SvyCod=svy_groups.SvyCod", Sco_GetDBStrFromScope (Scope),Cod); /***** Remove course surveys *****/ @@ -2598,12 +2607,19 @@ static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod) { /***** Get if I can do a survey from database *****/ return (DB_QueryCOUNT ("can not check if I can do a survey", - "SELECT COUNT(*) FROM svy_surveys" + "SELECT COUNT(*)" + " FROM svy_surveys" " WHERE SvyCod=%ld" - " AND (SvyCod NOT IN (SELECT SvyCod FROM svy_grp) OR" - " SvyCod IN (SELECT svy_grp.SvyCod FROM svy_grp,crs_grp_usr" - " WHERE crs_grp_usr.UsrCod=%ld" - " AND svy_grp.GrpCod=crs_grp_usr.GrpCod))", + " AND" + " (SvyCod NOT IN" + " (SELECT SvyCod FROM svy_groups)" + " OR" + " SvyCod IN" + " (SELECT svy_groups.SvyCod" + " FROM crs_grp_usr," + "svy_groups" + " WHERE crs_grp_usr.UsrCod=%ld" + " AND svy_groups.GrpCod=crs_grp_usr.GrpCod))", SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0); }