Version19.210

This commit is contained in:
acanas 2020-05-03 20:58:03 +02:00
parent a62b8fc90e
commit a0da2d16bf
27 changed files with 1202 additions and 712 deletions

View File

@ -172,7 +172,7 @@ static const char *API_Functions[1 + API_NUM_FUNCTIONS] =
#define API_NUM_ROLES 4
typedef enum
{
API_ROLE_UNKNOWN = 0, // User not logged in
API_ROLE_UNKNOWN = 0, // User not logged in (do not change this constant to any value other than 0)
API_ROLE__GUEST_ = 1, // User not belonging to any course
API_ROLE_STUDENT = 2, // Student in current course
API_ROLE_TEACHER = 3, // Teacher in current course
@ -190,16 +190,10 @@ static const Rol_Role_t API_SvcRole_to_RolRole[API_NUM_ROLES] =
/* Translation from swad-core-role to service-web-role */
static const API_Role_t API_RolRole_to_SvcRole[Rol_NUM_ROLES] =
{
[Rol_UNK ] = API_ROLE_UNKNOWN,
[Rol_GST ] = API_ROLE__GUEST_,
[Rol_USR ] = API_ROLE_UNKNOWN,
[Rol_STD ] = API_ROLE_STUDENT,
[Rol_NET ] = API_ROLE_TEACHER, // TODO: Create new web service role for non-editing teachers
[Rol_TCH ] = API_ROLE_TEACHER,
[Rol_DEG_ADM] = API_ROLE_UNKNOWN,
[Rol_CTR_ADM] = API_ROLE_UNKNOWN,
[Rol_INS_ADM] = API_ROLE_UNKNOWN,
[Rol_SYS_ADM] = API_ROLE_UNKNOWN,
[Rol_GST] = API_ROLE__GUEST_,
[Rol_STD] = API_ROLE_STUDENT,
[Rol_NET] = API_ROLE_TEACHER, // TODO: Create new web service role for non-editing teachers
[Rol_TCH] = API_ROLE_TEACHER,
};
#define API_BYTES_WS_KEY Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64

View File

@ -361,7 +361,6 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
const char *TxtClassNormal;
const char *TxtClassStrong;
const char *BgColor;
unsigned NumUsrsInCrss;
Ctr_StatusTxt_t StatusTxt;
/***** Get data of place of this centre *****/
@ -396,7 +395,7 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
/***** Number of users who claim to belong to this centre *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr));
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCtr (Ctr));
HTM_TD_End ();
/***** Place *****/
@ -406,28 +405,20 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
/***** Number of degrees *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Deg_GetNumDegsInCtr (Ctr->CtrCod));
HTM_Unsigned (Deg_GetCachedNumDegsInCtr (Ctr->CtrCod));
HTM_TD_End ();
/***** Number of courses *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Crs_GetNumCrssInCtr (Ctr->CtrCod));
HTM_Unsigned (Crs_GetCachedNumCrssInCtr (Ctr->CtrCod));
HTM_TD_End ();
/***** Number of users in courses of this centre *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTR,Ctr->CtrCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Hie_CTR,Ctr->CtrCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTR,Ctr->CtrCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_CTR,Ctr->CtrCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
HTM_TD_End ();
/***** Centre status *****/
@ -950,6 +941,7 @@ static void Ctr_ListCentresForEdition (const struct Plc_Places *Places)
struct UsrData UsrDat;
bool ICanEdit;
unsigned NumDegs;
unsigned NumUsrsCtr;
unsigned NumUsrsInCrssOfCtr;
Ctr_StatusTxt_t StatusTxt;
unsigned StatusUnsigned;
@ -970,6 +962,7 @@ static void Ctr_ListCentresForEdition (const struct Plc_Places *Places)
ICanEdit = Ctr_CheckIfICanEditACentre (Ctr);
NumDegs = Deg_GetNumDegsInCtr (Ctr->CtrCod);
NumUsrsCtr = Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr);
NumUsrsInCrssOfCtr = Usr_GetNumUsrsInCrss (Hie_CTR,Ctr->CtrCod,
1 << Rol_STD |
1 << Rol_NET |
@ -978,11 +971,10 @@ static void Ctr_ListCentresForEdition (const struct Plc_Places *Places)
/* Put icon to remove centre */
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"BM\"");
if (!ICanEdit || // I cannot edit
NumDegs || // Centre has degrees
NumUsrsInCrssOfCtr) // Centre has users
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr)) // Centre has users who claim to belong to it
if (!ICanEdit || // I cannot edit
NumDegs || // Centre has degrees
NumUsrsCtr || // Centre has users who claim to belong to it
NumUsrsInCrssOfCtr) // Centre has users
Ico_PutIconRemovalNotAllowed ();
else // I can remove centre
{
@ -1086,7 +1078,7 @@ static void Ctr_ListCentresForEdition (const struct Plc_Places *Places)
/* Number of users who claim to belong to this centre */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr));
HTM_Unsigned (NumUsrsCtr);
HTM_TD_End ();
/* Number of degrees */
@ -1927,10 +1919,21 @@ static void Ctr_CreateCentre (unsigned Status)
/************************** Get number of centres ****************************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsInSys (void)
unsigned Ctr_GetCachedNumCtrsInSys (void)
{
/***** Get total number of centres from database *****/
return (unsigned) DB_GetNumRowsTable ("centres");
unsigned NumCtrs;
/***** Get number of centres from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtrs))
{
/***** Get current number of centres from database and update cache *****/
NumCtrs = (unsigned) DB_GetNumRowsTable ("centres");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtrs);
}
return NumCtrs;
}
/*****************************************************************************/
@ -1964,6 +1967,23 @@ unsigned Ctr_GetNumCtrsInCty (long CtyCod)
return Gbl.Cache.NumCtrsInCty.NumCtrs;
}
unsigned Ctr_GetCachedNumCtrsInCty (long CtyCod)
{
unsigned NumCtrs;
/***** Get number of centres from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumCtrs))
{
/***** Get current number of centres from database and update cache *****/
NumCtrs = Ctr_GetNumCtrsInCty (CtyCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumCtrs);
}
return NumCtrs;
}
/*****************************************************************************/
/**************** Get number of centres in an institution ********************/
/*****************************************************************************/
@ -1995,17 +2015,46 @@ unsigned Ctr_GetNumCtrsInIns (long InsCod)
return Gbl.Cache.NumCtrsInIns.NumCtrs;
}
unsigned Ctr_GetCachedNumCtrsInIns (long InsCod)
{
unsigned NumCtrs;
/***** Get number of centres from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumCtrs))
{
/***** Get current number of centres from database and update cache *****/
NumCtrs = Ctr_GetNumCtrsInIns (InsCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumCtrs);
}
return NumCtrs;
}
/*****************************************************************************/
/********************** Get number of centres with map ***********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithMapInSys (void)
unsigned Ctr_GetCachedNumCtrsWithMapInSys (void)
{
/***** Get number of centres with map from database
(coordinates 0, 0 means not set ==> don't show map) *****/
return (unsigned) DB_QueryCOUNT ("can not get number of centres with map",
"SELECT COUNT(*) FROM centres"
" WHERE Latitude<>0 OR Longitude<>0");
unsigned NumCtrsWithMap;
/***** Get number of centres with map from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS_WITH_MAP,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtrsWithMap))
{
/***** Get current number of centres with map from database and update cache *****/
/* Ccoordinates 0, 0 means not set ==> don't show map */
NumCtrsWithMap = (unsigned)
DB_QueryCOUNT ("can not get number of centres with map",
"SELECT COUNT(*) FROM centres"
" WHERE Latitude<>0 OR Longitude<>0");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_MAP,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtrsWithMap);
}
return NumCtrsWithMap;
}
/*****************************************************************************/
@ -2057,52 +2106,94 @@ unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
/********************* Get number of centres with degrees ********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery)
unsigned Ctr_GetCachedNumCtrsWithDegs (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of centres with degrees from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with degrees",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
unsigned NumCtrsWithDegs;
/***** Get number of centres with degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS_WITH_DEGS,Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithDegs))
{
/***** Get current number of centres with degrees from database and update cache *****/
NumCtrsWithDegs = (unsigned)
DB_QueryCOUNT ("can not get number of centres with degrees",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_DEGS,Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithDegs);
}
return NumCtrsWithDegs;
}
/*****************************************************************************/
/********************* Get number of centres with courses ********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery)
unsigned Ctr_GetCachedNumCtrsWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of centres with courses from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with courses",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
unsigned NumCtrsWithCrss;
/***** Get number of centres with courses *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithCrss))
{
/***** Get number of centres with courses *****/
NumCtrsWithCrss = (unsigned)
DB_QueryCOUNT ("can not get number of centres with courses",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithCrss);
}
return NumCtrsWithCrss;
}
/*****************************************************************************/
/********************* Get number of centres with users **********************/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery)
unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of centres with users from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of centres with users",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
static const FigCch_FigureCached_t FigureCtrs[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_CTRS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_CTRS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_CTRS_WITH_TCHS, // Teachers
};
unsigned NumCtrsWithUsrs;
/***** Get number of centres with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureCtrs[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithUsrs))
{
/***** Get current number of centres with users from database and update cache *****/
NumCtrsWithUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of centres with users",
"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
FigCch_UpdateFigureIntoCache (FigureCtrs[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtrsWithUsrs);
}
return NumCtrsWithUsrs;
}
/*****************************************************************************/

View File

@ -132,18 +132,27 @@ void Ctr_ContEditAfterChgCtr (void);
void Ctr_RecFormReqCtr (void);
void Ctr_RecFormNewCtr (void);
unsigned Ctr_GetNumCtrsInSys (void);
unsigned Ctr_GetCachedNumCtrsInSys (void);
void Ctr_FlushCacheNumCtrsInCty (void);
unsigned Ctr_GetNumCtrsInCty (long CtyCod);
unsigned Ctr_GetCachedNumCtrsInCty (long CtyCod);
void Ctr_FlushCacheNumCtrsInIns (void);
unsigned Ctr_GetNumCtrsInIns (long InsCod);
unsigned Ctr_GetNumCtrsWithMapInSys (void);
unsigned Ctr_GetCachedNumCtrsInIns (long InsCod);
unsigned Ctr_GetCachedNumCtrsWithMapInSys (void);
unsigned Ctr_GetNumCtrsWithMapInCty (long CtyCod);
unsigned Ctr_GetNumCtrsWithMapInIns (long InsCod);
unsigned Ctr_GetNumCtrsInPlc (long PlcCod);
unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery);
unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery);
unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Ctr_GetCachedNumCtrsWithDegs (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Ctr_GetCachedNumCtrsWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod);
void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs);

View File

@ -35,6 +35,7 @@
#include "swad_centre.h"
#include "swad_database.h"
#include "swad_figure_cache.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_help.h"
@ -744,7 +745,7 @@ static void CtrCfg_NumUsrs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (&Gbl.Hierarchy.Ctr));
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCtr (&Gbl.Hierarchy.Ctr));
HTM_TD_End ();
HTM_TR_End ();
@ -773,7 +774,7 @@ static void CtrCfg_NumDegs (void)
Gbl.Hierarchy.Ctr.ShrtName),
"BT_LINK DAT",NULL);
Str_FreeString ();
HTM_Unsigned (Deg_GetNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod));
HTM_Unsigned (Deg_GetCachedNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod));
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
@ -797,7 +798,7 @@ static void CtrCfg_NumCrss (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Crs_GetNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod));
HTM_Unsigned (Crs_GetCachedNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod));
HTM_TD_End ();
HTM_TR_End ();

View File

