Version 21.0.2: Sep 13, 2021 Queries moved to module swad_notification.

This commit is contained in:
acanas 2021-09-13 23:26:25 +02:00
parent 304d2c1275
commit d239a2eb2b
5 changed files with 115 additions and 96 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.
*/
#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)

View File

@ -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);

View File

@ -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
}
}

View File

@ -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

View File

@ -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"