From d239a2eb2b00d3e8095e6a1c70b8c2b9f8a19629 Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 13 Sep 2021 23:26:25 +0200 Subject: [PATCH] Version 21.0.2: Sep 13, 2021 Queries moved to module swad_notification. --- swad_changelog.h | 3 +- swad_figure.c | 115 +++++++-------------------------------- swad_notification.c | 90 ++++++++++++++++++++++++++++++ swad_notification.h | 2 + swad_timeline_database.c | 1 + 5 files changed, 115 insertions(+), 96 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index bfcdac5d8..22e15f805 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.0.1 (2021-09-13)" +#define Log_PLATFORM_VERSION "SWAD 21.0.2 (2021-09-13)" #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.0.2: Sep 13, 2021 Queries moved to module swad_notification. (314927 lines) Version 21.0.1: Sep 13, 2021 Queries moved to module swad_follow_database. (314910 lines) Version 21.0: Sep 13, 2021 Fixed bug in degrees photo. (314914 lines) Version 20.100.5: Sep 12, 2021 Fixed bug removing all students in a course. Reported by José Luis Bernier Villamor and Francisco J. Pelayo Valle. (314909 lines) diff --git a/swad_figure.c b/swad_figure.c index dcda38f7f..2f3d1142f 100644 --- a/swad_figure.c +++ b/swad_figure.c @@ -2858,108 +2858,33 @@ static void Fig_GetAndShowNumUsrsPerNotifyEvent (void) free (SubQuery); /* Get number of notifications by email from database */ - switch (Gbl.Scope.Current) + if (Ntf_DB_GetNumNotifs (&mysql_res,NotifyEvent)) { - case HieLvl_SYS: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(NumEvents)," // row[0] - "SUM(NumMails)" // row[1] - " FROM sta_notifications" - " WHERE NotifyEvent=%u", - (unsigned) NotifyEvent); - break; - case HieLvl_CTY: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(sta_notifications.NumEvents)," // row[0] - "SUM(sta_notifications.NumMails)" // row[1] - " FROM ins_instits," - "ctr_centers," - "deg_degrees," - "sta_notifications" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=sta_notifications.DegCod" - " AND sta_notifications.NotifyEvent=%u", - Gbl.Hierarchy.Cty.CtyCod, - (unsigned) NotifyEvent); - break; - case HieLvl_INS: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(sta_notifications.NumEvents)," // row[0] - "SUM(sta_notifications.NumMails)" // row[1] - " FROM ctr_centers," - "deg_degrees," - "sta_notifications" - " WHERE ctr_centers.InsCod=%ld" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=sta_notifications.DegCod" - " AND sta_notifications.NotifyEvent=%u", - Gbl.Hierarchy.Ins.InsCod, - (unsigned) NotifyEvent); - break; - case HieLvl_CTR: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(sta_notifications.NumEvents)," // row[0] - "SUM(sta_notifications.NumMails)" // row[1] - " FROM deg_degrees," - "sta_notifications" - " WHERE deg_degrees.CtrCod=%ld" - " AND deg_degrees.DegCod=sta_notifications.DegCod" - " AND sta_notifications.NotifyEvent=%u", - Gbl.Hierarchy.Ctr.CtrCod, - (unsigned) NotifyEvent); - break; - case HieLvl_DEG: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(NumEvents)," // row[0] - "SUM(NumMails)" // row[1] - " FROM sta_notifications" - " WHERE DegCod=%ld" - " AND NotifyEvent=%u", - Gbl.Hierarchy.Deg.DegCod, - (unsigned) NotifyEvent); - break; - case HieLvl_CRS: - DB_QuerySELECT (&mysql_res,"can not get the number" - " of notifications by email", - "SELECT SUM(NumEvents)," // row[0] - "SUM(NumMails)" // row[1] - " FROM sta_notifications" - " WHERE CrsCod=%ld" - " AND NotifyEvent=%u", - Gbl.Hierarchy.Crs.CrsCod, - (unsigned) NotifyEvent); - break; - default: - Err_WrongScopeExit (); - break; - } + row = mysql_fetch_row (mysql_res); - row = mysql_fetch_row (mysql_res); + /* Get number of events notified */ + if (row[0]) + { + if (sscanf (row[0],"%u",&NumEvents[NotifyEvent]) != 1) + Err_ShowErrorAndExit ("Error when getting the number of notifications by email."); + } + else + NumEvents[NotifyEvent] = 0; - /* Get number of events notified */ - if (row[0]) - { - if (sscanf (row[0],"%u",&NumEvents[NotifyEvent]) != 1) - Err_ShowErrorAndExit ("Error when getting the number of notifications by email."); + /* Get number of mails sent */ + if (row[1]) + { + if (sscanf (row[1],"%u",&NumMails[NotifyEvent]) != 1) + Err_ShowErrorAndExit ("Error when getting the number of emails to notify events3."); + } + else + NumMails[NotifyEvent] = 0; } else + { NumEvents[NotifyEvent] = 0; - - /* Get number of mails sent */ - if (row[1]) - { - if (sscanf (row[1],"%u",&NumMails[NotifyEvent]) != 1) - Err_ShowErrorAndExit ("Error when getting the number of emails to notify events3."); + NumMails[NotifyEvent] = 0; } - else - NumMails[NotifyEvent] = 0; /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_notification.c b/swad_notification.c index 67f777b0d..32d28bc17 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -2223,3 +2223,93 @@ void Ntf_DB_RemoveUsrNtfs (long ToUsrCod) " WHERE ToUsrCod=%ld", ToUsrCod); } + +/*****************************************************************************/ +/****************** Get number of notifications by email *********************/ +/*****************************************************************************/ + +unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent) + { + switch (Gbl.Scope.Current) + { + case HieLvl_SYS: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(NumEvents)," // row[0] + "SUM(NumMails)" // row[1] + " FROM sta_notifications" + " WHERE NotifyEvent=%u", + (unsigned) NotifyEvent); + case HieLvl_CTY: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(sta_notifications.NumEvents)," // row[0] + "SUM(sta_notifications.NumMails)" // row[1] + " FROM ins_instits," + "ctr_centers," + "deg_degrees," + "sta_notifications" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=ctr_centers.InsCod" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=sta_notifications.DegCod" + " AND sta_notifications.NotifyEvent=%u", + Gbl.Hierarchy.Cty.CtyCod, + (unsigned) NotifyEvent); + case HieLvl_INS: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(sta_notifications.NumEvents)," // row[0] + "SUM(sta_notifications.NumMails)" // row[1] + " FROM ctr_centers," + "deg_degrees," + "sta_notifications" + " WHERE ctr_centers.InsCod=%ld" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=sta_notifications.DegCod" + " AND sta_notifications.NotifyEvent=%u", + Gbl.Hierarchy.Ins.InsCod, + (unsigned) NotifyEvent); + case HieLvl_CTR: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(sta_notifications.NumEvents)," // row[0] + "SUM(sta_notifications.NumMails)" // row[1] + " FROM deg_degrees," + "sta_notifications" + " WHERE deg_degrees.CtrCod=%ld" + " AND deg_degrees.DegCod=sta_notifications.DegCod" + " AND sta_notifications.NotifyEvent=%u", + Gbl.Hierarchy.Ctr.CtrCod, + (unsigned) NotifyEvent); + case HieLvl_DEG: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(NumEvents)," // row[0] + "SUM(NumMails)" // row[1] + " FROM sta_notifications" + " WHERE DegCod=%ld" + " AND NotifyEvent=%u", + Gbl.Hierarchy.Deg.DegCod, + (unsigned) NotifyEvent); + case HieLvl_CRS: + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the number" + " of notifications by email", + "SELECT SUM(NumEvents)," // row[0] + "SUM(NumMails)" // row[1] + " FROM sta_notifications" + " WHERE CrsCod=%ld" + " AND NotifyEvent=%u", + Gbl.Hierarchy.Crs.CrsCod, + (unsigned) NotifyEvent); + default: + Err_WrongScopeExit (); + return 0; // Not reached + } + } diff --git a/swad_notification.h b/swad_notification.h index 1d476511c..3ce38be90 100644 --- a/swad_notification.h +++ b/swad_notification.h @@ -142,4 +142,6 @@ void Ntf_ChangeNotifyEvents (void); void Ntf_WriteNumberOfNewNtfs (void); void Ntf_DB_RemoveUsrNtfs (long ToUsrCod); +unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent); + #endif diff --git a/swad_timeline_database.c b/swad_timeline_database.c index ddf00ded5..0da2e3ad3 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -28,6 +28,7 @@ #include "swad_database.h" #include "swad_error.h" #include "swad_follow.h" +#include "swad_follow_database.h" #include "swad_global.h" #include "swad_timeline.h" #include "swad_timeline_database.h"