@ -544,10 +544,15 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 19.209.5 (2020-05-02)"
#define Log_PLATFORM_VERSION "SWAD 19.210 (2020-05-03)"
#define CSS_FILE "swad19.193.1.css"
#define JS_FILE "swad19.193.1.js"
/*
Version 19.210: May 03, 2020 More figures cached. (301124 lines)
1 change necessary in database:
DELETE FROM figures;
Version 19.209.6: May 02, 2020 More figures cached. (300815 lines)
Version 19.209.5: May 02, 2020 More figures cached. (300756 lines)
Version 19.209.4: May 02, 2020 More figures cached.
Code refactoring in hierarchy configuration. (300637 lines)

View File

@ -228,7 +228,6 @@ void Cty_ListCountries2 (void)
extern const char *Txt_Other_countries;
extern const char *Txt_Country_unspecified;
unsigned NumCty;
unsigned NumUsrsInCrss;
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
@ -264,40 +263,37 @@ void Cty_ListCountries2 (void)
HTM_Txt (Txt_Other_countries);
HTM_TD_End ();
/* Number of users who claim to belong to another country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToAnotherCty ());
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty ());
HTM_TD_End ();
/* Number of institutions in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ins_GetNumInssInCty (0));
HTM_Unsigned (Ins_GetCachedNumInssInCty (0));
HTM_TD_End ();
/* Number of centres in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr_GetNumCtrsInCty (0));
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (0));
HTM_TD_End ();
/* Number of degrees in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Deg_GetNumDegsInCty (0));
HTM_Unsigned (Deg_GetCachedNumDegsInCty (0));
HTM_TD_End ();
/* Number of courses in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Crs_GetNumCrssInCty (0));
HTM_Unsigned (Crs_GetCachedNumCrssInCty (0));
HTM_TD_End ();
/* Number of users in courses of other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTY,0,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Hie_CTY,0,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTY,0,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_CTY,0,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
HTM_TD_End ();
HTM_TR_End ();
@ -312,24 +308,29 @@ void Cty_ListCountries2 (void)
HTM_Txt (Txt_Country_unspecified);
HTM_TD_End ();
/* Number of users who do not claim to belong to any country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty ());
HTM_Unsigned (Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty ());
HTM_TD_End ();
/* Number of institutions with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ins_GetNumInssInCty (-1L));
HTM_Unsigned (Ins_GetCachedNumInssInCty (-1L));
HTM_TD_End ();
/* Number of centres with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr_GetNumCtrsInCty (-1L));
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (-1L));
HTM_TD_End ();
/* Number of degrees with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Deg_GetNumDegsInCty (-1L));
HTM_Unsigned (Deg_GetCachedNumDegsInCty (-1L));
HTM_TD_End ();
/* Number of courses with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Crs_GetNumCrssInCty (-1L));
HTM_Unsigned (Crs_GetCachedNumCrssInCty (-1L));
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\"");
@ -415,8 +416,6 @@ static void Cty_PutHeadCountriesForSeeing (bool OrderSelectable)
static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty)
{
const char *BgColor;
unsigned NumUsrsCty;
unsigned NumUsrsInCrss;
BgColor = (Cty->CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
@ -438,48 +437,35 @@ static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty)
/***** Number of users who claim to belong to this country *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_CTY,Hie_CTY,Cty->CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsCty))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToCty (Cty);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_CTY,Hie_CTY,Cty->CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsCty);
}
HTM_Unsigned (NumUsrsCty);
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (Cty));
HTM_TD_End ();
/***** Other stats *****/
/***** Number of institutions *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Ins_GetNumInssInCty (Cty->CtyCod));
HTM_Unsigned (Ins_GetCachedNumInssInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of centres *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Ctr_GetNumCtrsInCty (Cty->CtyCod));
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of degrees *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Deg_GetNumDegsInCty (Cty->CtyCod));
HTM_Unsigned (Deg_GetCachedNumDegsInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of courses *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Crs_GetNumCrssInCty (Cty->CtyCod));
HTM_Unsigned (Crs_GetCachedNumCrssInCty (Cty->CtyCod));
HTM_TD_End ();
/* Number of users in courses */
/***** Number of users in courses *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTY,Cty->CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Hie_CTY,Cty->CtyCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_IN_CRSS,Hie_CTY,Cty->CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_CTY,Cty->CtyCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
HTM_TD_End ();
HTM_TR_End ();
@ -612,7 +598,8 @@ void Cty_WriteScriptGoogleGeochart (void)
extern const char *Txt_Users_NO_HTML;
extern const char *Txt_Institutions_NO_HTML;
unsigned NumCty;
unsigned NumUsrsWhoClaimToBelongToCty;
unsigned NumUsrsCty;
unsigned NumInss;
unsigned MaxUsrsInCountry = 0;
unsigned NumCtysWithUsrs = 0;
@ -638,16 +625,16 @@ void Cty_WriteScriptGoogleGeochart (void)
NumCty < Gbl.Hierarchy.Ctys.Num;
NumCty++)
{
NumUsrsWhoClaimToBelongToCty = Usr_GetNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Ctys.Lst[NumCty]);
if (NumUsrsWhoClaimToBelongToCty)
NumUsrsCty = Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Ctys.Lst[NumCty]);
if (NumUsrsCty)
{
NumInss = Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod);
/* Write data of this country */
HTM_TxtF (" ['%s', %u, %u],\n",
Gbl.Hierarchy.Ctys.Lst[NumCty].Alpha2,
NumUsrsWhoClaimToBelongToCty,
Ins_GetNumInssInCty (Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod));
if (NumUsrsWhoClaimToBelongToCty > MaxUsrsInCountry)
MaxUsrsInCountry = NumUsrsWhoClaimToBelongToCty;
Gbl.Hierarchy.Ctys.Lst[NumCty].Alpha2,NumUsrsCty,NumInss);
if (NumUsrsCty > MaxUsrsInCountry)
MaxUsrsInCountry = NumUsrsCty;
NumCtysWithUsrs++;
}
}
@ -1208,7 +1195,8 @@ static void Cty_ListCountriesForEdition (void)
extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES];
unsigned NumCty;
struct Country *Cty;
unsigned NumInssInCty;
unsigned NumInss;
unsigned NumUsrsCty;
Lan_Language_t Lan;
/***** Write heading *****/
@ -1221,22 +1209,21 @@ static void Cty_ListCountriesForEdition (void)
NumCty++)
{
Cty = &Gbl.Hierarchy.Ctys.Lst[NumCty];
NumInssInCty = Ins_GetNumInssInCty (Cty->CtyCod);
NumInss = Ins_GetNumInssInCty (Cty->CtyCod);
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToCty (Cty);
HTM_TR_Begin (NULL);
/* Put icon to remove country */
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
if (NumInssInCty) // Country has institutions
// Deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty)) // Country has users
if (NumInss || // Country has institutions
NumUsrsCty) // Country has users
// Deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsInCrss (Hie_CTY,Cty->CtyCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)) // Country has users
1 << Rol_TCH)) // Country has users
// Deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
@ -1262,12 +1249,12 @@ static void Cty_ListCountriesForEdition (void)
/* Number of users */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty));
HTM_Unsigned (NumUsrsCty);
HTM_TD_End ();
/* Number of institutions */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (NumInssInCty);
HTM_Unsigned (NumInss);
HTM_TD_End ();
HTM_TR_End ();
@ -1933,97 +1920,164 @@ static void Cty_CreateCountry (void)
/*********************** Get total number of countries ***********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysTotal (void)
unsigned Cty_GetCachedNumCtysInSys (void)
{
/***** Get total number of countries from database *****/
return (unsigned) DB_GetNumRowsTable ("countries");
unsigned NumCtys;
/***** Get number of countries from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtys))
{
/***** Get current number of countries from database and update cache *****/
NumCtys = (unsigned) DB_GetNumRowsTable ("countries");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtys);
}
return NumCtys;
}
/*****************************************************************************/
/***************** Get number of countries with institutions *****************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithInss (const char *SubQuery)
unsigned Cty_GetCachedNumCtysWithInss (void)
{
/***** Get number of countries with institutions from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of countries"
" with institutions",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions"
" WHERE %scountries.CtyCod=institutions.CtyCod",
SubQuery);
unsigned NumCtysWithInss;
/***** Get number of countries with institutions from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_INSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithInss))
{
/***** Get current number of countries with institutions from cache *****/
NumCtysWithInss = (unsigned)
DB_QueryCOUNT ("can not get number of countries"
" with institutions",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions"
" WHERE countries.CtyCod=institutions.CtyCod");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_INSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithInss);
}
return NumCtysWithInss;
}
/*****************************************************************************/
/******************* Get number of countries with centres ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithCtrs (const char *SubQuery)
unsigned Cty_GetCachedNumCtysWithCtrs (void)
{
/***** Get number of countries with centres from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with centres",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod",
SubQuery);
unsigned NumCtysWithCtrs;
/***** Get number of countries with centres from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_CTRS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithCtrs))
{
/***** Get current number of countries with centres from database and update cache *****/
NumCtysWithCtrs = (unsigned)
DB_QueryCOUNT ("can not get number of countries with centres",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres"
" WHERE countries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_CTRS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithCtrs);
}
return NumCtysWithCtrs;
}
/*****************************************************************************/
/******************* Get number of countries with degrees ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithDegs (const char *SubQuery)
unsigned Cty_GetCachedNumCtysWithDegs (void)
{
/***** Get number of countries with degrees from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with degrees",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
unsigned NumCtysWithDegs;
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_DEGS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithDegs))
{
NumCtysWithDegs = (unsigned)
DB_QueryCOUNT ("can not get number of countries with degrees",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees"
" WHERE countries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_DEGS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithDegs);
}
return NumCtysWithDegs;
}
/*****************************************************************************/
/******************* Get number of countries with courses ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithCrss (const char *SubQuery)
unsigned Cty_GetCachedNumCtysWithCrss (void)
{
/***** Get number of countries with courses from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with courses",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
unsigned NumCtysWithCrss;
/***** Get number of countries with courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_CRSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithCrss))
{
/***** Get current number of countries with courses from database and update cache *****/
NumCtysWithCrss = (unsigned)
DB_QueryCOUNT ("can not get number of countries with courses",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses"
" WHERE countries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_CRSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCtysWithCrss);
}
return NumCtysWithCrss;
}
/*****************************************************************************/
/******************* Get number of countries with users **********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery)
unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of countries with users from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with users",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses,crs_usr"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
static const FigCch_FigureCached_t FigureCtys[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_CTYS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_CTYS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_CTYS_WITH_TCHS, // Teachers
};
unsigned NumCtysWithUsrs;
/***** Get number of countries with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureCtys[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtysWithUsrs))
{
/***** Get current number of countries with users from database and update cache *****/
NumCtysWithUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of countries with users",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses,crs_usr"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
FigCch_UpdateFigureIntoCache (FigureCtys[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtysWithUsrs);
}
return NumCtysWithUsrs;
}
/*****************************************************************************/

View File

@ -112,12 +112,15 @@ void Cty_ChangeCtyWWW (void);
void Cty_ContEditAfterChgCty (void);
void Cty_RecFormNewCountry (void);
unsigned Cty_GetNumCtysTotal (void);
unsigned Cty_GetNumCtysWithInss (const char *SubQuery);
unsigned Cty_GetNumCtysWithCtrs (const char *SubQuery);
unsigned Cty_GetNumCtysWithDegs (const char *SubQuery);
unsigned Cty_GetNumCtysWithCrss (const char *SubQuery);
unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Cty_GetCachedNumCtysInSys (void);
unsigned Cty_GetCachedNumCtysWithInss (void);
unsigned Cty_GetCachedNumCtysWithCtrs (void);
unsigned Cty_GetCachedNumCtysWithDegs (void);
unsigned Cty_GetCachedNumCtysWithCrss (void);
unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod);
void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys);

View File

@ -154,7 +154,7 @@ static void CtyCfg_Configuration (bool PrintView)
CtyCfg_QR ();
else
{
NumCtrs = Ctr_GetNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod);
NumCtrs = Ctr_GetCachedNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod);
/***** Number of users who claim to belong to this country,
number of institutions,
@ -475,7 +475,6 @@ static void CtyCfg_QR (void)
static void CtyCfg_NumUsrs (void)
{
extern const char *Txt_Users_of_the_country;
unsigned NumUsrsCty;
/***** Number of users *****/
HTM_TR_Begin (NULL);
@ -485,15 +484,7 @@ static void CtyCfg_NumUsrs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_CTY,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsCty))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Cty);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_CTY,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod,
FigCch_Type_UNSIGNED,&NumUsrsCty);
}
HTM_Unsigned (NumUsrsCty);
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Cty));
HTM_TD_End ();
HTM_TR_End ();
@ -522,7 +513,7 @@ static void CtyCfg_NumInss (void)
Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]),
"BT_LINK DAT",NULL);
Str_FreeString ();
HTM_Unsigned (Ins_GetNumInssInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_Unsigned (Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
@ -546,7 +537,7 @@ static void CtyCfg_NumDegs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Deg_GetNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_Unsigned (Deg_GetCachedNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_TD_End ();
HTM_TR_End ();
@ -568,7 +559,7 @@ static void CtyCfg_NumCrss (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Crs_GetNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_Unsigned (Crs_GetCachedNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod));
HTM_TD_End ();
HTM_TR_End ();

View File

@ -37,6 +37,7 @@
#include "swad_database.h"
#include "swad_exam_announcement.h"
#include "swad_figure.h"
#include "swad_figure_cache.h"
#include "swad_form.h"
#include "swad_forum.h"
#include "swad_global.h"
@ -408,10 +409,21 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
/*********************** Get total number of courses *************************/
/*****************************************************************************/
unsigned Crs_GetNumCrssTotal (void)
unsigned Crs_GetCachedNumCrssInSys (void)
{
/***** Get total number of courses from database *****/
return (unsigned) DB_GetNumRowsTable ("courses");
unsigned NumCrss;
/***** Get number of courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCrss))
{
/***** Get current number of courses from database and update cache *****/
NumCrss = (unsigned) DB_GetNumRowsTable ("courses");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumCrss);
}
return NumCrss;
}
/*****************************************************************************/
@ -448,6 +460,23 @@ unsigned Crs_GetNumCrssInCty (long CtyCod)
return Gbl.Cache.NumCrssInCty.NumCrss;
}
unsigned Crs_GetCachedNumCrssInCty (long CtyCod)
{
unsigned NumCrss;
/***** Get number of courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumCrss))
{
/***** Get current number of courses from database and update cache *****/
NumCrss = Crs_GetNumCrssInCty (CtyCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumCrss);
}
return NumCrss;
}
/*****************************************************************************/
/**************** Get number of courses in an institution ********************/
/*****************************************************************************/
@ -481,6 +510,23 @@ unsigned Crs_GetNumCrssInIns (long InsCod)
return Gbl.Cache.NumCrssInIns.NumCrss;
}
unsigned Crs_GetCachedNumCrssInIns (long InsCod)
{
unsigned NumCrss;
/***** Get number of courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumCrss))
{
/***** Get current number of courses from database and update cache *****/
NumCrss = Crs_GetNumCrssInIns (InsCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumCrss);
}
return NumCrss;
}
/*****************************************************************************/
/******************** Get number of courses in a centre **********************/
/*****************************************************************************/
@ -512,6 +558,23 @@ unsigned Crs_GetNumCrssInCtr (long CtrCod)
return Gbl.Cache.NumCrssInCtr.NumCrss;
}
unsigned Crs_GetCachedNumCrssInCtr (long CtrCod)
{
unsigned NumCrss;
/***** Get number of courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_CTR,CtrCod,
FigCch_UNSIGNED,&NumCrss))
{
/***** Get current number of courses from database and update cache *****/
NumCrss = Crs_GetNumCrssInCtr (CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_CTR,CtrCod,
FigCch_UNSIGNED,&NumCrss);
}
return NumCrss;
}
/*****************************************************************************/
/******************** Get number of courses in a degree **********************/
/*****************************************************************************/
@ -542,23 +605,58 @@ unsigned Crs_GetNumCrssInDeg (long DegCod)
return Gbl.Cache.NumCrssInDeg.NumCrss;
}
unsigned Crs_GetCachedNumCrssInDeg (long DegCod)
{
unsigned NumCrss;
/***** Get number of courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_DEG,DegCod,
FigCch_UNSIGNED,&NumCrss))
{
/***** Get current number of courses from database and update cache *****/
NumCrss = Crs_GetNumCrssInDeg (DegCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_DEG,DegCod,
FigCch_UNSIGNED,&NumCrss);
}
return NumCrss;
}
/*****************************************************************************/
/********************* Get number of courses with users **********************/
/*****************************************************************************/
unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery)
unsigned Crs_GetCachedNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of degrees with users from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of courses with users",
"SELECT COUNT(DISTINCT courses.CrsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
static const FigCch_FigureCached_t FigureCrss[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_CRSS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_CRSS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_CRSS_WITH_TCHS, // Teachers
};
unsigned NumCrssWithUsrs;
/***** Get number of courses with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureCrss[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCrssWithUsrs))
{
/***** Get current number of courses with users from database and update cache *****/
NumCrssWithUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of courses with users",
"SELECT COUNT(DISTINCT courses.CrsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
FigCch_UpdateFigureIntoCache (FigureCrss[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCrssWithUsrs);
}
return NumCrssWithUsrs;
}
/*****************************************************************************/
@ -927,9 +1025,9 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year)
HTM_TR_Begin (NULL);
/* Get number of users */
NumUsrs[Rol_STD] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_STD);
NumUsrs[Rol_NET] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_NET);
NumUsrs[Rol_TCH] = Usr_GetNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_TCH);
NumUsrs[Rol_STD] = Usr_GetCachedNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_STD);
NumUsrs[Rol_NET] = Usr_GetCachedNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_NET);
NumUsrs[Rol_TCH] = Usr_GetCachedNumUsrsInCrss (Hie_CRS,Crs->CrsCod,1 << Rol_TCH);
NumUsrs[Rol_UNK] = NumUsrs[Rol_STD] +
NumUsrs[Rol_NET] +
NumUsrs[Rol_TCH];

View File

@ -99,16 +99,26 @@ struct ListCourses
void Crs_ShowIntroduction (void);
unsigned Crs_GetNumCrssTotal (void);
unsigned Crs_GetCachedNumCrssInSys (void);
void Crs_FlushCacheNumCrssInCty (void);
unsigned Crs_GetNumCrssInCty (long CtyCod);
unsigned Crs_GetCachedNumCrssInCty (long CtyCod);
void Crs_FlushCacheNumCrssInIns (void);
unsigned Crs_GetNumCrssInIns (long InsCod);
unsigned Crs_GetCachedNumCrssInIns (long InsCod);
void Crs_FlushCacheNumCrssInCtr (void);
unsigned Crs_GetNumCrssInCtr (long CtrCod);
unsigned Crs_GetCachedNumCrssInCtr (long CtrCod);
void Crs_FlushCacheNumCrssInDeg (void);
unsigned Crs_GetNumCrssInDeg (long DegCod);
unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Crs_GetCachedNumCrssInDeg (long DegCod);
unsigned Crs_GetCachedNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod);
void Crs_WriteSelectorOfCourse (void);
void Crs_ShowCrssOfCurrentDeg (void);

View File

@ -888,8 +888,7 @@ static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg)
const char *TxtClassNormal;
const char *TxtClassStrong;
const char *BgColor;
unsigned NumCrss = Crs_GetNumCrssInDeg (Deg->DegCod);
unsigned NumUsrsInCrss;
unsigned NumCrss = Crs_GetCachedNumCrssInDeg (Deg->DegCod);
Deg_StatusTxt_t StatusTxt;
/***** Get data of type of degree of this degree *****/
@ -944,18 +943,10 @@ static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg)
/***** Number of users in courses of this degree *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_IN_CRSS,Hie_DEG,Deg->DegCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Hie_DEG,Deg->DegCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_IN_CRSS,Hie_DEG,Deg->DegCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_DEG,Deg->DegCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
HTM_TD_End ();
/***** Degree status *****/
@ -1904,10 +1895,21 @@ void Deg_RemoveLogo (void)
/*********************** Get total number of degrees *************************/
/*****************************************************************************/
unsigned Deg_GetNumDegsTotal (void)
unsigned Deg_GetCachedNumDegsInSys (void)
{
/***** Get total number of degrees from database *****/
return (unsigned) DB_GetNumRowsTable ("degrees");
unsigned NumDegs;
/***** Get number of degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumDegs))
{
/***** Get current number of degrees from database and update cache *****/
NumDegs = (unsigned) DB_GetNumRowsTable ("degrees");
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumDegs);
}
return NumDegs;
}
/*****************************************************************************/
@ -1942,6 +1944,23 @@ unsigned Deg_GetNumDegsInCty (long CtyCod)
return Gbl.Cache.NumDegsInCty.NumDegs;
}
unsigned Deg_GetCachedNumDegsInCty (long CtyCod)
{
unsigned NumDegs;
/***** Get number of degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumDegs))
{
/***** Get current number of degrees from database and update cache *****/
NumDegs = Deg_GetNumDegsInCty (CtyCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumDegs);
}
return NumDegs;
}
/*****************************************************************************/
/****************** Get number of degrees in an institution ******************/
/*****************************************************************************/
@ -1974,6 +1993,23 @@ unsigned Deg_GetNumDegsInIns (long InsCod)
return Gbl.Cache.NumDegsInIns.NumDegs;
}
unsigned Deg_GetCachedNumDegsInIns (long InsCod)
{
unsigned NumDegs;
/***** Get number of degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumDegs))
{
/***** Get current number of degrees from database and update cache *****/
NumDegs = Deg_GetNumDegsInIns (InsCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_INS,InsCod,
FigCch_UNSIGNED,&NumDegs);
}
return NumDegs;
}
/*****************************************************************************/
/******************** Get number of degrees in a centre **********************/
/*****************************************************************************/
@ -2004,40 +2040,87 @@ unsigned Deg_GetNumDegsInCtr (long CtrCod)
return Gbl.Cache.NumDegsInCtr.NumDegs;
}
unsigned Deg_GetCachedNumDegsInCtr (long CtrCod)
{
unsigned NumDegs;
/***** Get number of degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS,Hie_CTR,CtrCod,
FigCch_UNSIGNED,&NumDegs))
{
/***** Get current number of degrees from database and update cache *****/
NumDegs = Deg_GetNumDegsInCtr (CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_CTR,CtrCod,
FigCch_UNSIGNED,&NumDegs);
}
return NumDegs;
}
/*****************************************************************************/
/********************* Get number of centres with courses ********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsWithCrss (const char *SubQuery)
unsigned Deg_GetCachedNumDegsWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of degrees with courses from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of degrees with courses",
"SELECT COUNT(DISTINCT degrees.DegCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
unsigned NumDegsWithCrss;
/***** Get number of degrees with courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumDegsWithCrss))
{
/***** Get current number of degrees with courses from database and update cache *****/
NumDegsWithCrss = (unsigned)
DB_QueryCOUNT ("can not get number of degrees with courses",
"SELECT COUNT(DISTINCT degrees.DegCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumDegsWithCrss);
}
return NumDegsWithCrss;
}
/*****************************************************************************/
/********************* Get number of degrees with users **********************/
/*****************************************************************************/
unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery)
unsigned Deg_GetCachedNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of degrees with users from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of degrees with users",
"SELECT COUNT(DISTINCT degrees.DegCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
static const FigCch_FigureCached_t FigureDegs[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_DEGS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_DEGS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_DEGS_WITH_TCHS, // Teachers
};
unsigned NumDegsWithUsrs;
/***** Get number of degrees with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureDegs[Role],Scope,Cod,
FigCch_UNSIGNED,&NumDegsWithUsrs))
{
/***** Get current number of degrees with users from database and update cache *****/
NumDegsWithUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of degrees with users",
"SELECT COUNT(DISTINCT degrees.DegCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
FigCch_UpdateFigureIntoCache (FigureDegs[Role],Scope,Cod,
FigCch_UNSIGNED,&NumDegsWithUsrs);
}
return NumDegsWithUsrs;
}
/*****************************************************************************/

View File

@ -134,15 +134,24 @@ void Deg_RequestLogo (void);
void Deg_ReceiveLogo (void);
void Deg_RemoveLogo (void);
unsigned Deg_GetNumDegsTotal (void);
unsigned Deg_GetCachedNumDegsInSys (void);
void Deg_FlushCacheNumDegsInCty (void);
unsigned Deg_GetNumDegsInCty (long CtyCod);
unsigned Deg_GetCachedNumDegsInCty (long CtyCod);
void Deg_FlushCacheNumDegsInIns (void);
unsigned Deg_GetNumDegsInIns (long InsCod);
unsigned Deg_GetCachedNumDegsInIns (long InsCod);
void Deg_FlushCacheNumDegsInCtr (void);
unsigned Deg_GetNumDegsInCtr (long CtrCod);
unsigned Deg_GetNumDegsWithCrss (const char *SubQuery);
unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Deg_GetCachedNumDegsInCtr (long CtrCod);
unsigned Deg_GetCachedNumDegsWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Deg_GetCachedNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod);
void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumCrss);

View File

@ -340,7 +340,7 @@ static void DegCfg_NumCrss (void)
Gbl.Hierarchy.Deg.ShrtName),
"BT_LINK DAT",NULL);
Str_FreeString ();
HTM_Unsigned (Crs_GetNumCrssInDeg (Gbl.Hierarchy.Deg.DegCod));
HTM_Unsigned (Crs_GetCachedNumCrssInDeg (Gbl.Hierarchy.Deg.DegCod));
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();

View File

@ -425,48 +425,6 @@ static void Fig_GetAndShowNumUsrsInCrss (Rol_Role_t Role)
{
extern const char *Txt_Total;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
static FigCch_FigureCached_t FigureNumUsrs[Rol_NUM_ROLES] =
{
[Rol_UNK ] = FigCch_NUM_USRS_IN_CRSS, // Any users in courses
[Rol_GST ] = FigCch_UNKNOWN, // Not applicable
[Rol_USR ] = FigCch_UNKNOWN, // Not applicable
[Rol_STD ] = FigCch_NUM_STDS_IN_CRSS, // Students
[Rol_NET ] = FigCch_NUM_NETS_IN_CRSS, // Non-editing teachers
[Rol_TCH ] = FigCch_NUM_TCHS_IN_CRSS, // Teachers
[Rol_DEG_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_CTR_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_INS_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_SYS_ADM] = FigCch_UNKNOWN, // Not applicable
};
static FigCch_FigureCached_t FigureNumCrssPerUsr[Rol_NUM_ROLES] =
{
[Rol_UNK ] = FigCch_NUM_CRSS_PER_USR, // Number of courses per user
[Rol_GST ] = FigCch_UNKNOWN, // Not applicable
[Rol_USR ] = FigCch_UNKNOWN, // Not applicable
[Rol_STD ] = FigCch_NUM_CRSS_PER_STD, // Number of courses per student
[Rol_NET ] = FigCch_NUM_CRSS_PER_NET, // Number of courses per non-editing teacher
[Rol_TCH ] = FigCch_NUM_CRSS_PER_TCH, // Number of courses per teacher
[Rol_DEG_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_CTR_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_INS_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_SYS_ADM] = FigCch_UNKNOWN, // Not applicable
};
static FigCch_FigureCached_t FigureNumUsrsPerCrs[Rol_NUM_ROLES] =
{
[Rol_UNK ] = FigCch_NUM_USRS_PER_CRS, // Number of users per course
[Rol_GST ] = FigCch_UNKNOWN, // Not applicable
[Rol_USR ] = FigCch_UNKNOWN, // Not applicable
[Rol_STD ] = FigCch_NUM_STDS_PER_CRS, // Number of students per course
[Rol_NET ] = FigCch_NUM_NETS_PER_CRS, // Number of non-editing teachers per course
[Rol_TCH ] = FigCch_NUM_TCHS_PER_CRS, // Number of teachers per course
[Rol_DEG_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_CTR_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_INS_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_SYS_ADM] = FigCch_UNKNOWN, // Not applicable
};
unsigned NumUsrs;
double NumCrssPerUsr;
double NumUsrsPerCrs;
long Cod = (Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
@ -480,36 +438,6 @@ static void Fig_GetAndShowNumUsrsInCrss (Rol_Role_t Role)
(1 << Rol_TCH)) :
(1 << Role);
/***** Get the number of users belonging to any course *****/
if (!FigCch_GetFigureFromCache (FigureNumUsrs[Role],Gbl.Scope.Current,Cod,
FigCch_Type_UNSIGNED,&NumUsrs))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrs = Usr_GetNumUsrsInCrss (Gbl.Scope.Current,Cod,Roles);
FigCch_UpdateFigureIntoCache (FigureNumUsrs[Role],Gbl.Scope.Current,Cod,
FigCch_Type_UNSIGNED,&NumUsrs);
}
/***** Get average number of courses per user *****/
if (!FigCch_GetFigureFromCache (FigureNumCrssPerUsr[Role],Gbl.Scope.Current,Cod,
FigCch_Type_DOUBLE,&NumCrssPerUsr))
{
// Not updated recently in cache ==> compute and update it in cache
NumCrssPerUsr = Usr_GetNumCrssPerUsr (Gbl.Scope.Current,Cod,Role);
FigCch_UpdateFigureIntoCache (FigureNumCrssPerUsr[Role],Gbl.Scope.Current,Cod,
FigCch_Type_DOUBLE,&NumCrssPerUsr);
}
/***** Query the number of users per course *****/
if (!FigCch_GetFigureFromCache (FigureNumUsrsPerCrs[Role],Gbl.Scope.Current,Cod,
FigCch_Type_DOUBLE,&NumUsrsPerCrs))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsPerCrs = Usr_GetNumUsrsPerCrs (Gbl.Scope.Current,Cod,Role);
FigCch_UpdateFigureIntoCache (FigureNumUsrsPerCrs[Role],Gbl.Scope.Current,Cod,
FigCch_Type_DOUBLE,&NumUsrsPerCrs);
}
/***** Write the total number of users *****/
HTM_TR_Begin (NULL);
@ -518,16 +446,17 @@ static void Fig_GetAndShowNumUsrsInCrss (Rol_Role_t Role)
Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN]);
HTM_TD_End ();
/* Number of users in courses */
HTM_TD_Begin ("class=\"%s\"",Class);
HTM_Unsigned (NumUsrs);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Gbl.Scope.Current,Cod,Roles));
HTM_TD_End ();
HTM_TD_Begin ("class=\"%s\"",Class);
HTM_Double2Decimals (NumCrssPerUsr);
HTM_Double2Decimals (Usr_GetCachedNumCrssPerUsr (Gbl.Scope.Current,Cod,Role));
HTM_TD_End ();
HTM_TD_Begin ("class=\"%s\"",Class);
HTM_Double2Decimals (NumUsrsPerCrs);
HTM_Double2Decimals (Usr_GetCachedNumUsrsPerCrs (Gbl.Scope.Current,Cod,Role));
HTM_TD_End ();
HTM_TR_End ();
@ -540,7 +469,6 @@ static void Fig_GetAndShowNumUsrsInCrss (Rol_Role_t Role)
static void Fig_GetAndShowNumUsrsNotBelongingToAnyCrs (void)
{
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
unsigned NumGsts;
char *Class = "DAT RB";
/***** Write the total number of users not belonging to any course *****/
@ -551,15 +479,7 @@ static void Fig_GetAndShowNumUsrsNotBelongingToAnyCrs (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"%s\"",Class);
if (!FigCch_GetFigureFromCache (FigCch_NUM_GSTS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumGsts))
{
// Not updated recently in cache ==> compute and update it in cache
NumGsts = Usr_GetNumUsrsNotBelongingToAnyCrs ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_GSTS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumGsts);
}
HTM_Unsigned (NumGsts);
HTM_Unsigned (Usr_GetCachedNumUsrsNotBelongingToAnyCrs ());
HTM_TD_End ();
HTM_TD_Begin ("class=\"%s\"",Class);
@ -738,7 +658,7 @@ static void Fig_GetAndShowHierarchyWithInss (void)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysWithInss = Cty_GetNumCtysWithInss ("");
NumCtysWithInss = Cty_GetCachedNumCtysWithInss ();
break;
case Hie_CTY:
case Hie_INS:
@ -777,13 +697,12 @@ static void Fig_GetAndShowHierarchyWithCtrs (void)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysWithCtrs = Cty_GetNumCtysWithCtrs ("");
NumInssWithCtrs = Ins_GetNumInssWithCtrs ("");
NumCtysWithCtrs = Cty_GetCachedNumCtysWithCtrs ();
NumInssWithCtrs = Ins_GetCachedNumInssWithCtrs ("",Hie_SYS,-1L);
break;
case Hie_CTY:
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",
Gbl.Hierarchy.Cty.CtyCod);
NumInssWithCtrs = Ins_GetNumInssWithCtrs (SubQuery);
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",Gbl.Hierarchy.Cty.CtyCod);
NumInssWithCtrs = Ins_GetCachedNumInssWithCtrs (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
case Hie_CTR:
@ -822,20 +741,18 @@ static void Fig_GetAndShowHierarchyWithDegs (void)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysWithDegs = Cty_GetNumCtysWithDegs ("");
NumInssWithDegs = Ins_GetNumInssWithDegs ("");
NumCtrsWithDegs = Ctr_GetNumCtrsWithDegs ("");
NumCtysWithDegs = Cty_GetCachedNumCtysWithDegs ();
NumInssWithDegs = Ins_GetCachedNumInssWithDegs ("",Hie_SYS,-1L);
NumCtrsWithDegs = Ctr_GetCachedNumCtrsWithDegs ("",Hie_SYS,-1L);
break;
case Hie_CTY:
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",
Gbl.Hierarchy.Cty.CtyCod);
NumInssWithDegs = Ins_GetNumInssWithDegs (SubQuery);
NumCtrsWithDegs = Ctr_GetNumCtrsWithDegs (SubQuery);
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",Gbl.Hierarchy.Cty.CtyCod);
NumInssWithDegs = Ins_GetCachedNumInssWithDegs (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumCtrsWithDegs = Ctr_GetCachedNumCtrsWithDegs (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
sprintf (SubQuery,"centres.InsCod=%ld AND ",
Gbl.Hierarchy.Ins.InsCod);
NumCtrsWithDegs = Ctr_GetNumCtrsWithDegs (SubQuery);
sprintf (SubQuery,"centres.InsCod=%ld AND ",Gbl.Hierarchy.Ins.InsCod);
NumCtrsWithDegs = Ctr_GetCachedNumCtrsWithDegs (SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
case Hie_DEG:
@ -874,28 +791,25 @@ static void Fig_GetAndShowHierarchyWithCrss (void)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysWithCrss = Cty_GetNumCtysWithCrss ("");
NumInssWithCrss = Ins_GetNumInssWithCrss ("");
NumCtrsWithCrss = Ctr_GetNumCtrsWithCrss ("");
NumDegsWithCrss = Deg_GetNumDegsWithCrss ("");
NumCtysWithCrss = Cty_GetCachedNumCtysWithCrss ();
NumInssWithCrss = Ins_GetCachedNumInssWithCrss ("",Hie_SYS,-1L);
NumCtrsWithCrss = Ctr_GetCachedNumCtrsWithCrss ("",Hie_SYS,-1L);
NumDegsWithCrss = Deg_GetCachedNumDegsWithCrss ("",Hie_SYS,-1L);
break;
case Hie_CTY:
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",
Gbl.Hierarchy.Cty.CtyCod);
NumInssWithCrss = Ins_GetNumInssWithCrss (SubQuery);
NumCtrsWithCrss = Ctr_GetNumCtrsWithCrss (SubQuery);
NumDegsWithCrss = Deg_GetNumDegsWithCrss (SubQuery);
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",Gbl.Hierarchy.Cty.CtyCod);
NumInssWithCrss = Ins_GetCachedNumInssWithCrss (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumCtrsWithCrss = Ctr_GetCachedNumCtrsWithCrss (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumDegsWithCrss = Deg_GetCachedNumDegsWithCrss (SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
sprintf (SubQuery,"centres.InsCod=%ld AND ",
Gbl.Hierarchy.Ins.InsCod);
NumCtrsWithCrss = Ctr_GetNumCtrsWithCrss (SubQuery);
NumDegsWithCrss = Deg_GetNumDegsWithCrss (SubQuery);
sprintf (SubQuery,"centres.InsCod=%ld AND ",Gbl.Hierarchy.Ins.InsCod);
NumCtrsWithCrss = Ctr_GetCachedNumCtrsWithCrss (SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
NumDegsWithCrss = Deg_GetCachedNumDegsWithCrss (SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
sprintf (SubQuery,"degrees.CtrCod=%ld AND ",
Gbl.Hierarchy.Ctr.CtrCod);
NumDegsWithCrss = Deg_GetNumDegsWithCrss (SubQuery);
sprintf (SubQuery,"degrees.CtrCod=%ld AND ",Gbl.Hierarchy.Ctr.CtrCod);
NumDegsWithCrss = Deg_GetCachedNumDegsWithCrss (SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
case Hie_CRS:
@ -934,56 +848,51 @@ static void Fig_GetAndShowHierarchyWithUsrs (Rol_Role_t Role)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,"");
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,"");
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,"");
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,"");
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,"");
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,"",Hie_SYS,-1L);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,"",Hie_SYS,-1L);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,"",Hie_SYS,-1L);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,"",Hie_SYS,-1L);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,"",Hie_SYS,-1L);
break;
case Hie_CTY:
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",
Gbl.Hierarchy.Cty.CtyCod);
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,SubQuery);
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,SubQuery);
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,SubQuery);
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,SubQuery);
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,SubQuery);
sprintf (SubQuery,"institutions.CtyCod=%ld AND ",Gbl.Hierarchy.Cty.CtyCod);
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,SubQuery,Hie_CTY,Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
sprintf (SubQuery,"centres.InsCod=%ld AND ",
Gbl.Hierarchy.Ins.InsCod);
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,SubQuery);
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,SubQuery);
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,SubQuery);
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,SubQuery);
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,SubQuery);
sprintf (SubQuery,"centres.InsCod=%ld AND ",Gbl.Hierarchy.Ins.InsCod);
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,SubQuery,Hie_INS,Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
sprintf (SubQuery,"degrees.CtrCod=%ld AND ",
Gbl.Hierarchy.Ctr.CtrCod);
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,SubQuery);
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,SubQuery);
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,SubQuery);
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,SubQuery);
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,SubQuery);
sprintf (SubQuery,"degrees.CtrCod=%ld AND ",Gbl.Hierarchy.Ctr.CtrCod);
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,SubQuery,Hie_CTR,Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
sprintf (SubQuery,"courses.DegCod=%ld AND ",
Gbl.Hierarchy.Deg.DegCod);
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,SubQuery);
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,SubQuery);
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,SubQuery);
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,SubQuery);
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,SubQuery);
sprintf (SubQuery,"courses.DegCod=%ld AND ",Gbl.Hierarchy.Deg.DegCod);
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,SubQuery,Hie_DEG,Gbl.Hierarchy.Deg.DegCod);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,SubQuery,Hie_DEG,Gbl.Hierarchy.Deg.DegCod);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,SubQuery,Hie_DEG,Gbl.Hierarchy.Deg.DegCod);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,SubQuery,Hie_DEG,Gbl.Hierarchy.Deg.DegCod);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,SubQuery,Hie_DEG,Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_CRS:
sprintf (SubQuery,"crs_usr.CrsCod=%ld AND ",
Gbl.Hierarchy.Crs.CrsCod);
NumCtysWithUsrs = Cty_GetNumCtysWithUsrs (Role,SubQuery);
NumInssWithUsrs = Ins_GetNumInssWithUsrs (Role,SubQuery);
NumCtrsWithUsrs = Ctr_GetNumCtrsWithUsrs (Role,SubQuery);
NumDegsWithUsrs = Deg_GetNumDegsWithUsrs (Role,SubQuery);
NumCrssWithUsrs = Crs_GetNumCrssWithUsrs (Role,SubQuery);
sprintf (SubQuery,"crs_usr.CrsCod=%ld AND ",Gbl.Hierarchy.Crs.CrsCod);
NumCtysWithUsrs = Cty_GetCachedNumCtysWithUsrs (Role,SubQuery,Hie_CRS,Gbl.Hierarchy.Crs.CrsCod);
NumInssWithUsrs = Ins_GetCachedNumInssWithUsrs (Role,SubQuery,Hie_CRS,Gbl.Hierarchy.Crs.CrsCod);
NumCtrsWithUsrs = Ctr_GetCachedNumCtrsWithUsrs (Role,SubQuery,Hie_CRS,Gbl.Hierarchy.Crs.CrsCod);
NumDegsWithUsrs = Deg_GetCachedNumDegsWithUsrs (Role,SubQuery,Hie_CRS,Gbl.Hierarchy.Crs.CrsCod);
NumCrssWithUsrs = Crs_GetCachedNumCrssWithUsrs (Role,SubQuery,Hie_CRS,Gbl.Hierarchy.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
@ -1017,29 +926,29 @@ static void Fig_GetAndShowHierarchyTotal (void)
switch (Gbl.Scope.Current)
{
case Hie_SYS:
NumCtysTotal = Cty_GetNumCtysTotal ();
NumInssTotal = Ins_GetNumInssTotal ();
NumCtrsTotal = Ctr_GetNumCtrsInSys ();
NumDegsTotal = Deg_GetNumDegsTotal ();
NumCrssTotal = Crs_GetNumCrssTotal ();
NumCtysTotal = Cty_GetCachedNumCtysInSys ();
NumInssTotal = Ins_GetCachedNumInssInSys ();
NumCtrsTotal = Ctr_GetCachedNumCtrsInSys ();
NumDegsTotal = Deg_GetCachedNumDegsInSys ();
NumCrssTotal = Crs_GetCachedNumCrssInSys ();
break;
case Hie_CTY:
NumInssTotal = Ins_GetNumInssInCty (Gbl.Hierarchy.Cty.CtyCod);
NumCtrsTotal = Ctr_GetNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod);
NumDegsTotal = Deg_GetNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod);
NumCrssTotal = Crs_GetNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod);
NumInssTotal = Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Cty.CtyCod);
NumCtrsTotal = Ctr_GetCachedNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod);
NumDegsTotal = Deg_GetCachedNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod);
NumCrssTotal = Crs_GetCachedNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
NumCtrsTotal = Ctr_GetNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
NumDegsTotal = Deg_GetNumDegsInIns (Gbl.Hierarchy.Ins.InsCod);
NumCrssTotal = Crs_GetNumCrssInIns (Gbl.Hierarchy.Ins.InsCod);
NumCtrsTotal = Ctr_GetCachedNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
NumDegsTotal = Deg_GetCachedNumDegsInIns (Gbl.Hierarchy.Ins.InsCod);
NumCrssTotal = Crs_GetCachedNumCrssInIns (Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
NumDegsTotal = Deg_GetNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod);
NumCrssTotal = Crs_GetNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod);
NumDegsTotal = Deg_GetCachedNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod);
NumCrssTotal = Crs_GetCachedNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
NumCrssTotal = Crs_GetNumCrssInDeg (Gbl.Hierarchy.Deg.DegCod);
NumCrssTotal = Crs_GetCachedNumCrssInDeg (Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_CRS:
break;
@ -3512,16 +3421,16 @@ static void Fig_GetAndShowTimelineActivityStats (void)
/***** Get total number of users *****/
NumUsrsTotal =
(Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
Usr_GetNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
Usr_GetCachedNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
/***** Get total number of following/followers from database *****/
for (NoteType = (TL_NoteType_t) 0;
@ -3824,16 +3733,16 @@ static void Fig_GetAndShowFollowStats (void)
/***** Get total number of users *****/
NumUsrsTotal =
(Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
Usr_GetNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
Usr_GetCachedNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
/***** Get total number of following/followers from database *****/
for (Fol = 0;
@ -4463,16 +4372,16 @@ static void Fig_GetAndShowNumUsrsPerNotifyEvent (void)
/***** Get total number of users *****/
NumUsrsTotal =
(Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
Usr_GetNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
Usr_GetCachedNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH);
/***** Get total number of users who want to be
notified by email on some event, from database *****/

View File

@ -68,7 +68,7 @@ void FigCch_UpdateFigureIntoCache (FigCch_FigureCached_t Figure,
/***** Update figure's value in database *****/
switch (Type)
{
case FigCch_Type_UNSIGNED:
case FigCch_UNSIGNED:
DB_QueryREPLACE ("can not update cached figure value",
"REPLACE INTO figures"
" (Figure,Scope,Cod,ValueInt,ValueDouble)"
@ -77,7 +77,7 @@ void FigCch_UpdateFigureIntoCache (FigCch_FigureCached_t Figure,
(unsigned) Figure,Sco_GetDBStrFromScope (Scope),Cod,
*((unsigned *) ValuePtr));
break;
case FigCch_Type_DOUBLE:
case FigCch_DOUBLE:
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
DB_QueryREPLACE ("can not update cached figure value",
"REPLACE INTO figures"
@ -113,8 +113,8 @@ bool FigCch_GetFigureFromCache (FigCch_FigureCached_t Figure,
};
static const char *Field[FigCch_NUM_TYPES] =
{
[FigCch_Type_UNSIGNED] = "ValueInt",
[FigCch_Type_DOUBLE ] = "ValueDouble",
[FigCch_UNSIGNED] = "ValueInt",
[FigCch_DOUBLE ] = "ValueDouble",
};
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -123,10 +123,10 @@ bool FigCch_GetFigureFromCache (FigCch_FigureCached_t Figure,
/***** Set default value when not found *****/
switch (Type)
{
case FigCch_Type_UNSIGNED:
case FigCch_UNSIGNED:
*((unsigned *) ValuePtr) = 0;
break;
case FigCch_Type_DOUBLE:
case FigCch_DOUBLE:
*((double *) ValuePtr) = 0.0;
break;
}
@ -154,11 +154,11 @@ bool FigCch_GetFigureFromCache (FigCch_FigureCached_t Figure,
{
switch (Type)
{
case FigCch_Type_UNSIGNED:
case FigCch_UNSIGNED:
if (sscanf (row[0],"%u",(unsigned *) ValuePtr) == 1)
Found = true;
break;
case FigCch_Type_DOUBLE:
case FigCch_DOUBLE:
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
if (sscanf (row[0],"%lf",(double *) ValuePtr) == 1)
Found = true;

View File

@ -38,7 +38,7 @@
// If numbers change, clean database table figures: "DELETE FROM figures;"
typedef enum
{
FigCch_UNKNOWN = 0, // Unknown figure
FigCch_UNKNOWN = 0, // Unknown figure (do not change this constant to any value other than 0)
//--------------------------------------------------------------------------
FigCch_NUM_CTYS = 1, // Number of countries
FigCch_NUM_INSS = 2, // Number of institutions
@ -47,30 +47,62 @@ typedef enum
FigCch_NUM_DEGS = 5, // Number of degrees
FigCch_NUM_CRSS = 6, // Number of courses
//--------------------------------------------------------------------------
FigCch_NUM_STDS_IN_CRSS = 7, // Number of students in courses
FigCch_NUM_NETS_IN_CRSS = 8, // Number of non-editing teachers in courses
FigCch_NUM_TCHS_IN_CRSS = 9, // Number of teachers in courses
FigCch_NUM_USRS_IN_CRSS = 10, // Number of users in courses
FigCch_NUM_GSTS = 11, // Number of guests (users not belonging to any course)
FigCch_NUM_CTYS_WITH_INSS = 7, // Number of countries with institutions
FigCch_NUM_CTYS_WITH_CTRS = 8, // Number of countries with centres
FigCch_NUM_CTYS_WITH_DEGS = 9, // Number of countries with degrees
FigCch_NUM_CTYS_WITH_CRSS = 10, // Number of countries with courses
FigCch_NUM_CTYS_WITH_TCHS = 11, // Number of countries with teachers
FigCch_NUM_CTYS_WITH_NETS = 12, // Number of countries with non-editing teachers
FigCch_NUM_CTYS_WITH_STDS = 13, // Number of countries with students
//--------------------------------------------------------------------------
FigCch_NUM_CRSS_PER_USR = 12, // Number of courses per user
FigCch_NUM_CRSS_PER_STD = 13, // Number of courses per student
FigCch_NUM_CRSS_PER_NET = 14, // Number of courses per non-editing teacher
FigCch_NUM_CRSS_PER_TCH = 15, // Number of courses per teacher
FigCch_NUM_INSS_WITH_CTRS = 14, // Number of institutions with centres
FigCch_NUM_INSS_WITH_DEGS = 15, // Number of institutions with degrees
FigCch_NUM_INSS_WITH_CRSS = 16, // Number of institutions with courses
FigCch_NUM_INSS_WITH_TCHS = 17, // Number of institutions with teachers
FigCch_NUM_INSS_WITH_NETS = 18, // Number of institutions with non-editing teachers
FigCch_NUM_INSS_WITH_STDS = 19, // Number of institutions with students
//--------------------------------------------------------------------------
FigCch_NUM_USRS_PER_CRS = 16, // Number of users per course
FigCch_NUM_STDS_PER_CRS = 17, // Number of students per course
FigCch_NUM_NETS_PER_CRS = 18, // Number of non-editing teachers per course
FigCch_NUM_TCHS_PER_CRS = 19, // Number of teachers per course
FigCch_NUM_CTRS_WITH_DEGS = 20, // Number of centres with degrees
FigCch_NUM_CTRS_WITH_CRSS = 21, // Number of centres with courses
FigCch_NUM_CTRS_WITH_TCHS = 22, // Number of centres with teachers
FigCch_NUM_CTRS_WITH_NETS = 23, // Number of centres with non-editing teachers
FigCch_NUM_CTRS_WITH_STDS = 24, // Number of centres with students
//--------------------------------------------------------------------------
FigCch_NUM_USRS_CTY = 20, // Number of users who claim to belong to country
FigCch_NUM_DEGS_WITH_CRSS = 25, // Number of degrees with courses
FigCch_NUM_DEGS_WITH_TCHS = 26, // Number of degrees with teachers
FigCch_NUM_DEGS_WITH_NETS = 27, // Number of degrees with non-editing teachers
FigCch_NUM_DEGS_WITH_STDS = 28, // Number of degrees with students
//--------------------------------------------------------------------------
FigCch_NUM_CRSS_WITH_TCHS = 29, // Number of courses with teachers
FigCch_NUM_CRSS_WITH_NETS = 30, // Number of courses with non-editing teachers
FigCch_NUM_CRSS_WITH_STDS = 31, // Number of courses with students
//--------------------------------------------------------------------------
FigCch_NUM_STDS_IN_CRSS = 32, // Number of students in courses
FigCch_NUM_NETS_IN_CRSS = 33, // Number of non-editing teachers in courses
FigCch_NUM_TCHS_IN_CRSS = 34, // Number of teachers in courses
FigCch_NUM_USRS_IN_CRSS = 35, // Number of users in courses
FigCch_NUM_GSTS = 36, // Number of guests (users not belonging to any course)
//--------------------------------------------------------------------------
FigCch_NUM_CRSS_PER_USR = 37, // Number of courses per user
FigCch_NUM_CRSS_PER_STD = 38, // Number of courses per student
FigCch_NUM_CRSS_PER_NET = 39, // Number of courses per non-editing teacher
FigCch_NUM_CRSS_PER_TCH = 40, // Number of courses per teacher
//--------------------------------------------------------------------------
FigCch_NUM_USRS_PER_CRS = 41, // Number of users per course
FigCch_NUM_STDS_PER_CRS = 42, // Number of students per course
FigCch_NUM_NETS_PER_CRS = 43, // Number of non-editing teachers per course
FigCch_NUM_TCHS_PER_CRS = 44, // Number of teachers per course
//--------------------------------------------------------------------------
FigCch_NUM_USRS_BELONG_CTY = 45, // Number of users who claim to belong to country
FigCch_NUM_USRS_BELONG_INS = 46, // Number of users who claim to belong to institution
FigCch_NUM_USRS_BELONG_CTR = 47, // Number of users who claim to belong to centre
} FigCch_FigureCached_t;
#define FigCch_NUM_TYPES 2
typedef enum
{
FigCch_Type_UNSIGNED,
FigCch_Type_DOUBLE,
FigCch_UNSIGNED,
FigCch_DOUBLE,
} FigCch_Type_t;
/*****************************************************************************/

View File

@ -1243,16 +1243,9 @@ static const Act_Action_t Brw_ActZIPFolder[Brw_NUM_TYPES_FILE_BROWSER] =
static const unsigned long long Brw_MAX_QUOTA_BRIEF[Rol_NUM_ROLES] = // MaxRole is used
{
[Rol_UNK ] = 0,
[Rol_GST ] = 0,
[Rol_USR ] = 0,
[Rol_STD ] = 32ULL*Brw_GiB,
[Rol_NET ] = 32ULL*Brw_GiB,
[Rol_TCH ] = 64ULL*Brw_GiB,
[Rol_DEG_ADM] = 0,
[Rol_CTR_ADM] = 0,
[Rol_INS_ADM] = 0,
[Rol_SYS_ADM] = 0,
[Rol_STD] = 32ULL*Brw_GiB,
[Rol_NET] = 32ULL*Brw_GiB,
[Rol_TCH] = 64ULL*Brw_GiB,
};
#define Brw_MAX_FILES_BRIEF 5000
#define Brw_MAX_FOLDS_BRIEF 1000

View File

@ -164,8 +164,8 @@ void Hlp_ShowHelpWhatWouldYouLikeToDo (void)
{
if (Gbl.Hierarchy.Level == Hie_CRS && // Course selected
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role == Rol_TCH) // I am a teacher in current course
if (!Usr_GetNumUsrsInCrss (Hie_CRS,Gbl.Hierarchy.Crs.CrsCod,
1 << Rol_STD)) // Current course has no students
if (!Usr_GetCachedNumUsrsInCrss (Hie_CRS,Gbl.Hierarchy.Crs.CrsCod,
1 << Rol_STD)) // Current course probably has no students
{
/* Request students enrolment */
Hlp_ShowRowHelpWhatWouldYouLikeToDo (Str_BuildStringStr (Txt_Register_students_in_COURSE_X,

View File

@ -324,20 +324,6 @@ void HieCfg_NumUsrsInCrss (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
{
extern const char *Txt_Users_in_courses;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
unsigned NumUsrsInCrss;
static FigCch_FigureCached_t Figure[Rol_NUM_ROLES] =
{
[Rol_UNK ] = FigCch_NUM_USRS_IN_CRSS, // Any users in courses
[Rol_GST ] = FigCch_UNKNOWN, // Not applicable
[Rol_USR ] = FigCch_UNKNOWN, // Not applicable
[Rol_STD ] = FigCch_NUM_STDS_IN_CRSS, // Students
[Rol_NET ] = FigCch_NUM_NETS_IN_CRSS, // Non-editing teachers
[Rol_TCH ] = FigCch_NUM_TCHS_IN_CRSS, // Teachers
[Rol_DEG_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_CTR_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_INS_ADM] = FigCch_UNKNOWN, // Not applicable
[Rol_SYS_ADM] = FigCch_UNKNOWN, // Not applicable
};
/***** Number of users in courses *****/
HTM_TR_Begin (NULL);
@ -349,19 +335,11 @@ void HieCfg_NumUsrsInCrss (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
if (!FigCch_GetFigureFromCache (Figure[Role],Scope,Cod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Scope,Cod,
Role == Rol_UNK ? (1 << Rol_STD) |
(1 << Rol_NET) |
(1 << Rol_TCH) : // Any user
(1 << Role));
FigCch_UpdateFigureIntoCache (Figure[Role],Scope,Cod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Scope,Cod,
Role == Rol_UNK ? (1 << Rol_STD) |
(1 << Rol_NET) |
(1 << Rol_TCH) : // Any user
(1 << Role)));
HTM_TD_End ();
HTM_TR_End ();

View File

@ -386,7 +386,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
const char *TxtClassNormal;
const char *TxtClassStrong;
const char *BgColor;
unsigned NumUsrsInCrss;
unsigned NumUsrsIns;
Ins_StatusTxt_t StatusTxt;
if (Ins->Status & Ins_STATUS_BIT_PENDING)
@ -417,23 +417,30 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
/***** Number of users who claim to belong to this institution *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins));
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_INS,Hie_INS,Ins->InsCod,
FigCch_UNSIGNED,&NumUsrsIns))
{
NumUsrsIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_INS,Hie_INS,Ins->InsCod,
FigCch_UNSIGNED,&NumUsrsIns);
}
HTM_Unsigned (NumUsrsIns);
HTM_TD_End ();
/***** Other stats *****/
/* Number of centres in this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Ctr_GetNumCtrsInIns (Ins->InsCod));
HTM_Unsigned (Ctr_GetCachedNumCtrsInIns (Ins->InsCod));
HTM_TD_End ();
/* Number of degrees in this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Deg_GetNumDegsInIns (Ins->InsCod));
HTM_Unsigned (Deg_GetCachedNumDegsInIns (Ins->InsCod));
HTM_TD_End ();
/* Number of courses in this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Crs_GetNumCrssInIns (Ins->InsCod));
HTM_Unsigned (Crs_GetCachedNumCrssInIns (Ins->InsCod));
HTM_TD_End ();
/* Number of departments in this institution */
@ -443,18 +450,10 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
/* Number of users in courses of this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_IN_CRSS,Hie_INS,Ins->InsCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Hie_INS,Ins->InsCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_IN_CRSS,Hie_INS,Ins->InsCod,
FigCch_Type_UNSIGNED,&NumUsrsInCrss);
}
HTM_Unsigned (NumUsrsInCrss);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_INS,Ins->InsCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user);
HTM_TD_End ();
/***** Institution status *****/
@ -1090,8 +1089,8 @@ static void Ins_ListInstitutionsForEdition (void)
struct UsrData UsrDat;
bool ICanEdit;
unsigned NumCtrss;
unsigned NumUsrsIns;
unsigned NumUsrsInCrssOfIns;
unsigned NumUsrsWhoClaimToBelongToIns;
Ins_StatusTxt_t StatusTxt;
unsigned StatusUnsigned;
@ -1111,20 +1110,20 @@ static void Ins_ListInstitutionsForEdition (void)
ICanEdit = Ins_CheckIfICanEdit (Ins);
NumCtrss = Ctr_GetNumCtrsInIns (Ins->InsCod);
NumUsrsIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins);
NumUsrsInCrssOfIns = Usr_GetNumUsrsInCrss (Hie_INS,Ins->InsCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
NumUsrsWhoClaimToBelongToIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins);
HTM_TR_Begin (NULL);
/* Put icon to remove institution */
HTM_TD_Begin ("class=\"BM\"");
if (!ICanEdit ||
NumCtrss || // Institution has centres
NumUsrsInCrssOfIns || // Institution has users
NumUsrsWhoClaimToBelongToIns) // Institution has users
NumCtrss || // Institution has centres
NumUsrsIns || // Institution has users
NumUsrsInCrssOfIns) // Institution has users
// Institution has centres or users ==> deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
@ -1201,7 +1200,7 @@ static void Ins_ListInstitutionsForEdition (void)
/* Number of users who claim to belong to this institution */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (NumUsrsWhoClaimToBelongToIns);
HTM_Unsigned (NumUsrsIns);
HTM_TD_End ();
/* Number of centres */
@ -1944,10 +1943,21 @@ static void Ins_CreateInstitution (unsigned Status)
/********************* Get total number of institutions **********************/
/*****************************************************************************/
unsigned Ins_GetNumInssTotal (void)
unsigned Ins_GetCachedNumInssInSys (void)
{
/***** Get total number of institutions from database *****/
return (unsigned) DB_GetNumRowsTable ("institutions");
unsigned NumInss;
/***** Get number of institutions from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumInss))
{
/***** Get current number of institutions from database and update cache *****/
NumInss = (unsigned) DB_GetNumRowsTable ("institutions");
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumInss);
}
return NumInss;
}
/*****************************************************************************/
@ -1978,71 +1988,142 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
return Gbl.Cache.NumInssInCty.NumInss;
}
unsigned Ins_GetCachedNumInssInCty (long CtyCod)
{
unsigned NumInss;
/***** Get number of institutions from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumInss))
{
/***** Get current number of institutions from database and update cache *****/
NumInss = Ins_GetNumInssInCty (CtyCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,Hie_CTY,CtyCod,
FigCch_UNSIGNED,&NumInss);
}
return NumInss;
}
/*****************************************************************************/
/***************** Get number of institutions with centres *******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
unsigned Ins_GetCachedNumInssWithCtrs (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of institutions with centres from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of institutions with centres",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres"
" WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery);
unsigned NumInssWithCtrs;
/***** Get number of institutions with centres from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS_WITH_CTRS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithCtrs))
{
/***** Get current number of institutions with centres from database and update cache *****/
NumInssWithCtrs = (unsigned)
DB_QueryCOUNT ("can not get number of institutions with centres",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres"
" WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS_WITH_CTRS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithCtrs);
}
return NumInssWithCtrs;
}
/*****************************************************************************/
/****************** Get number of institutions with degrees ******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
unsigned Ins_GetCachedNumInssWithDegs (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of institutions with degrees from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of institutions with degrees",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
unsigned NumInssWithDegs;
/***** Get number of institutions with degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS_WITH_DEGS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithDegs))
{
/***** Get current number of institutions with degrees from database and update cache *****/
NumInssWithDegs = (unsigned)
DB_QueryCOUNT ("can not get number of institutions with degrees",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS_WITH_DEGS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithDegs);
}
return NumInssWithDegs;
}
/*****************************************************************************/
/****************** Get number of institutions with courses ******************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
unsigned Ins_GetCachedNumInssWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of institutions with courses from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of institutions with courses",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
unsigned NumInssWithCrss;
/***** Get number of institutions with courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithCrss))
{
/***** Get current number of institutions with courses from database and update cache *****/
NumInssWithCrss = (unsigned)
DB_QueryCOUNT ("can not get number of institutions with courses",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS_WITH_CRSS,Scope,Cod,
FigCch_UNSIGNED,&NumInssWithCrss);
}
return NumInssWithCrss;
}
/*****************************************************************************/
/****************** Get number of institutions with users ********************/
/*****************************************************************************/
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod)
{
/***** Get number of institutions with users from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of institutions with users",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
static const FigCch_FigureCached_t FigureInss[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_INSS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_INSS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_INSS_WITH_TCHS, // Teachers
};
unsigned NumInssWithUsrs;
/***** Get number of institutions with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureInss[Role],Scope,Cod,
FigCch_UNSIGNED,&NumInssWithUsrs))
{
/***** Get current number of institutions with users from database and update cache *****/
NumInssWithUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of institutions with users",
"SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
FigCch_UpdateFigureIntoCache (FigureInss[Role],Scope,Cod,
FigCch_UNSIGNED,&NumInssWithUsrs);
}
return NumInssWithUsrs;
}
/*****************************************************************************/

View File

@ -129,13 +129,20 @@ void Ins_ContEditAfterChgIns (void);
void Ins_RecFormReqIns (void);
void Ins_RecFormNewIns (void);
unsigned Ins_GetNumInssTotal (void);
unsigned Ins_GetCachedNumInssInSys (void);
void Ins_FlushCacheNumInssInCty (void);
unsigned Ins_GetNumInssInCty (long CtyCod);
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery);
unsigned Ins_GetNumInssWithDegs (const char *SubQuery);
unsigned Ins_GetNumInssWithCrss (const char *SubQuery);
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Ins_GetCachedNumInssInCty (long CtyCod);
unsigned Ins_GetCachedNumInssWithCtrs (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Ins_GetCachedNumInssWithDegs (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Ins_GetCachedNumInssWithCrss (const char *SubQuery,
Hie_Level_t Scope,long Cod);
unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery,
Hie_Level_t Scope,long Cod);
void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss);

View File

@ -33,6 +33,7 @@
#include "swad_database.h"
#include "swad_department.h"
#include "swad_figure_cache.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_help.h"
@ -165,7 +166,7 @@ static void InsCfg_Configuration (bool PrintView)
InsCfg_QR ();
else
{
NumCtrs = Ctr_GetNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
NumCtrs = Ctr_GetCachedNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod);
/***** Number of users who claim to belong to this institution,
number of centres,
@ -461,6 +462,7 @@ static void InsCfg_QR (void)
static void InsCfg_NumUsrs (void)
{
extern const char *Txt_Users_of_the_institution;
unsigned NumUsrsIns;
/***** Number of users *****/
HTM_TR_Begin (NULL);
@ -470,7 +472,14 @@ static void InsCfg_NumUsrs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (&Gbl.Hierarchy.Ins));
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_INS,Hie_INS,Gbl.Hierarchy.Ins.InsCod,
FigCch_UNSIGNED,&NumUsrsIns))
{
NumUsrsIns = Usr_GetNumUsrsWhoClaimToBelongToIns (&Gbl.Hierarchy.Ins);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_INS,Hie_INS,Gbl.Hierarchy.Ins.InsCod,
FigCch_UNSIGNED,&NumUsrsIns);
}
HTM_Unsigned (NumUsrsIns);
HTM_TD_End ();
HTM_TR_End ();
@ -492,7 +501,7 @@ static void InsCfg_NumDegs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Deg_GetNumDegsInIns (Gbl.Hierarchy.Ins.InsCod));
HTM_Unsigned (Deg_GetCachedNumDegsInIns (Gbl.Hierarchy.Ins.InsCod));
HTM_TD_End ();
HTM_TR_End ();
@ -514,7 +523,7 @@ static void InsCfg_NumCrss (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Crs_GetNumCrssInIns (Gbl.Hierarchy.Ins.InsCod));
HTM_Unsigned (Crs_GetCachedNumCrssInIns (Gbl.Hierarchy.Ins.InsCod));
HTM_TD_End ();
HTM_TR_End ();

View File

@ -447,16 +447,16 @@ void Net_ShowWebAndSocialNetworksStats (void)
/***** Get total number of users in current scope *****/
NumUsrsTotal =
(Gbl.Scope.Current == Hie_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
Usr_GetNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
Usr_GetCachedNumUsrsInCrss (Gbl.Scope.Current,
(Gbl.Scope.Current == Hie_CTY ? Gbl.Hierarchy.Cty.CtyCod :
(Gbl.Scope.Current == Hie_INS ? Gbl.Hierarchy.Ins.InsCod :
(Gbl.Scope.Current == Hie_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == Hie_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == Hie_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH); // Any user
/***** Get number of users with a web / social network *****/
switch (Gbl.Scope.Current)

View File

@ -203,7 +203,7 @@ void Plc_SeePlaces (void)
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr_GetNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod) -
NumCtrsWithPlc);
NumCtrsWithPlc);
HTM_TD_End ();
HTM_TR_End ();

View File

@ -132,12 +132,11 @@ static void SysCfg_Configuration (bool PrintView)
/***** Get number of centres with map *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS_WITH_MAP,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtrsWithMap))
FigCch_UNSIGNED,&NumCtrsWithMap))
{
// Not updated recently in cache ==> compute and update it in cache
NumCtrsWithMap = Ctr_GetNumCtrsWithMapInSys ();
NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInSys ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_MAP,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtrsWithMap);
FigCch_UNSIGNED,&NumCtrsWithMap);
}
if (PrintView)
@ -146,14 +145,7 @@ static void SysCfg_Configuration (bool PrintView)
else
{
/***** Get number of centres *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTRS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtrs))
{
// Not updated recently in cache ==> compute and update it in cache
NumCtrs = Ctr_GetNumCtrsInSys ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtrs);
}
NumCtrs = Ctr_GetCachedNumCtrsInSys ();
/***** Number of countries,
number of institutions,
@ -353,7 +345,6 @@ static void SysCfg_QR (void)
static void SysCfg_NumCtys (void)
{
extern const char *Txt_Countries;
unsigned NumCtys;
/***** Number of countries ******/
HTM_TR_Begin (NULL);
@ -365,15 +356,7 @@ static void SysCfg_NumCtys (void)
HTM_TD_Begin ("class=\"LB\"");
Frm_StartFormGoTo (ActSeeCty);
HTM_BUTTON_SUBMIT_Begin (Txt_Countries,"BT_LINK DAT",NULL);
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtys))
{
// Not updated recently in cache ==> compute and update it in cache
NumCtys = Cty_GetNumCtysTotal ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCtys);
}
HTM_Unsigned (NumCtys);
HTM_Unsigned (Cty_GetCachedNumCtysInSys ());
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
@ -388,7 +371,6 @@ static void SysCfg_NumCtys (void)
static void SysCfg_NumInss (void)
{
extern const char *Txt_Institutions;
unsigned NumInss;
/***** Number of institutions ******/
HTM_TR_Begin (NULL);
@ -398,15 +380,7 @@ static void SysCfg_NumInss (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
if (!FigCch_GetFigureFromCache (FigCch_NUM_INSS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumInss))
{
// Not updated recently in cache ==> compute and update it in cache
NumInss = Ins_GetNumInssTotal ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumInss);
}
HTM_Unsigned (NumInss);
HTM_Unsigned (Ins_GetCachedNumInssInSys ());
HTM_TD_End ();
HTM_TR_End ();
@ -419,7 +393,6 @@ static void SysCfg_NumInss (void)
static void SysCfg_NumDegs (void)
{
extern const char *Txt_Degrees;
unsigned NumDegs;
/***** Number of degrees *****/
HTM_TR_Begin (NULL);
@ -429,15 +402,7 @@ static void SysCfg_NumDegs (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
if (!FigCch_GetFigureFromCache (FigCch_NUM_DEGS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumDegs))
{
// Not updated recently in cache ==> compute and update it in cache
NumDegs = Deg_GetNumDegsTotal ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumDegs);
}
HTM_Unsigned (NumDegs);
HTM_Unsigned (Deg_GetCachedNumDegsInSys ());
HTM_TD_End ();
HTM_TR_End ();
@ -450,7 +415,6 @@ static void SysCfg_NumDegs (void)
static void SysCfg_NumCrss (void)
{
extern const char *Txt_Courses;
unsigned NumCrss;
/***** Number of courses *****/
HTM_TR_Begin (NULL);
@ -460,15 +424,7 @@ static void SysCfg_NumCrss (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
if (!FigCch_GetFigureFromCache (FigCch_NUM_CRSS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCrss))
{
// Not updated recently in cache ==> compute and update it in cache
NumCrss = Crs_GetNumCrssTotal ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_SYS,-1L,
FigCch_Type_UNSIGNED,&NumCrss);
}
HTM_Unsigned (NumCrss);
HTM_Unsigned (Crs_GetCachedNumCrssInSys ());
HTM_TD_End ();
HTM_TR_End ();

View File

@ -49,6 +49,7 @@
#include "swad_duplicate.h"
#include "swad_enrolment.h"
#include "swad_figure.h"
#include "swad_figure_cache.h"
#include "swad_follow.h"
#include "swad_form.h"
#include "swad_global.h"
@ -112,29 +113,18 @@ static const char *Usr_IconsClassPhotoOrList[Usr_NUM_USR_LIST_TYPES] =
static const char *Usr_NameSelUnsel[Rol_NUM_ROLES] =
{
[Rol_UNK ] = NULL,
[Rol_GST ] = "SEL_UNSEL_GSTS",
[Rol_USR ] = NULL,
[Rol_STD ] = "SEL_UNSEL_STDS",
[Rol_NET ] = "SEL_UNSEL_NETS",
[Rol_TCH ] = "SEL_UNSEL_TCHS",
[Rol_DEG_ADM] = NULL,
[Rol_CTR_ADM] = NULL,
[Rol_INS_ADM] = NULL,
[Rol_SYS_ADM] = NULL,
[Rol_GST] = "SEL_UNSEL_GSTS",
[Rol_STD] = "SEL_UNSEL_STDS",
[Rol_NET] = "SEL_UNSEL_NETS",
[Rol_TCH] = "SEL_UNSEL_TCHS",
};
static const char *Usr_ParamUsrCod[Rol_NUM_ROLES] =
{
[Rol_UNK ] = "UsrCodAll", // here means all users
[Rol_GST ] = "UsrCodGst",
[Rol_USR ] = NULL,
[Rol_STD ] = "UsrCodStd",
[Rol_NET ] = "UsrCodNET",
[Rol_TCH ] = "UsrCodTch",
[Rol_DEG_ADM] = NULL,
[Rol_CTR_ADM] = NULL,
[Rol_INS_ADM] = NULL,
[Rol_SYS_ADM] = NULL,
[Rol_UNK] = "UsrCodAll", // here means all users
[Rol_GST] = "UsrCodGst",
[Rol_STD] = "UsrCodStd",
[Rol_NET] = "UsrCodNET",
[Rol_TCH] = "UsrCodTch",
};
#define Usr_NUM_MAIN_FIELDS_DATA_ADM 7
@ -4192,6 +4182,23 @@ unsigned Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty (void)
return Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs;
}
unsigned Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty (void)
{
unsigned NumUsrs;
/***** Get number of user who don't claim to belong to any country from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,-1L,
FigCch_UNSIGNED,&NumUsrs))
{
/***** Get current number of user who don't claim to belong to any country from database and update cache *****/
NumUsrs = Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,-1L,
FigCch_UNSIGNED,&NumUsrs);
}
return NumUsrs;
}
/*****************************************************************************/
/******** Get number of users who claim to belong to another country *********/
/*****************************************************************************/
@ -4217,6 +4224,23 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToAnotherCty (void)
return Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs;
}
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty (void)
{
unsigned NumUsrsCty;
/***** Get number of users who claim to belong to another country form cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,0,
FigCch_UNSIGNED,&NumUsrsCty))
{
/***** Get current number of users who claim to belong to another country from database and update cache *****/
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToAnotherCty ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,0,
FigCch_UNSIGNED,&NumUsrsCty);
}
return NumUsrsCty;
}
/*****************************************************************************/
/*********** Get number of users who claim to belong to a country ************/
/*****************************************************************************/
@ -4258,6 +4282,23 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Country *Cty)
return Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs;
}
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToCty (struct Country *Cty)
{
unsigned NumUsrsCty;
/***** Get number of users who claim to belong to country from cache ******/
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,Cty->CtyCod,
FigCch_UNSIGNED,&NumUsrsCty))
{
/***** Get current number of users who claim to belong to country from database and update cache ******/
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToCty (Cty);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_CTY,Cty->CtyCod,
FigCch_UNSIGNED,&NumUsrsCty);
}
return NumUsrsCty;
}
/*****************************************************************************/
/******** Get number of users who claim to belong to an institution **********/
/*****************************************************************************/
@ -4339,6 +4380,21 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (struct Centre *Ctr)
return Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs;
}
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToCtr (struct Centre *Ctr)
{
unsigned NumUsrsCtr;
if (!FigCch_GetFigureFromCache (FigCch_NUM_USRS_BELONG_CTR,Hie_CTR,Ctr->CtrCod,
FigCch_UNSIGNED,&NumUsrsCtr))
{
NumUsrsCtr = Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_CTR,Ctr->CtrCod,
FigCch_UNSIGNED,&NumUsrsCtr);
}
return NumUsrsCtr;
}
/*****************************************************************************/
/******************* Get number of teachers in a centre **********************/
/*****************************************************************************/
@ -9416,6 +9472,45 @@ unsigned Usr_GetNumUsrsInCrss (Hie_Level_t Scope,long Cod,unsigned Roles)
return NumUsrs;
}
unsigned Usr_GetCachedNumUsrsInCrss (Hie_Level_t Scope,long Cod,unsigned Roles)
{
FigCch_FigureCached_t Figure = FigCch_NUM_USRS_IN_CRSS; // Initialized to avoid warning
unsigned NumUsrsInCrss;
/***** Set figure depending on roles *****/
switch (Roles)
{
case 1 << Rol_STD: // Students
Figure = FigCch_NUM_STDS_IN_CRSS;
break;
case 1 << Rol_NET: // Non-editing teachers
Figure = FigCch_NUM_NETS_IN_CRSS;
break;
case 1 << Rol_TCH: // Teachers
Figure = FigCch_NUM_TCHS_IN_CRSS;
break;
case 1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH: // Any users in courses
Figure = FigCch_NUM_USRS_IN_CRSS;
break;
default:
Rol_WrongRoleExit ();
}
/***** Get number of users in courses from cache *****/
if (!FigCch_GetFigureFromCache (Figure,Scope,Cod,
FigCch_UNSIGNED,&NumUsrsInCrss))
{
/***** Get current number of users in courses from database and update cache *****/
NumUsrsInCrss = Usr_GetNumUsrsInCrss (Scope,Cod,Roles);
FigCch_UpdateFigureIntoCache (Figure,Scope,Cod,
FigCch_UNSIGNED,&NumUsrsInCrss);
}
return NumUsrsInCrss;
}
/*****************************************************************************/
/******** Get total number of users who do not belong to any course **********/
/*****************************************************************************/
@ -9430,6 +9525,23 @@ unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void)
" (SELECT DISTINCT(UsrCod) FROM crs_usr)");
}
unsigned Usr_GetCachedNumUsrsNotBelongingToAnyCrs (void)
{
unsigned NumGsts;
/***** Get number of guests from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_GSTS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumGsts))
{
/***** Get current number of guests from database and update cache *****/
NumGsts = Usr_GetNumUsrsNotBelongingToAnyCrs ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_GSTS,Hie_SYS,-1L,
FigCch_UNSIGNED,&NumGsts);
}
return NumGsts;
}
/*****************************************************************************/
/************ Get average number of courses with users of a role *************/
/*****************************************************************************/
@ -9575,6 +9687,30 @@ double Usr_GetNumCrssPerUsr (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
return NumCrssPerUsr;
}
double Usr_GetCachedNumCrssPerUsr (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
{
static const FigCch_FigureCached_t FigureNumCrssPerUsr[Rol_NUM_ROLES] =
{
[Rol_UNK] = FigCch_NUM_CRSS_PER_USR, // Number of courses per user
[Rol_STD] = FigCch_NUM_CRSS_PER_STD, // Number of courses per student
[Rol_NET] = FigCch_NUM_CRSS_PER_NET, // Number of courses per non-editing teacher
[Rol_TCH] = FigCch_NUM_CRSS_PER_TCH, // Number of courses per teacher
};
double NumCrssPerUsr;
/***** Get number of courses per user from cache *****/
if (!FigCch_GetFigureFromCache (FigureNumCrssPerUsr[Role],Scope,Cod,
FigCch_DOUBLE,&NumCrssPerUsr))
{
/***** Get current number of courses per user from database and update cache *****/
NumCrssPerUsr = Usr_GetNumCrssPerUsr (Scope,Cod,Role);
FigCch_UpdateFigureIntoCache (FigureNumCrssPerUsr[Role],Scope,Cod,
FigCch_DOUBLE,&NumCrssPerUsr);
}
return NumCrssPerUsr;
}
/*****************************************************************************/
/************ Get average number of courses with users of a type *************/
/*****************************************************************************/
@ -9725,6 +9861,30 @@ double Usr_GetNumUsrsPerCrs (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
return NumUsrsPerCrs;
}
double Usr_GetCachedNumUsrsPerCrs (Hie_Level_t Scope,long Cod,Rol_Role_t Role)
{
static const FigCch_FigureCached_t FigureNumUsrsPerCrs[Rol_NUM_ROLES] =
{
[Rol_UNK] = FigCch_NUM_USRS_PER_CRS, // Number of users per course
[Rol_STD] = FigCch_NUM_STDS_PER_CRS, // Number of students per course
[Rol_NET] = FigCch_NUM_NETS_PER_CRS, // Number of non-editing teachers per course
[Rol_TCH] = FigCch_NUM_TCHS_PER_CRS, // Number of teachers per course
};
double NumUsrsPerCrs;
/***** Get number of users per course from cache *****/
if (!FigCch_GetFigureFromCache (FigureNumUsrsPerCrs[Role],Scope,Cod,
FigCch_DOUBLE,&NumUsrsPerCrs))
{
/***** Get current number of users per course from database and update cache *****/
NumUsrsPerCrs = Usr_GetNumUsrsPerCrs (Scope,Cod,Role);
FigCch_UpdateFigureIntoCache (FigureNumUsrsPerCrs[Role],Scope,Cod,
FigCch_DOUBLE,&NumUsrsPerCrs);
}
return NumUsrsPerCrs;
}
/*****************************************************************************/
/****************** Check if a user is banned in ranking *********************/
/*****************************************************************************/

View File

@ -407,16 +407,26 @@ long Usr_GetRamdomStdFromCrs (long CrsCod);
long Usr_GetRamdomStdFromGrp (long GrpCod);
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod);
void Usr_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty (void);
unsigned Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty (void);
unsigned Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty (void);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToAnotherCty (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToAnotherCty (void);
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty (void);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCty (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Country *Cty);
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToCty (struct Country *Cty);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Instit *Ins);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (struct Centre *Ctr);
unsigned Usr_GetCachedNumUsrsWhoClaimToBelongToCtr (struct Centre *Ctr);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);
void Usr_GetListUsrs (Hie_Level_t Scope,Rol_Role_t Role);
@ -509,9 +519,16 @@ void Usr_ShowWarningNoUsersFound (Rol_Role_t Role);
unsigned Usr_GetTotalNumberOfUsersInPlatform (void);
unsigned Usr_GetNumUsrsInCrss (Hie_Level_t Scope,long Cod,unsigned Roles);
unsigned Usr_GetCachedNumUsrsInCrss (Hie_Level_t Scope,long Cod,unsigned Roles);
unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void);
unsigned Usr_GetCachedNumUsrsNotBelongingToAnyCrs (void);
double Usr_GetNumCrssPerUsr (Hie_Level_t Scope,long Cod,Rol_Role_t Role);
double Usr_GetCachedNumCrssPerUsr (Hie_Level_t Scope,long Cod,Rol_Role_t Role);
double Usr_GetNumUsrsPerCrs (Hie_Level_t Scope,long Cod,Rol_Role_t Role);
double Usr_GetCachedNumUsrsPerCrs (Hie_Level_t Scope,long Cod,Rol_Role_t Role);
bool Usr_CheckIfUsrBanned (long UsrCod);
void Usr_RemoveUsrFromUsrBanned (long UsrCod);